@@ -2,6 +2,7 @@ package dbv1
22
33import (
44 "context"
5+ "fmt"
56
67 "bridgerton.audius.co/trashid"
78 "github.com/jackc/pgx/v5/pgtype"
@@ -10,12 +11,13 @@ import (
1011type FullPlaylist struct {
1112 GetPlaylistsRow
1213
13- ID string `json:"id"`
14- Artwork * SquareImage `json:"artwork"`
15- UserID trashid.HashId `json:"user_id"`
16- User FullUser `json:"user"`
17- Tracks []FullTrack `json:"tracks"`
18- Access Access `json:"access"`
14+ ID string `json:"id"`
15+ Artwork * SquareImage `json:"artwork"`
16+ UserID trashid.HashId `json:"user_id"`
17+ User FullUser `json:"user"`
18+ Tracks []FullTrack `json:"tracks"`
19+ Access Access `json:"access"`
20+ Permalink string `json:"permalink"`
1921
2022 FolloweeReposts []* FolloweeRepost `json:"followee_reposts"`
2123 FolloweeFavorites []* FolloweeFavorite `json:"followee_favorites"`
@@ -89,6 +91,13 @@ func (q *Queries) FullPlaylistsKeyed(ctx context.Context, arg GetPlaylistsParams
8991 streamAccess := q .GetPlaylistAccess (ctx , arg .MyID .(int32 ), playlist .StreamConditions , & playlist , & user )
9092 downloadAccess := streamAccess
9193
94+ var playlistType string
95+ if playlist .IsAlbum {
96+ playlistType = "album"
97+ } else {
98+ playlistType = "playlist"
99+ }
100+
92101 playlistMap [playlist .PlaylistID ] = FullPlaylist {
93102 GetPlaylistsRow : playlist ,
94103 ID : id ,
@@ -99,6 +108,7 @@ func (q *Queries) FullPlaylistsKeyed(ctx context.Context, arg GetPlaylistsParams
99108 FolloweeFavorites : fullFolloweeFavorites (playlist .FolloweeFavorites ),
100109 FolloweeReposts : fullFolloweeReposts (playlist .FolloweeReposts ),
101110 PlaylistContents : fullPlaylistContents ,
111+ Permalink : fmt .Sprintf ("/%s/%s/%s" , user .Handle .String , playlistType , playlist .Slug .String ),
102112 AddedTimestamps : fullPlaylistContents ,
103113 Access : Access {
104114 Stream : streamAccess ,
@@ -129,20 +139,22 @@ func (q *Queries) FullPlaylists(ctx context.Context, arg GetPlaylistsParams) ([]
129139}
130140
131141type MinPlaylist struct {
132- ID string `json:"id"`
133- PlaylistName pgtype.Text `json:"playlist_name"`
134- PlaylistOwnerID int32 `json:"playlist_owner_id"`
135- PlaylistID int32 `json:"playlist_id"`
136- Artwork * SquareImage `json:"artwork"`
137- Description * string `json:"description"`
138- PlaylistContents interface {} `json:"playlist_contents"`
139- IsAlbum bool `json:"is_album"`
140- IsPrivate bool `json:"is_private"`
141- FavoriteCount int32 `json:"favorite_count"`
142- RepostCount int32 `json:"repost_count"`
143- UserID trashid.HashId `json:"user_id"`
144- User MinUser `json:"user"`
145- Tracks []MinTrack `json:"tracks"`
142+ ID string `json:"id"`
143+ PlaylistName pgtype.Text `json:"playlist_name"`
144+ Artwork * SquareImage `json:"artwork"`
145+ Access Access `json:"access"`
146+ Description string `json:"description"`
147+ IsImageAutogenerated bool `json:"is_image_autogenerated"`
148+ Upc string `json:"upc"`
149+ DdexApp string `json:"ddex_app"`
150+ PlaylistContents interface {} `json:"playlist_contents"`
151+ TrackCount int32 `json:"track_count"`
152+ TotalPlayCount int64 `json:"total_play_count"`
153+ IsAlbum bool `json:"is_album"`
154+ FavoriteCount int32 `json:"favorite_count"`
155+ RepostCount int32 `json:"repost_count"`
156+ User MinUser `json:"user"`
157+ Permalink string `json:"permalink"`
146158}
147159
148160func ToMinPlaylist (fullPlaylist FullPlaylist ) MinPlaylist {
@@ -152,20 +164,30 @@ func ToMinPlaylist(fullPlaylist FullPlaylist) MinPlaylist {
152164 }
153165
154166 return MinPlaylist {
155- ID : fullPlaylist .ID ,
156- PlaylistName : fullPlaylist .PlaylistName ,
157- PlaylistOwnerID : fullPlaylist .PlaylistOwnerID ,
158- PlaylistID : fullPlaylist .PlaylistID ,
159- Artwork : fullPlaylist .Artwork ,
160- PlaylistContents : fullPlaylist .PlaylistContents ,
161- Description : nil ,
162- IsAlbum : false ,
163- IsPrivate : false ,
164- FavoriteCount : 0 ,
165- RepostCount : 0 ,
166- UserID : fullPlaylist .UserID ,
167- User : ToMinUser (fullPlaylist .User ),
168- Tracks : minTracks ,
167+ ID : fullPlaylist .ID ,
168+ PlaylistName : fullPlaylist .PlaylistName ,
169+ Artwork : fullPlaylist .Artwork ,
170+ Access : fullPlaylist .Access ,
171+ Upc : fullPlaylist .Upc .String ,
172+ DdexApp : fullPlaylist .DdexApp .String ,
173+ PlaylistContents : fullPlaylist .PlaylistContents ,
174+ Description : fullPlaylist .Description .String ,
175+ IsImageAutogenerated : fullPlaylist .IsImageAutogenerated ,
176+ IsAlbum : fullPlaylist .IsAlbum ,
177+ TrackCount : int32 (len (fullPlaylist .Tracks )),
178+ TotalPlayCount : func () int64 {
179+ var total int64
180+ for _ , track := range fullPlaylist .Tracks {
181+ if track .PlayCount .Valid {
182+ total += track .PlayCount .Int64
183+ }
184+ }
185+ return total
186+ }(),
187+ FavoriteCount : int32 (fullPlaylist .FavoriteCount .Int32 ),
188+ RepostCount : int32 (fullPlaylist .RepostCount .Int32 ),
189+ User : ToMinUser (fullPlaylist .User ),
190+ Permalink : fullPlaylist .Permalink ,
169191 }
170192}
171193
0 commit comments