Add includes for /tracks

This commit is contained in:
Deluan 2023-05-23 18:36:38 -04:00 committed by Deluan
parent 90c2d7d1cf
commit 4507895d58
10 changed files with 321 additions and 58 deletions

View file

@ -20,6 +20,10 @@ get:
properties: properties:
data: data:
$ref: '../schemas/Track.yml' $ref: '../schemas/Track.yml'
included:
type: array
items:
$ref: '../schemas/IncludedResource.yml'
'403': '403':
$ref: '../responses/NotAuthorized.yml' $ref: '../responses/NotAuthorized.yml'
'404': '404':

View file

@ -31,6 +31,10 @@ get:
$ref: '../schemas/PaginationLinks.yml' $ref: '../schemas/PaginationLinks.yml'
meta: meta:
$ref: '../schemas/PaginationMeta.yml' $ref: '../schemas/PaginationMeta.yml'
included:
type: array
items:
$ref: '../schemas/IncludedResource.yml'
'400': '400':
$ref: '../responses/BadRequest.yml' $ref: '../responses/BadRequest.yml'
'403': '403':

View file

@ -6,3 +6,5 @@ properties:
bio: bio:
type: string type: string
description: A short biography of the artist description: A short biography of the artist
required:
- name

View file

@ -1,5 +1,6 @@
oneOf: oneOf:
- $ref: './Track.yml' - $ref: './Track.yml'
- $ref: './Album.yml'
- $ref: './Artist.yml' - $ref: './Artist.yml'
discriminator: discriminator:
propertyName: type propertyName: type

View file

@ -183,6 +183,22 @@ func (mfs MediaFiles) ToAlbum() Album {
return a return a
} }
func (mfs MediaFiles) ArtistIDs() []string {
var ids []string
for _, mf := range mfs {
ids = append(ids, mf.ArtistID, mf.AlbumArtistID)
}
return ids
}
func (mfs MediaFiles) AlbumIDs() []string {
var ids []string
for _, mf := range mfs {
ids = append(ids, mf.AlbumID)
}
return ids
}
func allOrNothing(items []string) (string, int) { func allOrNothing(items []string) (string, int) {
items = slices.Compact(items) items = slices.Compact(items)
if len(items) == 1 { if len(items) == 1 {

View file

@ -73,10 +73,20 @@ func (a *Router) GetTracks(ctx context.Context, request GetTracksRequestObject)
} }
baseUrl := baseResourceUrl(ctx, "tracks") baseUrl := baseResourceUrl(ctx, "tracks")
links, meta := buildPaginationLinksAndMeta(int32(cnt), request.Params, baseUrl) links, meta := buildPaginationLinksAndMeta(int32(cnt), request.Params, baseUrl)
resources := includedResources{ctx: ctx, ds: a.ds, includes: request.Params.Include}
err = resources.AddArtists(mfs.ArtistIDs()...)
if err != nil {
return nil, err
}
err = resources.AddAlbums(mfs.AlbumIDs()...)
if err != nil {
return nil, err
}
return GetTracks200JSONResponse{ return GetTracks200JSONResponse{
Data: toAPITracks(mfs), Data: toAPITracks(mfs),
Links: links, Links: links,
Meta: &meta, Meta: &meta,
Included: resources.Build(),
}, nil }, nil
} }
@ -85,7 +95,19 @@ func (a *Router) GetTrack(ctx context.Context, request GetTrackRequestObject) (G
if err != nil { if err != nil {
return nil, err return nil, err
} }
return GetTrack200JSONResponse{Data: toAPITrack(*mf)}, nil resources := includedResources{ctx: ctx, ds: a.ds, includes: request.Params.Include}
err = resources.AddArtists(mf.ArtistID, mf.AlbumArtistID)
if err != nil {
return nil, err
}
err = resources.AddAlbums(mf.AlbumID)
if err != nil {
return nil, err
}
return GetTrack200JSONResponse{
Data: toAPITrack(*mf),
Included: resources.Build(),
}, nil
} }
func (a *Router) GetAlbums(ctx context.Context, request GetAlbumsRequestObject) (GetAlbumsResponseObject, error) { func (a *Router) GetAlbums(ctx context.Context, request GetAlbumsRequestObject) (GetAlbumsResponseObject, error) {

View file

@ -122,6 +122,25 @@ func toAPIAlbums(mas model.Albums) []Album {
return albums return albums
} }
func toAPIArtist(ma model.Artist) Artist {
return Artist{
Type: ResourceTypeArtist,
Id: ma.ID,
Attributes: &ArtistAttributes{
Name: ma.Name,
Bio: P(ma.Biography),
},
}
}
func toAPIArtists(mas model.Artists) []Artist {
artists := make([]Artist, len(mas))
for i := range mas {
artists[i] = toAPIArtist(mas[i])
}
return artists
}
type GetParams interface { type GetParams interface {
GetParams() GetTracksParams GetParams() GetTracksParams
} }

60
server/api/includes.go Normal file
View file

@ -0,0 +1,60 @@
package api
import (
"context"
"sort"
"github.com/Masterminds/squirrel"
"github.com/navidrome/navidrome/model"
"golang.org/x/exp/slices"
)
type includedResources struct {
ctx context.Context
ds model.DataStore
includes *includeSlice
resources []IncludedResource
}
func (i *includedResources) AddAlbums(albumIds ...string) error {
if i.includes == nil || !slices.Contains(*i.includes, "album") {
return nil
}
sort.Strings(albumIds)
slices.Compact(albumIds)
albums, err := i.ds.Album(i.ctx).GetAll(model.QueryOptions{Filters: squirrel.Eq{"id": albumIds}})
if err != nil {
return err
}
for _, al := range albums {
inc := &IncludedResource{}
_ = inc.FromAlbum(toAPIAlbum(al))
i.resources = append(i.resources, *inc)
}
return nil
}
func (i *includedResources) AddArtists(artistIds ...string) error {
if i.includes == nil || !slices.Contains(*i.includes, "artist") {
return nil
}
sort.Strings(artistIds)
slices.Compact(artistIds)
artists, err := i.ds.Artist(i.ctx).GetAll(model.QueryOptions{Filters: squirrel.Eq{"artist.id": artistIds}})
if err != nil {
return err
}
for _, ar := range artists {
inc := &IncludedResource{}
_ = inc.FromArtist(toAPIArtist(ar))
i.resources = append(i.resources, *inc)
}
return nil
}
func (i *includedResources) Build() *[]IncludedResource {
if len(i.resources) == 0 {
return nil
}
return &i.resources
}

View file

@ -933,9 +933,10 @@ type GetTracksResponseObject interface {
} }
type GetTracks200JSONResponse struct { type GetTracks200JSONResponse struct {
Data []Track `json:"data"` Data []Track `json:"data"`
Links PaginationLinks `json:"links"` Included *[]IncludedResource `json:"included,omitempty"`
Meta *PaginationMeta `json:"meta,omitempty"` Links PaginationLinks `json:"links"`
Meta *PaginationMeta `json:"meta,omitempty"`
} }
func (response GetTracks200JSONResponse) VisitGetTracksResponse(w http.ResponseWriter) error { func (response GetTracks200JSONResponse) VisitGetTracksResponse(w http.ResponseWriter) error {
@ -984,7 +985,8 @@ type GetTrackResponseObject interface {
} }
type GetTrack200JSONResponse struct { type GetTrack200JSONResponse struct {
Data Track `json:"data"` Data Track `json:"data"`
Included *[]IncludedResource `json:"included,omitempty"`
} }
func (response GetTrack200JSONResponse) VisitGetTrackResponse(w http.ResponseWriter) error { func (response GetTrack200JSONResponse) VisitGetTrackResponse(w http.ResponseWriter) error {
@ -1263,55 +1265,57 @@ func (sh *strictHandler) GetTrack(w http.ResponseWriter, r *http.Request, trackI
// Base64 encoded, gzipped, json marshaled Swagger object // Base64 encoded, gzipped, json marshaled Swagger object
var swaggerSpec = []string{ var swaggerSpec = []string{
"H4sIAAAAAAAC/+xb224bOdJ+FYL/D8wMpiN5k9m9MLAXzmwSeJCDYXs2FxkvwO4uqTlhkx2SLVsTCNjX", "H4sIAAAAAAAC/+w73W7bONavQuj7gJnBqHa2nd0LA3uRzrZFBm0aJJntRScLUNKxxalEqiTlxFMY2NfY",
"2NfbJ1mwyD5IYkstJU4mQW4Su8mq+qpYrCoW6fc0U2WlJEhr6Ol7WjHNSrCg8bcZFxb0z0paxiV+ycFk", "19snWfCQlGSLsmW3aadBb9pE5Pnl4fnjyYcoFWUlOHCtotmHqKKSlqBB4m9zVmiQPwuuKeP4JQOVSlZp",
"mleWK0lP6VMcJ+mSMLkklVYVaLskmSfgck4s3NkJ+dWwOZwSz+5NGDY3f28oThdM1EATyh3XdzXoJU2o", "Jng0i57jOklWhPIVqaSoQOoVSS0A4wui4U5PyK+KLmBGLLq3blnd/N1DzJa0qCGKI2awvq9BrqI44rSE",
"ZCXQU7pJRRNqsgJK5vBwC2UAbi1oR/6v3367/fHU/UMTapeV42Gs5nJOV+0HpjVb0tUqCeyfyNy85rYY", "aBZtQ0VxpNIcSmr4YRpKx7jWIA34v3777fbHmfkniiO9qgwOpSXji2jdfKBS0lW0XscO/TOeqTdM56Nl",
"raMtmCUgc0NuuS2iekLgeZieLdX96PmuZmL8SqJuTBK4Y5klJbNZsaUlcjxQR09zLxo+08As6Fde1X2a", "1DnVBHimyC3TeVBOcDgPk7OBuh8539e0GH+SKBvlBO5oqklJdZr3pESMB8poYe5FwhcSqAb52oq6T1Je",
"yroEzbNO47knd+sridIEoRKrCCOo2Kb68zVxh5lhg3asOfIjzHFdMPlhttitv+N/lPJIeC+aPwdjjvUC",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Ldtp+cc01H3mG2LcHig7n7vxogrMfJ5u2+M3LU22nT5OMP66eSn",
"G2mxxBngfimZM+yID0md4Y7gK8udnWGm3T3jkP/1bms/21L2MBy9nNe9v0T577//Y4ijJG9hSUpW+cZD", "UVBuhOweLJETxjO2ZFlNC3e+1hjbDHzQBpsW7LcY+i2GfuoY+ucIne5588HETndlH0jw9NJ0HNb0g/1h",
"e68dVpzkHBsNTC+JhkqDcdtFzteuQT93tHkGNmD5zpC5UCkT2Fvy69u9HBxa3/CXPd9Ko2+l0b20F4J/", "X/z0LZOjAujBcdNTCwVOx+7XEjndjfiY0OneCB5Y7GwVM23fGYfsr/Na+8WOssPD0cd53fmjnv/++z+K",
"/RlqJP9y4KspkcLe/joqpEaZLmhN3+P/e8qj63CRdGx7oXHPw8qk5voqUiUF0F9IkRS2xNE1UnNB+HVV", "GEjyDlakpJVtPDTv2u7EScaw0UDlikioJChzXfhi4xn0S3ubF6AdL98psihEQgvsLdnzbYcwh87X/ZHU",
"SDZYpXe1hl7Vv1R7c+OWzWde73P+VmHKKj5dPKSrm9X/AgAA//8ZTssfikQAAA==", "t9ToW2p0L+0FZ19/hhypGUrbTpEct9loTL25uweTdzmH8TDSLi9M6wmnH/D/PTnXtXudOrZn4W3+sNzL",
"v4kFUi/H9FeSeTX37B7u1dHZnH/KfFi5nLWZdfcREE21+/z39sbYgs0RrCHb948prdh0+Tha36z/FwAA",
"///+0r9yf0YAAA==",
} }
// GetSwagger returns the content of the embedded swagger specification file // GetSwagger returns the content of the embedded swagger specification file

View file

@ -3,6 +3,13 @@
// Code generated by github.com/deepmap/oapi-codegen version v1.12.5-0.20230513000919-14548c7e7bbe DO NOT EDIT. // Code generated by github.com/deepmap/oapi-codegen version v1.12.5-0.20230513000919-14548c7e7bbe DO NOT EDIT.
package api package api
import (
"encoding/json"
"errors"
"github.com/deepmap/oapi-codegen/pkg/runtime"
)
const ( const (
BearerAuthScopes = "bearerAuth.Scopes" BearerAuthScopes = "bearerAuth.Scopes"
) )
@ -105,7 +112,7 @@ type ArtistAttributes struct {
Bio *string `json:"bio,omitempty"` Bio *string `json:"bio,omitempty"`
// Name The name of the artist // Name The name of the artist
Name *string `json:"name,omitempty"` Name string `json:"name"`
} }
// ArtistMetaObject defines model for ArtistMetaObject. // ArtistMetaObject defines model for ArtistMetaObject.
@ -139,6 +146,11 @@ type ErrorObject struct {
Title *string `json:"title,omitempty"` Title *string `json:"title,omitempty"`
} }
// IncludedResource defines model for IncludedResource.
type IncludedResource struct {
union json.RawMessage
}
// PaginationLinks defines model for PaginationLinks. // PaginationLinks defines model for PaginationLinks.
type PaginationLinks struct { type PaginationLinks struct {
First *string `json:"first,omitempty"` First *string `json:"first,omitempty"`
@ -443,3 +455,122 @@ type GetTrackParams struct {
// Include Related resources to include in the response, separated by commas // Include Related resources to include in the response, separated by commas
Include *IncludeForTracks `form:"include,omitempty" json:"include,omitempty"` Include *IncludeForTracks `form:"include,omitempty" json:"include,omitempty"`
} }
// AsTrack returns the union data inside the IncludedResource as a Track
func (t IncludedResource) AsTrack() (Track, error) {
var body Track
err := json.Unmarshal(t.union, &body)
return body, err
}
// FromTrack overwrites any union data inside the IncludedResource as the provided Track
func (t *IncludedResource) FromTrack(v Track) error {
v.Type = "track"
b, err := json.Marshal(v)
t.union = b
return err
}
// MergeTrack performs a merge with any union data inside the IncludedResource, using the provided Track
func (t *IncludedResource) MergeTrack(v Track) error {
v.Type = "track"
b, err := json.Marshal(v)
if err != nil {
return err
}
merged, err := runtime.JsonMerge(t.union, b)
t.union = merged
return err
}
// AsAlbum returns the union data inside the IncludedResource as a Album
func (t IncludedResource) AsAlbum() (Album, error) {
var body Album
err := json.Unmarshal(t.union, &body)
return body, err
}
// FromAlbum overwrites any union data inside the IncludedResource as the provided Album
func (t *IncludedResource) FromAlbum(v Album) error {
v.Type = "album"
b, err := json.Marshal(v)
t.union = b
return err
}
// MergeAlbum performs a merge with any union data inside the IncludedResource, using the provided Album
func (t *IncludedResource) MergeAlbum(v Album) error {
v.Type = "album"
b, err := json.Marshal(v)
if err != nil {
return err
}
merged, err := runtime.JsonMerge(t.union, b)
t.union = merged
return err
}
// AsArtist returns the union data inside the IncludedResource as a Artist
func (t IncludedResource) AsArtist() (Artist, error) {
var body Artist
err := json.Unmarshal(t.union, &body)
return body, err
}
// FromArtist overwrites any union data inside the IncludedResource as the provided Artist
func (t *IncludedResource) FromArtist(v Artist) error {
v.Type = "artist"
b, err := json.Marshal(v)
t.union = b
return err
}
// MergeArtist performs a merge with any union data inside the IncludedResource, using the provided Artist
func (t *IncludedResource) MergeArtist(v Artist) error {
v.Type = "artist"
b, err := json.Marshal(v)
if err != nil {
return err
}
merged, err := runtime.JsonMerge(t.union, b)
t.union = merged
return err
}
func (t IncludedResource) Discriminator() (string, error) {
var discriminator struct {
Discriminator string `json:"type"`
}
err := json.Unmarshal(t.union, &discriminator)
return discriminator.Discriminator, err
}
func (t IncludedResource) ValueByDiscriminator() (interface{}, error) {
discriminator, err := t.Discriminator()
if err != nil {
return nil, err
}
switch discriminator {
case "album":
return t.AsAlbum()
case "artist":
return t.AsArtist()
case "track":
return t.AsTrack()
default:
return nil, errors.New("unknown discriminator value: " + discriminator)
}
}
func (t IncludedResource) MarshalJSON() ([]byte, error) {
b, err := t.union.MarshalJSON()
return b, err
}
func (t *IncludedResource) UnmarshalJSON(b []byte) error {
err := t.union.UnmarshalJSON(b)
return err
}