Skip to content

Commit

Permalink
Fix top_listeners restx schema (#7157)
Browse files Browse the repository at this point in the history
  • Loading branch information
stereosteve committed Jan 12, 2024
1 parent aab456d commit 3d602d6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,9 @@ def test_track_top_listeners(app):
with db.scoped_session() as session:
top_listeners = _get_top_listeners_for_track(session, {"track_id": 2})
assert len(top_listeners) == 2
assert top_listeners[0]["user"]["user_id"] == 2
assert top_listeners[0]["user"]["user_id"] == 1
assert top_listeners[0]["count"] == 1
assert top_listeners[1]["user"]["user_id"] == 1
assert top_listeners[1]["user"]["user_id"] == 2
assert top_listeners[1]["count"] == 1

top_listeners = _get_top_listeners_for_track(session, {"track_id": 1})
Expand Down
6 changes: 5 additions & 1 deletion packages/discovery-provider/src/api/v1/tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,14 +1004,18 @@ def get(self, track_id):
return success_response(users)


top_listener_response_full = full_ns.model(
top_listener_item = full_ns.model(
"full_top_listener",
{
"count": fields.Integer(required=True),
"user": fields.Nested(user_model_full, required=True),
},
)

top_listener_response_full = make_response(
"full_top_listener", full_ns, fields.List(fields.Nested(top_listener_item))
)


@full_ns.route("/<string:track_id>/top_listeners")
class FullTrackTopListeners(Resource):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _get_top_listeners_for_track(session, args):
select *
from counted
left join aggregate_user using (user_id)
order by play_count, follower_count, counted.user_id desc
order by play_count desc, follower_count desc, counted.user_id asc
limit :limit
offset :offset
"""
Expand Down
25 changes: 4 additions & 21 deletions packages/libs/src/sdk/api/generated/full/models/FullTopListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
*/

import { exists, mapValues } from '../runtime';
import type { UserFull } from './UserFull';
import {
UserFullFromJSON,
UserFullFromJSONTyped,
UserFullToJSON,
} from './UserFull';

/**
*
* @export
Expand All @@ -29,25 +22,17 @@ import {
export interface FullTopListener {
/**
*
* @type {number}
* @memberof FullTopListener
*/
count: number;
/**
*
* @type {UserFull}
* @type {Array<FullTopListener>}
* @memberof FullTopListener
*/
user: UserFull;
data?: Array<FullTopListener>;
}

/**
* Check if a given object implements the FullTopListener interface.
*/
export function instanceOfFullTopListener(value: object): boolean {
let isInstance = true;
isInstance = isInstance && "count" in value;
isInstance = isInstance && "user" in value;

return isInstance;
}
Expand All @@ -62,8 +47,7 @@ export function FullTopListenerFromJSONTyped(json: any, ignoreDiscriminator: boo
}
return {

'count': json['count'],
'user': UserFullFromJSON(json['user']),
'data': !exists(json, 'data') ? undefined : ((json['data'] as Array<any>).map(FullTopListenerFromJSON)),
};
}

Expand All @@ -76,8 +60,7 @@ export function FullTopListenerToJSON(value?: FullTopListener | null): any {
}
return {

'count': value.count,
'user': UserFullToJSON(value.user),
'data': value.data === undefined ? undefined : ((value.data as Array<any>).map(FullTopListenerToJSON)),
};
}

0 comments on commit 3d602d6

Please sign in to comment.