Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions api/dbv1/parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
)

type ParallelParams struct {
UserIds []int32
TrackIds []int32
PlaylistIds []int32
MyID int32
AuthedWallet string
UserIds []int32
TrackIds []int32
PlaylistIds []int32
MyID int32
AuthedWallet string
IncludeUnlisted bool
}

type ParallelResult struct {
Expand Down Expand Up @@ -43,9 +44,10 @@ func (q *Queries) Parallel(ctx context.Context, arg ParallelParams) (*ParallelRe
var err error
trackMap, err = q.TracksKeyed(ctx, TracksParams{
GetTracksParams: GetTracksParams{
Ids: arg.TrackIds,
MyID: arg.MyID,
AuthedWallet: arg.AuthedWallet,
Ids: arg.TrackIds,
MyID: arg.MyID,
AuthedWallet: arg.AuthedWallet,
IncludeUnlisted: arg.IncludeUnlisted,
},
})
return err
Expand Down
9 changes: 5 additions & 4 deletions api/dbv1/playlists.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ func (q *Queries) PlaylistsKeyed(ctx context.Context, arg PlaylistsParams) (map[

// fetch users + tracks in parallel
loaded, err := q.Parallel(ctx, ParallelParams{
UserIds: userIds,
TrackIds: trackIds,
MyID: arg.MyID.(int32),
AuthedWallet: arg.AuthedWallet,
UserIds: userIds,
TrackIds: trackIds,
MyID: arg.MyID.(int32),
AuthedWallet: arg.AuthedWallet,
IncludeUnlisted: true,
})
if err != nil {
return nil, err
Expand Down
56 changes: 56 additions & 0 deletions api/v1_playlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"api.audius.co/api/dbv1"
"api.audius.co/database"
"api.audius.co/trashid"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -99,3 +100,58 @@ func TestGetPlaylistUsdcPurchaseSelfAccess(t *testing.T) {
"data.0.access": `{"stream":true,"download":true}`,
})
}

func TestGetPlaylistIncludesUnlistedTracks(t *testing.T) {
app := emptyTestApp(t)

fixtures := database.FixtureMap{
"users": []map[string]any{
{
"user_id": 1,
"handle": "user1",
"name": "User 1",
},
},
"tracks": []map[string]any{
{
"track_id": 1,
"owner_id": 1,
"title": "Listed Track",
},
{
"track_id": 2,
"owner_id": 1,
"title": "Unlisted Track",
"is_unlisted": true,
},
},
"playlists": []map[string]any{
{
"playlist_id": 1,
"playlist_owner_id": 1,
"playlist_contents": map[string]any{
"track_ids": []map[string]any{
{"track": 1, "time": 1, "metadata_time": 1},
{"track": 2, "time": 2, "metadata_time": 2},
},
},
},
},
}
database.Seed(app.pool.Replicas[0], fixtures)

playlistId := trashid.MustEncodeHashID(1)

var playlistResponse struct {
Data []dbv1.Playlist
}
status, body := testGet(t, app, "/v1/full/playlists/"+playlistId, &playlistResponse)
assert.Equal(t, 200, status)

// Both listed and unlisted tracks should appear in the hydrated tracks array
jsonAssert(t, body, map[string]any{
"data.0.tracks.#": 2,
"data.0.tracks.0.id": trashid.MustEncodeHashID(1),
"data.0.tracks.1.id": trashid.MustEncodeHashID(2),
})
}
7 changes: 4 additions & 3 deletions api/v1_playlist_tracks.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ func (app *ApiServer) v1PlaylistTracks(c *fiber.Ctx) error {

tracks, err := app.queries.Tracks(c.Context(), dbv1.TracksParams{
GetTracksParams: dbv1.GetTracksParams{
Ids: trackIds,
MyID: myId,
AuthedWallet: app.tryGetAuthedWallet(c),
Ids: trackIds,
MyID: myId,
AuthedWallet: app.tryGetAuthedWallet(c),
IncludeUnlisted: true,
},
})

Expand Down
62 changes: 62 additions & 0 deletions api/v1_playlist_tracks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,65 @@ func TestV1PlaylistTracks(t *testing.T) {
})
}
}

func TestV1PlaylistTracksIncludesUnlisted(t *testing.T) {
app := emptyTestApp(t)

fixtures := database.FixtureMap{
"users": []map[string]any{
{
"user_id": 1,
"handle": "user1",
"name": "User 1",
},
},
"tracks": []map[string]any{
{
"track_id": 1,
"owner_id": 1,
"title": "Listed Track",
},
{
"track_id": 2,
"owner_id": 1,
"title": "Unlisted Track",
"is_unlisted": true,
},
},
"playlists": []map[string]any{
{
"playlist_id": 1,
"playlist_owner_id": 1,
"playlist_contents": map[string]any{
"track_ids": []map[string]any{
{"track": 1, "time": 1, "metadata_time": 1},
{"track": 2, "time": 2, "metadata_time": 2},
},
},
},
},
}
database.Seed(app.pool.Replicas[0], fixtures)

playlistId := trashid.MustEncodeHashID(1)

// GET /v1/playlists/:id/tracks should include unlisted tracks
{
status, body := testGet(t, app, "/v1/playlists/"+playlistId+"/tracks", nil)
assert.Equal(t, 200, status)
jsonAssert(t, body, map[string]any{
"data.#": 2,
"data.0.id": trashid.MustEncodeHashID(1),
"data.1.id": trashid.MustEncodeHashID(2),
})
}

// Also works with exclude_gated=false
{
status, body := testGet(t, app, "/v1/playlists/"+playlistId+"/tracks?exclude_gated=false", nil)
assert.Equal(t, 200, status)
jsonAssert(t, body, map[string]any{
"data.#": 2,
})
}
}
Loading