diff --git a/api/dbv1/get_playlists.sql.go b/api/dbv1/get_playlists.sql.go index 94f4c244..c98c7fca 100644 --- a/api/dbv1/get_playlists.sql.go +++ b/api/dbv1/get_playlists.sql.go @@ -58,6 +58,12 @@ SELECT updated_at, release_date, + ( + SELECT COALESCE(SUM(ap.count), 0)::bigint + FROM jsonb_array_elements(COALESCE(p.playlist_contents->'track_ids', '[]'::jsonb)) AS e(item) + LEFT JOIN aggregate_plays ap ON ap.play_item_id = (e.item->>'track')::int + ) AS total_play_count, + ( SELECT count(*) > 0 FROM reposts @@ -159,6 +165,7 @@ type GetPlaylistsRow struct { CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` ReleaseDate *time.Time `json:"release_date"` + TotalPlayCount int64 `json:"total_play_count"` HasCurrentUserReposted bool `json:"has_current_user_reposted"` HasCurrentUserSaved bool `json:"has_current_user_saved"` FolloweeReposts json.RawMessage `json:"followee_reposts"` @@ -200,6 +207,7 @@ func (q *Queries) GetPlaylists(ctx context.Context, arg GetPlaylistsParams) ([]G &i.CreatedAt, &i.UpdatedAt, &i.ReleaseDate, + &i.TotalPlayCount, &i.HasCurrentUserReposted, &i.HasCurrentUserSaved, &i.FolloweeReposts, diff --git a/api/dbv1/models.go b/api/dbv1/models.go index cd5d69fc..340496ee 100644 --- a/api/dbv1/models.go +++ b/api/dbv1/models.go @@ -1394,7 +1394,19 @@ type Play struct { Country pgtype.Text `json:"country"` } -type Playlist struct { +type PlaylistRoute struct { + Slug string `json:"slug"` + TitleSlug string `json:"title_slug"` + CollisionID int32 `json:"collision_id"` + OwnerID int32 `json:"owner_id"` + PlaylistID int32 `json:"playlist_id"` + IsCurrent bool `json:"is_current"` + Blockhash string `json:"blockhash"` + Blocknumber int32 `json:"blocknumber"` + Txhash string `json:"txhash"` +} + +type PlaylistRow struct { Blockhash pgtype.Text `json:"blockhash"` Blocknumber pgtype.Int4 `json:"blocknumber"` PlaylistID int32 `json:"playlist_id"` @@ -1428,18 +1440,6 @@ type Playlist struct { ReleaseDate *time.Time `json:"release_date"` } -type PlaylistRoute struct { - Slug string `json:"slug"` - TitleSlug string `json:"title_slug"` - CollisionID int32 `json:"collision_id"` - OwnerID int32 `json:"owner_id"` - PlaylistID int32 `json:"playlist_id"` - IsCurrent bool `json:"is_current"` - Blockhash string `json:"blockhash"` - Blocknumber int32 `json:"blocknumber"` - Txhash string `json:"txhash"` -} - type PlaylistSeen struct { UserID int32 `json:"user_id"` PlaylistID int32 `json:"playlist_id"` diff --git a/api/dbv1/parallel.go b/api/dbv1/parallel.go index cfdece3f..5b1b400b 100644 --- a/api/dbv1/parallel.go +++ b/api/dbv1/parallel.go @@ -16,7 +16,7 @@ type ParallelParams struct { type ParallelResult struct { UserMap map[int32]User TrackMap map[int32]Track - PlaylistMap map[int32]FullPlaylist + PlaylistMap map[int32]Playlist } func (q *Queries) Parallel(ctx context.Context, arg ParallelParams) (*ParallelResult, error) { @@ -24,7 +24,7 @@ func (q *Queries) Parallel(ctx context.Context, arg ParallelParams) (*ParallelRe var userMap map[int32]User var trackMap map[int32]Track - var playlistMap map[int32]FullPlaylist + var playlistMap map[int32]Playlist if len(arg.UserIds) > 0 { g.Go(func() error { @@ -53,7 +53,7 @@ func (q *Queries) Parallel(ctx context.Context, arg ParallelParams) (*ParallelRe if len(arg.PlaylistIds) > 0 { g.Go(func() error { var err error - playlistMap, err = q.FullPlaylistsKeyed(ctx, FullPlaylistsParams{ + playlistMap, err = q.PlaylistsKeyed(ctx, PlaylistsParams{ GetPlaylistsParams: GetPlaylistsParams{ Ids: arg.PlaylistIds, MyID: arg.MyID, @@ -93,8 +93,8 @@ func (r *ParallelResult) TrackList() []Track { return trackList } -func (r *ParallelResult) PlaylistList() []FullPlaylist { - playlistList := make([]FullPlaylist, 0, len(r.PlaylistMap)) +func (r *ParallelResult) PlaylistList() []Playlist { + playlistList := make([]Playlist, 0, len(r.PlaylistMap)) for _, p := range r.PlaylistMap { playlistList = append(playlistList, p) } diff --git a/api/dbv1/full_playlists.go b/api/dbv1/playlists.go similarity index 53% rename from api/dbv1/full_playlists.go rename to api/dbv1/playlists.go index 047797d6..9394a25f 100644 --- a/api/dbv1/full_playlists.go +++ b/api/dbv1/playlists.go @@ -5,16 +5,15 @@ import ( "fmt" "api.audius.co/trashid" - "github.com/jackc/pgx/v5/pgtype" ) -type FullPlaylistsParams struct { +type PlaylistsParams struct { GetPlaylistsParams OmitTracks bool TrackLimit int // 0 means use default (200), positive values set the limit } -type FullPlaylist struct { +type Playlist struct { GetPlaylistsRow ID string `json:"id"` @@ -28,17 +27,17 @@ type FullPlaylist struct { FolloweeReposts []*FolloweeRepost `json:"followee_reposts"` FolloweeFavorites []*FolloweeFavorite `json:"followee_favorites"` - PlaylistContents []FullPlaylistContentsItem `json:"playlist_contents"` - AddedTimestamps []FullPlaylistContentsItem `json:"added_timestamps"` + PlaylistContents []PlaylistContentsItem `json:"playlist_contents"` + AddedTimestamps []PlaylistContentsItem `json:"added_timestamps"` } -type FullPlaylistContentsItem struct { +type PlaylistContentsItem struct { Time float64 `json:"timestamp"` TrackId string `json:"track_id"` MetadataTime float64 `json:"metadata_timestamp"` } -func (q *Queries) FullPlaylistsKeyed(ctx context.Context, arg FullPlaylistsParams) (map[int32]FullPlaylist, error) { +func (q *Queries) PlaylistsKeyed(ctx context.Context, arg PlaylistsParams) (map[int32]Playlist, error) { rawPlaylists, err := q.GetPlaylists(ctx, arg.GetPlaylistsParams) if err != nil { return nil, err @@ -77,7 +76,7 @@ func (q *Queries) FullPlaylistsKeyed(ctx context.Context, arg FullPlaylistsParam return nil, err } - playlistMap := map[int32]FullPlaylist{} + playlistMap := map[int32]Playlist{} for _, playlist := range rawPlaylists { id, _ := trashid.EncodeHashId(int(playlist.PlaylistID)) user, ok := loaded.UserMap[playlist.PlaylistOwnerID] @@ -97,10 +96,10 @@ func (q *Queries) FullPlaylistsKeyed(ctx context.Context, arg FullPlaylistsParam } // slightly change playlist_contents - fullPlaylistContents := []FullPlaylistContentsItem{} + playlistContents := []PlaylistContentsItem{} for _, item := range playlist.PlaylistContents.TrackIDs { trackId, _ := trashid.EncodeHashId(int(item.Track)) - fullPlaylistContents = append(fullPlaylistContents, FullPlaylistContentsItem{ + playlistContents = append(playlistContents, PlaylistContentsItem{ Time: item.Time, MetadataTime: item.MetadataTime, TrackId: trackId, @@ -123,7 +122,7 @@ func (q *Queries) FullPlaylistsKeyed(ctx context.Context, arg FullPlaylistsParam playlistType = "playlist" } - playlistMap[playlist.PlaylistID] = FullPlaylist{ + playlistMap[playlist.PlaylistID] = Playlist{ GetPlaylistsRow: playlist, ID: id, Artwork: squareImageStruct(playlist.Artwork), @@ -133,9 +132,9 @@ func (q *Queries) FullPlaylistsKeyed(ctx context.Context, arg FullPlaylistsParam TrackCount: int32(len(playlist.PlaylistContents.TrackIDs)), FolloweeFavorites: fullFolloweeFavorites(playlist.FolloweeFavorites), FolloweeReposts: fullFolloweeReposts(playlist.FolloweeReposts), - PlaylistContents: fullPlaylistContents, + PlaylistContents: playlistContents, Permalink: fmt.Sprintf("/%s/%s/%s", user.Handle.String, playlistType, playlist.Slug.String), - AddedTimestamps: fullPlaylistContents, + AddedTimestamps: playlistContents, Access: Access{ Stream: streamAccess, Download: downloadAccess, @@ -146,79 +145,20 @@ func (q *Queries) FullPlaylistsKeyed(ctx context.Context, arg FullPlaylistsParam return playlistMap, nil } -func (q *Queries) FullPlaylists(ctx context.Context, arg FullPlaylistsParams) ([]FullPlaylist, error) { - playlistMap, err := q.FullPlaylistsKeyed(ctx, arg) +func (q *Queries) Playlists(ctx context.Context, arg PlaylistsParams) ([]Playlist, error) { + playlistMap, err := q.PlaylistsKeyed(ctx, arg) if err != nil { return nil, err } // return in same order as input list of ids // some ids may be not found... - fullPlaylists := []FullPlaylist{} + list := make([]Playlist, 0, len(arg.Ids)) for _, id := range arg.Ids { - if t, found := playlistMap[id]; found { - fullPlaylists = append(fullPlaylists, t) + if p, found := playlistMap[id]; found { + list = append(list, p) } } - return fullPlaylists, nil -} - -type MinPlaylist struct { - ID string `json:"id"` - PlaylistName pgtype.Text `json:"playlist_name"` - Artwork *SquareImage `json:"artwork"` - Access Access `json:"access"` - Description string `json:"description"` - IsImageAutogenerated bool `json:"is_image_autogenerated"` - Upc string `json:"upc"` - DdexApp string `json:"ddex_app"` - PlaylistContents interface{} `json:"playlist_contents"` - TrackCount int32 `json:"track_count"` - TotalPlayCount int64 `json:"total_play_count"` - IsAlbum bool `json:"is_album"` - FavoriteCount int32 `json:"favorite_count"` - RepostCount int32 `json:"repost_count"` - User User `json:"user"` - Permalink string `json:"permalink"` -} - -func ToMinPlaylist(fullPlaylist FullPlaylist) MinPlaylist { - minTracks := make([]Track, len(fullPlaylist.Tracks)) - for i, track := range fullPlaylist.Tracks { - minTracks[i] = track - } - - return MinPlaylist{ - ID: fullPlaylist.ID, - PlaylistName: fullPlaylist.PlaylistName, - Artwork: fullPlaylist.Artwork, - Access: fullPlaylist.Access, - Upc: fullPlaylist.Upc.String, - DdexApp: fullPlaylist.DdexApp.String, - PlaylistContents: fullPlaylist.PlaylistContents, - Description: fullPlaylist.Description.String, - IsImageAutogenerated: fullPlaylist.IsImageAutogenerated, - IsAlbum: fullPlaylist.IsAlbum, - TrackCount: int32(len(fullPlaylist.Tracks)), - TotalPlayCount: func() int64 { - var total int64 - for _, track := range fullPlaylist.Tracks { - total += track.PlayCount - } - return total - }(), - FavoriteCount: int32(fullPlaylist.FavoriteCount.Int32), - RepostCount: int32(fullPlaylist.RepostCount.Int32), - User: fullPlaylist.User, - Permalink: fullPlaylist.Permalink, - } -} - -func ToMinPlaylists(fullPlaylists []FullPlaylist) []MinPlaylist { - result := make([]MinPlaylist, len(fullPlaylists)) - for i, playlist := range fullPlaylists { - result[i] = ToMinPlaylist(playlist) - } - return result + return list, nil } diff --git a/api/dbv1/queries/get_playlists.sql b/api/dbv1/queries/get_playlists.sql index c8f9c7de..a0bf2db5 100644 --- a/api/dbv1/queries/get_playlists.sql +++ b/api/dbv1/queries/get_playlists.sql @@ -43,6 +43,12 @@ SELECT updated_at, release_date, + ( + SELECT COALESCE(SUM(ap.count), 0)::bigint + FROM jsonb_array_elements(COALESCE(p.playlist_contents->'track_ids', '[]'::jsonb)) AS e(item) + LEFT JOIN aggregate_plays ap ON ap.play_item_id = (e.item->>'track')::int + ) AS total_play_count, + ( SELECT count(*) > 0 FROM reposts diff --git a/api/response_helpers.go b/api/response_helpers.go index 349279ac..d93843c4 100644 --- a/api/response_helpers.go +++ b/api/response_helpers.go @@ -29,25 +29,16 @@ func v1UsersResponse(c *fiber.Ctx, users []dbv1.User) error { // Note: playlist response returned an array even though it's a single playlist // Done for backwards compatibility. Would be nice to get rid of this. -func v1PlaylistResponse(c *fiber.Ctx, playlist dbv1.FullPlaylist) error { - if c.Locals("isFull").(bool) { - return c.JSON(fiber.Map{ - "data": []dbv1.FullPlaylist{playlist}, - }) - } +// Default and full both return full playlist shape (min-collection parity with full). +func v1PlaylistResponse(c *fiber.Ctx, playlist dbv1.Playlist) error { return c.JSON(fiber.Map{ - "data": []dbv1.MinPlaylist{dbv1.ToMinPlaylist(playlist)}, + "data": []dbv1.Playlist{playlist}, }) } -func v1PlaylistsResponse(c *fiber.Ctx, playlists []dbv1.FullPlaylist) error { - if c.Locals("isFull").(bool) { - return c.JSON(fiber.Map{ - "data": playlists, - }) - } +func v1PlaylistsResponse(c *fiber.Ctx, playlists []dbv1.Playlist) error { return c.JSON(fiber.Map{ - "data": dbv1.ToMinPlaylists(playlists), + "data": playlists, }) } diff --git a/api/swagger/swagger-v1.yaml b/api/swagger/swagger-v1.yaml index 5e4e6342..4e7114f8 100644 --- a/api/swagger/swagger-v1.yaml +++ b/api/swagger/swagger-v1.yaml @@ -661,6 +661,11 @@ paths: description: The number of items to fetch schema: type: integer + - name: user_id + in: query + description: The user ID of the user making the request + schema: + type: string - name: time in: query description: Calculate trending over a specified time range @@ -5433,17 +5438,30 @@ components: playlist: required: - access + - added_timestamps + - blocknumber + - created_at - favorite_count + - followee_favorites + - followee_reposts + - has_current_user_reposted + - has_current_user_saved - id - is_album + - is_delete - is_image_autogenerated + - is_private + - is_scheduled_release + - is_stream_gated - permalink - playlist_contents - playlist_name - repost_count - total_play_count - track_count + - updated_at - user + - user_id type: object properties: artwork: @@ -5480,6 +5498,72 @@ components: type: string track_count: type: integer + blocknumber: + type: integer + created_at: + type: string + followee_reposts: + type: array + items: + $ref: '#/components/schemas/repost' + followee_favorites: + type: array + items: + $ref: '#/components/schemas/favorite' + has_current_user_reposted: + type: boolean + has_current_user_saved: + type: boolean + is_delete: + type: boolean + is_private: + type: boolean + updated_at: + type: string + added_timestamps: + type: array + description: DEPRECATED. Use playlist_contents instead. + items: + $ref: '#/components/schemas/playlist_added_timestamp' + user_id: + type: string + tracks: + type: array + items: + $ref: '#/components/schemas/Track' + cover_art: + type: string + cover_art_sizes: + type: string + cover_art_cids: + $ref: '#/components/schemas/playlist_artwork' + is_stream_gated: + type: boolean + stream_conditions: + type: object + description: How to unlock stream access to the track + allOf: + - $ref: '#/components/schemas/access_gate' + is_scheduled_release: + type: boolean + release_date: + type: string + ddex_release_ids: + type: object + properties: {} + artists: + type: array + items: + type: object + properties: {} + copyright_line: + type: object + properties: {} + producer_copyright_line: + type: object + properties: {} + parental_warning_type: + type: string playlist_artwork: type: object properties: @@ -5526,6 +5610,19 @@ components: type: array items: $ref: '#/components/schemas/favorite' + repost: + required: + - repost_item_id + - repost_type + - user_id + type: object + properties: + repost_item_id: + type: string + repost_type: + type: string + user_id: + type: string favorite: required: - created_at diff --git a/api/v1_explore_best_selling_test.go b/api/v1_explore_best_selling_test.go index 4bc49f22..7baa634b 100644 --- a/api/v1_explore_best_selling_test.go +++ b/api/v1_explore_best_selling_test.go @@ -285,7 +285,7 @@ func TestExploreBestSelling(t *testing.T) { Data []BestSellingItem Related struct { Tracks []dbv1.Track - Playlists []dbv1.FullPlaylist + Playlists []dbv1.Playlist } } diff --git a/api/v1_playlist.go b/api/v1_playlist.go index 4d759169..414915f3 100644 --- a/api/v1_playlist.go +++ b/api/v1_playlist.go @@ -9,7 +9,7 @@ func (app *ApiServer) v1Playlist(c *fiber.Ctx) error { myId := app.getMyId(c) playlistId := c.Locals("playlistId").(int) - playlists, err := app.queries.FullPlaylists(c.Context(), dbv1.FullPlaylistsParams{ + playlists, err := app.queries.Playlists(c.Context(), dbv1.PlaylistsParams{ GetPlaylistsParams: dbv1.GetPlaylistsParams{ MyID: myId, Ids: []int32{int32(playlistId)}, diff --git a/api/v1_playlist_by_permalink.go b/api/v1_playlist_by_permalink.go index 0adaffee..3d75f77b 100644 --- a/api/v1_playlist_by_permalink.go +++ b/api/v1_playlist_by_permalink.go @@ -28,7 +28,7 @@ func (app *ApiServer) v1PlaylistByPermalink(c *fiber.Ctx) error { return err } - playlists, err := app.queries.FullPlaylists(c.Context(), dbv1.FullPlaylistsParams{ + playlists, err := app.queries.Playlists(c.Context(), dbv1.PlaylistsParams{ GetPlaylistsParams: dbv1.GetPlaylistsParams{ MyID: myId, Ids: ids, diff --git a/api/v1_playlist_stream.go b/api/v1_playlist_stream.go index b1fdc844..63d6a8e3 100644 --- a/api/v1_playlist_stream.go +++ b/api/v1_playlist_stream.go @@ -13,7 +13,7 @@ func (app *ApiServer) v1PlaylistStream(c *fiber.Ctx) error { myId := app.getMyId(c) playlistId := c.Locals("playlistId").(int) - playlists, err := app.queries.FullPlaylists(c.Context(), dbv1.FullPlaylistsParams{ + playlists, err := app.queries.Playlists(c.Context(), dbv1.PlaylistsParams{ GetPlaylistsParams: dbv1.GetPlaylistsParams{ MyID: myId, Ids: []int32{int32(playlistId)}, diff --git a/api/v1_playlist_test.go b/api/v1_playlist_test.go index 724f9ebd..223b0baa 100644 --- a/api/v1_playlist_test.go +++ b/api/v1_playlist_test.go @@ -11,7 +11,7 @@ import ( func TestGetPlaylist(t *testing.T) { app := testAppWithFixtures(t) var playlistResponse struct { - Data []dbv1.FullPlaylist + Data []dbv1.Playlist } status, body := testGet(t, app, "/v1/full/playlists/7eP5n", &playlistResponse) @@ -27,7 +27,7 @@ func TestGetPlaylist(t *testing.T) { func TestGetPlaylistFollowDownloadAccess(t *testing.T) { app := testAppWithFixtures(t) var playlistResponse struct { - Data []dbv1.FullPlaylist + Data []dbv1.Playlist } // No access _, body1 := testGet(t, app, "/v1/full/playlists/ML51L", &playlistResponse) @@ -52,7 +52,7 @@ func TestGetPlaylistFollowDownloadAccess(t *testing.T) { func TestGetPlaylistUsdcPurchaseStreamAccess(t *testing.T) { app := testAppWithFixtures(t) var playlistResponse struct { - Data []dbv1.FullPlaylist + Data []dbv1.Playlist } // No access _, body1 := testGet(t, app, "/v1/full/playlists/ELKzn", &playlistResponse) @@ -77,7 +77,7 @@ func TestGetPlaylistUsdcPurchaseStreamAccess(t *testing.T) { func TestGetPlaylistUsdcPurchaseSelfAccess(t *testing.T) { app := testAppWithFixtures(t) var playlistResponse struct { - Data []dbv1.FullPlaylist + Data []dbv1.Playlist } // No access. User 3 is the owner, but has not signed authorization status, _ := testGet( diff --git a/api/v1_playlists.go b/api/v1_playlists.go index 4afdd6c7..a43e4a81 100644 --- a/api/v1_playlists.go +++ b/api/v1_playlists.go @@ -49,7 +49,7 @@ func (app *ApiServer) v1Playlists(c *fiber.Ctx) error { ids = append(ids, newIds...) } - playlists, err := app.queries.FullPlaylists(c.Context(), dbv1.FullPlaylistsParams{ + playlists, err := app.queries.Playlists(c.Context(), dbv1.PlaylistsParams{ GetPlaylistsParams: dbv1.GetPlaylistsParams{ MyID: myId, Ids: ids, diff --git a/api/v1_playlists_test.go b/api/v1_playlists_test.go index 1508857b..da2ec1b4 100644 --- a/api/v1_playlists_test.go +++ b/api/v1_playlists_test.go @@ -34,7 +34,7 @@ func TestPlaylistsEndpointWithTracks(t *testing.T) { func TestPlaylistsEndpointWithPlaylistPermalink(t *testing.T) { app := testAppWithFixtures(t) var resp struct { - Data []dbv1.FullPlaylist + Data []dbv1.Playlist } status, body := testGet(t, app, "/v1/full/playlists?permalink=/PlaylistsByPermalink/playlist/playlist-by-permalink", &resp) @@ -49,7 +49,7 @@ func TestPlaylistsEndpointWithPlaylistPermalink(t *testing.T) { func TestPlaylistsEndpointWithAlbumPermalink(t *testing.T) { app := testAppWithFixtures(t) var resp struct { - Data []dbv1.FullPlaylist + Data []dbv1.Playlist } status, body := testGet(t, app, "/v1/full/playlists?permalink=/AlbumsByPermalink/album/album-by-permalink", &resp) diff --git a/api/v1_playlists_top.go b/api/v1_playlists_top.go index dfb1f983..5555c5d5 100644 --- a/api/v1_playlists_top.go +++ b/api/v1_playlists_top.go @@ -42,7 +42,7 @@ func (app *ApiServer) v1PlaylistsTop(c *fiber.Ctx) error { myId = app.getMyId(c) } - playlists, err := app.queries.FullPlaylists(c.Context(), dbv1.FullPlaylistsParams{ + playlists, err := app.queries.Playlists(c.Context(), dbv1.PlaylistsParams{ GetPlaylistsParams: dbv1.GetPlaylistsParams{ Ids: playlistsIds, MyID: myId, diff --git a/api/v1_playlists_trending.go b/api/v1_playlists_trending.go index 575f7333..ee9ebf2a 100644 --- a/api/v1_playlists_trending.go +++ b/api/v1_playlists_trending.go @@ -106,7 +106,7 @@ func (app *ApiServer) v1PlaylistsTrending(c *fiber.Ctx) error { return err } - playlists, err := app.queries.FullPlaylists(c.Context(), dbv1.FullPlaylistsParams{ + playlists, err := app.queries.Playlists(c.Context(), dbv1.PlaylistsParams{ GetPlaylistsParams: dbv1.GetPlaylistsParams{ Ids: ids, MyID: myId, diff --git a/api/v1_search.go b/api/v1_search.go index f15cb09e..fb82a9bc 100644 --- a/api/v1_search.go +++ b/api/v1_search.go @@ -16,8 +16,8 @@ func (app *ApiServer) v1SearchFull(c *fiber.Ctx) error { g := errgroup.Group{} var users = []dbv1.User{} var tracks = []dbv1.Track{} - var playlists = []dbv1.FullPlaylist{} - var albums = []dbv1.FullPlaylist{} + var playlists = []dbv1.Playlist{} + var albums = []dbv1.Playlist{} // users g.Go(func() (err error) { @@ -178,7 +178,7 @@ func (app *ApiServer) searchTracks(c *fiber.Ctx) ([]dbv1.Track, error) { return tracks, err } -func (app *ApiServer) searchPlaylists(c *fiber.Ctx) ([]dbv1.FullPlaylist, error) { +func (app *ApiServer) searchPlaylists(c *fiber.Ctx) ([]dbv1.Playlist, error) { isTagSearch := strings.Contains(c.Route().Path, "search/tags") isFullSearch := strings.Contains(c.Route().Path, "search/full") limit := c.QueryInt("limit", 10) @@ -209,7 +209,7 @@ func (app *ApiServer) searchPlaylists(c *fiber.Ctx) ([]dbv1.FullPlaylist, error) myId = 0 } - playlists, err := app.queries.FullPlaylists(c.Context(), dbv1.FullPlaylistsParams{ + playlists, err := app.queries.Playlists(c.Context(), dbv1.PlaylistsParams{ GetPlaylistsParams: dbv1.GetPlaylistsParams{ Ids: playlistsIds, MyID: myId, @@ -219,7 +219,7 @@ func (app *ApiServer) searchPlaylists(c *fiber.Ctx) ([]dbv1.FullPlaylist, error) return playlists, err } -func (app *ApiServer) searchAlbums(c *fiber.Ctx) ([]dbv1.FullPlaylist, error) { +func (app *ApiServer) searchAlbums(c *fiber.Ctx) ([]dbv1.Playlist, error) { isTagSearch := strings.Contains(c.Route().Path, "search/tags") isFullSearch := strings.Contains(c.Route().Path, "search/full") limit := c.QueryInt("limit", 10) @@ -251,7 +251,7 @@ func (app *ApiServer) searchAlbums(c *fiber.Ctx) ([]dbv1.FullPlaylist, error) { myId = 0 } - playlists, err := app.queries.FullPlaylists(c.Context(), dbv1.FullPlaylistsParams{ + playlists, err := app.queries.Playlists(c.Context(), dbv1.PlaylistsParams{ GetPlaylistsParams: dbv1.GetPlaylistsParams{ Ids: playlistsIds, MyID: myId, diff --git a/api/v1_users_albums.go b/api/v1_users_albums.go index f293e7ca..5b9ea558 100644 --- a/api/v1_users_albums.go +++ b/api/v1_users_albums.go @@ -82,7 +82,7 @@ func (app *ApiServer) v1UserAlbums(c *fiber.Ctx) error { return err } - albums, err := app.queries.FullPlaylists(c.Context(), dbv1.FullPlaylistsParams{ + albums, err := app.queries.Playlists(c.Context(), dbv1.PlaylistsParams{ GetPlaylistsParams: dbv1.GetPlaylistsParams{ Ids: ids, MyID: myId, diff --git a/api/v1_users_albums_test.go b/api/v1_users_albums_test.go index e4cfd349..77e7e809 100644 --- a/api/v1_users_albums_test.go +++ b/api/v1_users_albums_test.go @@ -45,7 +45,7 @@ func TestGetUserAlbums(t *testing.T) { database.Seed(app.pool.Replicas[0], fixtures) var userAlbumsResponse struct { - Data []dbv1.FullPlaylist + Data []dbv1.Playlist } { @@ -101,7 +101,7 @@ func TestGetUserAlbums_SortRecentDesc(t *testing.T) { database.Seed(app.pool.Replicas[0], fixtures) var userAlbumsResponse struct { - Data []dbv1.FullPlaylist + Data []dbv1.Playlist } status, body := testGet(t, app, "/v1/full/users/handle/one/albums?sort_method=recent&sort_direction=desc", &userAlbumsResponse) @@ -147,7 +147,7 @@ func TestGetUserAlbums_SortPopularAsc(t *testing.T) { database.Seed(app.pool.Replicas[0], fixtures) var userAlbumsResponse struct { - Data []dbv1.FullPlaylist + Data []dbv1.Playlist } status, body := testGet(t, app, "/v1/full/users/handle/one/albums?sort_method=popular&sort_direction=asc", &userAlbumsResponse) @@ -196,7 +196,7 @@ func TestGetUserAlbums_FilterAlbumsPublic(t *testing.T) { database.Seed(app.pool.Replicas[0], fixtures) var userAlbumsResponse struct { - Data []dbv1.FullPlaylist + Data []dbv1.Playlist } status, body := testGet(t, app, "/v1/full/users/handle/one/albums?filter_albums=public", &userAlbumsResponse) @@ -245,7 +245,7 @@ func TestGetUserAlbums_FilterAlbumsPrivate(t *testing.T) { database.Seed(app.pool.Replicas[0], fixtures) var userAlbumsResponse struct { - Data []dbv1.FullPlaylist + Data []dbv1.Playlist } status, body := testGet(t, app, "/v1/full/users/handle/one/albums?filter_albums=private", &userAlbumsResponse) diff --git a/api/v1_users_library_playlists.go b/api/v1_users_library_playlists.go index 8e55cd9c..49e737d5 100644 --- a/api/v1_users_library_playlists.go +++ b/api/v1_users_library_playlists.go @@ -159,7 +159,7 @@ func (app *ApiServer) v1UsersLibraryPlaylists(c *fiber.Ctx) error { } // get playlists - playlists, err := app.queries.FullPlaylistsKeyed(c.Context(), dbv1.FullPlaylistsParams{ + playlists, err := app.queries.PlaylistsKeyed(c.Context(), dbv1.PlaylistsParams{ GetPlaylistsParams: dbv1.GetPlaylistsParams{ Ids: ids, MyID: myId, diff --git a/api/v1_users_playlists.go b/api/v1_users_playlists.go index 31b02d1a..cc607b4a 100644 --- a/api/v1_users_playlists.go +++ b/api/v1_users_playlists.go @@ -82,7 +82,7 @@ func (app *ApiServer) v1UserPlaylists(c *fiber.Ctx) error { return err } - playlists, err := app.queries.FullPlaylists(c.Context(), dbv1.FullPlaylistsParams{ + playlists, err := app.queries.Playlists(c.Context(), dbv1.PlaylistsParams{ GetPlaylistsParams: dbv1.GetPlaylistsParams{ Ids: ids, MyID: myId, diff --git a/api/v1_users_playlists_test.go b/api/v1_users_playlists_test.go index 5402d58d..74926bc3 100644 --- a/api/v1_users_playlists_test.go +++ b/api/v1_users_playlists_test.go @@ -45,7 +45,7 @@ func TestGetUserPlaylists(t *testing.T) { database.Seed(app.pool.Replicas[0], fixtures) var userPlaylistsResponse struct { - Data []dbv1.FullPlaylist + Data []dbv1.Playlist } { @@ -101,7 +101,7 @@ func TestGetUserPlaylists_SortRecentDesc(t *testing.T) { database.Seed(app.pool.Replicas[0], fixtures) var userPlaylistsResponse struct { - Data []dbv1.FullPlaylist + Data []dbv1.Playlist } status, body := testGet(t, app, "/v1/full/users/handle/one/playlists?sort_method=recent&sort_direction=desc", &userPlaylistsResponse) @@ -147,7 +147,7 @@ func TestGetUserPlaylists_SortPopularAsc(t *testing.T) { database.Seed(app.pool.Replicas[0], fixtures) var userPlaylistsResponse struct { - Data []dbv1.FullPlaylist + Data []dbv1.Playlist } status, body := testGet(t, app, "/v1/full/users/handle/one/playlists?sort_method=popular&sort_direction=asc", &userPlaylistsResponse) @@ -196,7 +196,7 @@ func TestGetUserPlaylists_FilterPlaylistsPublic(t *testing.T) { database.Seed(app.pool.Replicas[0], fixtures) var userPlaylistsResponse struct { - Data []dbv1.FullPlaylist + Data []dbv1.Playlist } status, body := testGet(t, app, "/v1/full/users/handle/one/playlists?filter_playlists=public", &userPlaylistsResponse) @@ -245,7 +245,7 @@ func TestGetUserPlaylists_FilterPlaylistsPrivate(t *testing.T) { database.Seed(app.pool.Replicas[0], fixtures) var userPlaylistsResponse struct { - Data []dbv1.FullPlaylist + Data []dbv1.Playlist } status, body := testGet(t, app, "/v1/full/users/handle/one/playlists?filter_playlists=private", &userPlaylistsResponse) diff --git a/sqlc.yaml b/sqlc.yaml index 81b0c887..eda778b8 100644 --- a/sqlc.yaml +++ b/sqlc.yaml @@ -13,6 +13,7 @@ sql: rename: user: UserRow track: TrackRow + playlist: PlaylistRow overrides: - db_type: "pg_catalog.timestamp" engine: "postgresql"