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
3 changes: 2 additions & 1 deletion api/v1_track_stems.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ func (app *ApiServer) v1TrackStems(c *fiber.Ctx) error {
t.track_cid,
t.owner_id,
t.blocknumber,
t.orig_filename
COALESCE(t.orig_filename, t.title, '') AS orig_filename
FROM tracks t
JOIN stems s ON s.child_track_id = t.track_id
JOIN tracks parent ON parent.track_id = s.parent_track_id
WHERE t.is_current = true
AND t.is_delete = false
AND s.parent_track_id = @track_id
AND parent.is_delete = false
ORDER BY t.track_id
`

rows, err := app.pool.Query(c.Context(), sql, pgx.NamedArgs{
Expand Down
23 changes: 22 additions & 1 deletion api/v1_track_stems_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ func TestGetTrackStems(t *testing.T) {
"category": "vocals",
},
},
{
"track_id": 4,
"owner_id": 1,
"title": "Stem Without Original Filename",
"track_cid": "testcid3",
"blocknumber": 101,
"stem_of": map[string]any{
"parent_track_id": 1,
"category": "guitar",
},
},
},
"stems": {
{
Expand All @@ -55,6 +66,10 @@ func TestGetTrackStems(t *testing.T) {
"child_track_id": 3,
"parent_track_id": 1,
},
{
"child_track_id": 4,
"parent_track_id": 1,
},
},
}

Expand All @@ -64,7 +79,7 @@ func TestGetTrackStems(t *testing.T) {
assert.Equal(t, 200, status)

jsonAssert(t, body, map[string]any{
"data.#": 2,
"data.#": 3,
"data.0.id": trashid.MustEncodeHashID(2),
"data.0.parent_id": trashid.MustEncodeHashID(1),
"data.0.category": "bass",
Expand All @@ -77,5 +92,11 @@ func TestGetTrackStems(t *testing.T) {
"data.1.orig_filename": "stem2.wav",
"data.1.cid": "testcid2",
"data.1.user_id": trashid.MustEncodeHashID(1),
"data.2.id": trashid.MustEncodeHashID(4),
"data.2.parent_id": trashid.MustEncodeHashID(1),
"data.2.category": "guitar",
"data.2.orig_filename": "Stem Without Original Filename",
"data.2.cid": "testcid3",
"data.2.user_id": trashid.MustEncodeHashID(1),
})
}
Loading