Skip to content
Open
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
2 changes: 1 addition & 1 deletion api/dbv1/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/exists.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_account_playlists.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_connected_wallets.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_developer_apps.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_events.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_extended_account_fields.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_genres.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_grants.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_playlist_ids_by_permalink.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_playlist_ids_by_upc.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_playlists.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_plays.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_track_ids_by_isrc.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_track_ids_by_permalink.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion api/dbv1/get_tracks.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_undisbursed_challenges.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_user_for_handle.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_user_for_wallet.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_users.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions api/dbv1/queries/get_tracks.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ SELECT
duration,
is_downloadable,
COALESCE(aggregate_plays.count, 0) as play_count,
(
SELECT count(*)::bigint
FROM track_downloads d
WHERE (t.stem_of IS NOT NULL
AND d.parent_track_id = (t.stem_of->>'parent_track_id')::int
AND d.track_id = t.track_id)
OR (t.stem_of IS NULL AND d.parent_track_id = t.track_id)
) AS download_count,
ddex_app,
pinned_comment_id,
playlists_containing_track,
Expand Down
8 changes: 8 additions & 0 deletions api/swagger/swagger-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13992,6 +13992,7 @@ components:
- is_unlisted
- permalink
- play_count
- download_count
- preview
- remix_of
- repost_count
Expand Down Expand Up @@ -14047,6 +14048,9 @@ components:
type: boolean
play_count:
type: integer
download_count:
type: integer
description: Full track + all stems (parent) or stem-only (stem)
permalink:
type: string
is_streamable:
Expand Down Expand Up @@ -15458,6 +15462,7 @@ components:
- is_unlisted
- permalink
- play_count
- download_count
- preview
- remix_of
- repost_count
Expand Down Expand Up @@ -15513,6 +15518,9 @@ components:
type: boolean
play_count:
type: integer
download_count:
type: integer
description: Full track + all stems (parent) or stem-only (stem)
permalink:
type: string
is_streamable:
Expand Down
32 changes: 29 additions & 3 deletions api/v1_track_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package api

import (
"context"
"testing"

"api.audius.co/api/dbv1"
"api.audius.co/trashid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestGetTrack(t *testing.T) {
Expand All @@ -18,9 +20,33 @@ func TestGetTrack(t *testing.T) {
assert.Equal(t, 200, status)

jsonAssert(t, body, map[string]any{
"data.id": "eYJyn",
"data.title": "Culca Canyon",
"data.play_count": 0,
"data.id": "eYJyn",
"data.title": "Culca Canyon",
"data.play_count": 0,
"data.download_count": 0,
})
}

func TestGetTrackDownloadCount(t *testing.T) {
app := testAppWithFixtures(t)
ctx := context.Background()
require.NotNil(t, app.writePool, "test requires write pool")

// Track 200 is "Culca Canyon" (eYJyn). Insert two download rows so download_count is 2.
_, err := app.writePool.Exec(ctx, `
INSERT INTO track_downloads (txhash, blocknumber, parent_track_id, track_id, user_id)
VALUES ('tx-dl-1', 101, 200, 200, 1), ('tx-dl-2', 101, 200, 200, 2)
`)
require.NoError(t, err)

var trackResponse struct {
Data dbv1.Track
}
status, body := testGet(t, app, "/v1/full/tracks/eYJyn", &trackResponse)
assert.Equal(t, 200, status)
jsonAssert(t, body, map[string]any{
"data.id": "eYJyn",
"data.download_count": 2,
})
}

Expand Down
10 changes: 6 additions & 4 deletions api/v1_tracks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ func TestTracksEndpoint(t *testing.T) {
assert.Equal(t, 200, status)

jsonAssert(t, body, map[string]any{
"data.0.id": "eYZmn",
"data.0.title": "T1",
"data.0.id": "eYZmn",
"data.0.title": "T1",
"data.0.download_count": 0,
})
}

Expand All @@ -31,8 +32,9 @@ func TestGetTracksByPermalink(t *testing.T) {
assert.Equal(t, 200, status)

jsonAssert(t, body, map[string]any{
"data.0.id": "eYake",
"data.0.title": "track by permalink",
"data.0.id": "eYake",
"data.0.title": "track by permalink",
"data.0.download_count": 0,
})
}

Expand Down
Loading