From e5391a2ea83439f9f9e98133641251e36c8653c6 Mon Sep 17 00:00:00 2001 From: Raymond Jacobson Date: Wed, 21 Feb 2024 17:29:29 -0800 Subject: [PATCH 1/3] Add history tracks activity model --- .../src/api/v1/models/activities.py | 31 ++++++++++++++++--- .../discovery-provider/src/api/v1/users.py | 10 ++++-- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/packages/discovery-provider/src/api/v1/models/activities.py b/packages/discovery-provider/src/api/v1/models/activities.py index a4e36c4f9bd..495beb7b7d8 100644 --- a/packages/discovery-provider/src/api/v1/models/activities.py +++ b/packages/discovery-provider/src/api/v1/models/activities.py @@ -60,16 +60,37 @@ def format(self, value): }, ) -library_track_activity_model_full = ns.clone( +history_track_activity_model = ns.model( + "activity", + { + "timestamp": fields.String(allow_null=True), + "item_type": fields.FormattedString("track"), + "item": fields.Nested(track), + }, +) + +history_track_activity_model_full = ns.model( + "activity_full", + { + "timestamp": fields.String(allow_null=True), + "item_type": fields.FormattedString("track"), + "item": fields.Nested(track_full), + }, +) + +library_track_activity_model_full = ns.model( "track_activity_full", - activity_model_full, - {"item_type": fields.FormattedString("track"), "item": fields.Nested(track_full)}, + { + "timestamp": fields.String(allow_null=True), + "item_type": fields.FormattedString("track"), + "item": fields.Nested(track_full), + }, ) -library_collection_activity_model_full = ns.clone( +library_collection_activity_model_full = ns.model( "collection_activity_full", - activity_model_full, { + "timestamp": fields.String(allow_null=True), "item_type": fields.FormattedString("playlist"), "item": fields.Nested(full_playlist_without_tracks_model), }, diff --git a/packages/discovery-provider/src/api/v1/users.py b/packages/discovery-provider/src/api/v1/users.py index f56a8ca51a8..943e0bbfcf1 100644 --- a/packages/discovery-provider/src/api/v1/users.py +++ b/packages/discovery-provider/src/api/v1/users.py @@ -50,6 +50,8 @@ from src.api.v1.models.activities import ( activity_model, activity_model_full, + history_track_activity_model, + history_track_activity_model_full, library_collection_activity_model_full, library_track_activity_model_full, ) @@ -990,11 +992,13 @@ def get(self, id): return success_response(favorites) -history_response = make_full_response( - "history_response", ns, fields.List(fields.Nested(activity_model)) +history_response = make_response( + "history_response", ns, fields.List(fields.Nested(history_track_activity_model)) ) history_response_full = make_full_response( - "history_response_full", full_ns, fields.List(fields.Nested(activity_model_full)) + "history_response_full", + full_ns, + fields.List(fields.Nested(history_track_activity_model_full)), ) USER_HISTORY_TRACKS_ROUTE = "//history/tracks" From 7a02be6bab25c0fc0d1f9962419dd69ab9c581e4 Mon Sep 17 00:00:00 2001 From: Raymond Jacobson Date: Wed, 21 Feb 2024 18:03:03 -0800 Subject: [PATCH 2/3] Update sdk --- .../api/generated/default/models/Activity.ts | 19 +++++++++++++------ .../api/generated/full/models/ActivityFull.ts | 19 +++++++++++++------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/packages/libs/src/sdk/api/generated/default/models/Activity.ts b/packages/libs/src/sdk/api/generated/default/models/Activity.ts index a020b02b114..678b366c566 100644 --- a/packages/libs/src/sdk/api/generated/default/models/Activity.ts +++ b/packages/libs/src/sdk/api/generated/default/models/Activity.ts @@ -14,6 +14,13 @@ */ import { exists, mapValues } from '../runtime'; +import type { Track } from './Track'; +import { + TrackFromJSON, + TrackFromJSONTyped, + TrackToJSON, +} from './Track'; + /** * * @export @@ -28,16 +35,16 @@ export interface Activity { timestamp?: string; /** * - * @type {object} + * @type {string} * @memberof Activity */ - itemType?: object; + itemType?: string; /** * - * @type {object} + * @type {Track} * @memberof Activity */ - item?: object; + item?: Track; } /** @@ -61,7 +68,7 @@ export function ActivityFromJSONTyped(json: any, ignoreDiscriminator: boolean): 'timestamp': !exists(json, 'timestamp') ? undefined : json['timestamp'], 'itemType': !exists(json, 'item_type') ? undefined : json['item_type'], - 'item': !exists(json, 'item') ? undefined : json['item'], + 'item': !exists(json, 'item') ? undefined : TrackFromJSON(json['item']), }; } @@ -76,7 +83,7 @@ export function ActivityToJSON(value?: Activity | null): any { 'timestamp': value.timestamp, 'item_type': value.itemType, - 'item': value.item, + 'item': TrackToJSON(value.item), }; } diff --git a/packages/libs/src/sdk/api/generated/full/models/ActivityFull.ts b/packages/libs/src/sdk/api/generated/full/models/ActivityFull.ts index ca301602e3b..0897aee7f62 100644 --- a/packages/libs/src/sdk/api/generated/full/models/ActivityFull.ts +++ b/packages/libs/src/sdk/api/generated/full/models/ActivityFull.ts @@ -14,6 +14,13 @@ */ import { exists, mapValues } from '../runtime'; +import type { TrackFull } from './TrackFull'; +import { + TrackFullFromJSON, + TrackFullFromJSONTyped, + TrackFullToJSON, +} from './TrackFull'; + /** * * @export @@ -28,16 +35,16 @@ export interface ActivityFull { timestamp?: string; /** * - * @type {object} + * @type {string} * @memberof ActivityFull */ - itemType?: object; + itemType?: string; /** * - * @type {object} + * @type {TrackFull} * @memberof ActivityFull */ - item?: object; + item?: TrackFull; } /** @@ -61,7 +68,7 @@ export function ActivityFullFromJSONTyped(json: any, ignoreDiscriminator: boolea 'timestamp': !exists(json, 'timestamp') ? undefined : json['timestamp'], 'itemType': !exists(json, 'item_type') ? undefined : json['item_type'], - 'item': !exists(json, 'item') ? undefined : json['item'], + 'item': !exists(json, 'item') ? undefined : TrackFullFromJSON(json['item']), }; } @@ -76,7 +83,7 @@ export function ActivityFullToJSON(value?: ActivityFull | null): any { 'timestamp': value.timestamp, 'item_type': value.itemType, - 'item': value.item, + 'item': TrackFullToJSON(value.item), }; } From eded04d899befe18164190eab0a3157d470b92b0 Mon Sep 17 00:00:00 2001 From: Raymond Jacobson Date: Wed, 21 Feb 2024 18:11:34 -0800 Subject: [PATCH 3/3] Consolidate --- .../src/api/v1/models/activities.py | 17 ++++------------- .../discovery-provider/src/api/v1/users.py | 15 +++++++-------- .../api/generated/default/models/Activity.ts | 19 ++++++------------- .../api/generated/full/models/ActivityFull.ts | 19 ++++++------------- .../full/models/HistoryResponseFull.ts | 18 +++++++++--------- 5 files changed, 32 insertions(+), 56 deletions(-) diff --git a/packages/discovery-provider/src/api/v1/models/activities.py b/packages/discovery-provider/src/api/v1/models/activities.py index 495beb7b7d8..01bbb895f7b 100644 --- a/packages/discovery-provider/src/api/v1/models/activities.py +++ b/packages/discovery-provider/src/api/v1/models/activities.py @@ -60,8 +60,8 @@ def format(self, value): }, ) -history_track_activity_model = ns.model( - "activity", +track_activity_model = ns.model( + "track_activity", { "timestamp": fields.String(allow_null=True), "item_type": fields.FormattedString("track"), @@ -69,16 +69,7 @@ def format(self, value): }, ) -history_track_activity_model_full = ns.model( - "activity_full", - { - "timestamp": fields.String(allow_null=True), - "item_type": fields.FormattedString("track"), - "item": fields.Nested(track_full), - }, -) - -library_track_activity_model_full = ns.model( +track_activity_model_full = ns.model( "track_activity_full", { "timestamp": fields.String(allow_null=True), @@ -87,7 +78,7 @@ def format(self, value): }, ) -library_collection_activity_model_full = ns.model( +collection_activity_model_full = ns.model( "collection_activity_full", { "timestamp": fields.String(allow_null=True), diff --git a/packages/discovery-provider/src/api/v1/users.py b/packages/discovery-provider/src/api/v1/users.py index 943e0bbfcf1..b0eb79bd6f9 100644 --- a/packages/discovery-provider/src/api/v1/users.py +++ b/packages/discovery-provider/src/api/v1/users.py @@ -50,10 +50,9 @@ from src.api.v1.models.activities import ( activity_model, activity_model_full, - history_track_activity_model, - history_track_activity_model_full, - library_collection_activity_model_full, - library_track_activity_model_full, + collection_activity_model_full, + track_activity_model, + track_activity_model_full, ) from src.api.v1.models.common import favorite from src.api.v1.models.developer_apps import authorized_app, developer_app @@ -766,13 +765,13 @@ def get(self, id): track_library_full_response = make_full_response( "track_library_response_full", full_ns, - fields.List(fields.Nested(library_track_activity_model_full)), + fields.List(fields.Nested(track_activity_model_full)), ) collection_library_full_response = make_full_response( "collection_library_response_full", full_ns, - fields.List(fields.Nested(library_collection_activity_model_full)), + fields.List(fields.Nested(collection_activity_model_full)), ) @@ -993,12 +992,12 @@ def get(self, id): history_response = make_response( - "history_response", ns, fields.List(fields.Nested(history_track_activity_model)) + "history_response", ns, fields.List(fields.Nested(track_activity_model)) ) history_response_full = make_full_response( "history_response_full", full_ns, - fields.List(fields.Nested(history_track_activity_model_full)), + fields.List(fields.Nested(track_activity_model_full)), ) USER_HISTORY_TRACKS_ROUTE = "//history/tracks" diff --git a/packages/libs/src/sdk/api/generated/default/models/Activity.ts b/packages/libs/src/sdk/api/generated/default/models/Activity.ts index 678b366c566..a020b02b114 100644 --- a/packages/libs/src/sdk/api/generated/default/models/Activity.ts +++ b/packages/libs/src/sdk/api/generated/default/models/Activity.ts @@ -14,13 +14,6 @@ */ import { exists, mapValues } from '../runtime'; -import type { Track } from './Track'; -import { - TrackFromJSON, - TrackFromJSONTyped, - TrackToJSON, -} from './Track'; - /** * * @export @@ -35,16 +28,16 @@ export interface Activity { timestamp?: string; /** * - * @type {string} + * @type {object} * @memberof Activity */ - itemType?: string; + itemType?: object; /** * - * @type {Track} + * @type {object} * @memberof Activity */ - item?: Track; + item?: object; } /** @@ -68,7 +61,7 @@ export function ActivityFromJSONTyped(json: any, ignoreDiscriminator: boolean): 'timestamp': !exists(json, 'timestamp') ? undefined : json['timestamp'], 'itemType': !exists(json, 'item_type') ? undefined : json['item_type'], - 'item': !exists(json, 'item') ? undefined : TrackFromJSON(json['item']), + 'item': !exists(json, 'item') ? undefined : json['item'], }; } @@ -83,7 +76,7 @@ export function ActivityToJSON(value?: Activity | null): any { 'timestamp': value.timestamp, 'item_type': value.itemType, - 'item': TrackToJSON(value.item), + 'item': value.item, }; } diff --git a/packages/libs/src/sdk/api/generated/full/models/ActivityFull.ts b/packages/libs/src/sdk/api/generated/full/models/ActivityFull.ts index 0897aee7f62..ca301602e3b 100644 --- a/packages/libs/src/sdk/api/generated/full/models/ActivityFull.ts +++ b/packages/libs/src/sdk/api/generated/full/models/ActivityFull.ts @@ -14,13 +14,6 @@ */ import { exists, mapValues } from '../runtime'; -import type { TrackFull } from './TrackFull'; -import { - TrackFullFromJSON, - TrackFullFromJSONTyped, - TrackFullToJSON, -} from './TrackFull'; - /** * * @export @@ -35,16 +28,16 @@ export interface ActivityFull { timestamp?: string; /** * - * @type {string} + * @type {object} * @memberof ActivityFull */ - itemType?: string; + itemType?: object; /** * - * @type {TrackFull} + * @type {object} * @memberof ActivityFull */ - item?: TrackFull; + item?: object; } /** @@ -68,7 +61,7 @@ export function ActivityFullFromJSONTyped(json: any, ignoreDiscriminator: boolea 'timestamp': !exists(json, 'timestamp') ? undefined : json['timestamp'], 'itemType': !exists(json, 'item_type') ? undefined : json['item_type'], - 'item': !exists(json, 'item') ? undefined : TrackFullFromJSON(json['item']), + 'item': !exists(json, 'item') ? undefined : json['item'], }; } @@ -83,7 +76,7 @@ export function ActivityFullToJSON(value?: ActivityFull | null): any { 'timestamp': value.timestamp, 'item_type': value.itemType, - 'item': TrackFullToJSON(value.item), + 'item': value.item, }; } diff --git a/packages/libs/src/sdk/api/generated/full/models/HistoryResponseFull.ts b/packages/libs/src/sdk/api/generated/full/models/HistoryResponseFull.ts index 5fba284c665..2950dc04dd8 100644 --- a/packages/libs/src/sdk/api/generated/full/models/HistoryResponseFull.ts +++ b/packages/libs/src/sdk/api/generated/full/models/HistoryResponseFull.ts @@ -14,12 +14,12 @@ */ import { exists, mapValues } from '../runtime'; -import type { ActivityFull } from './ActivityFull'; +import type { TrackActivityFull } from './TrackActivityFull'; import { - ActivityFullFromJSON, - ActivityFullFromJSONTyped, - ActivityFullToJSON, -} from './ActivityFull'; + TrackActivityFullFromJSON, + TrackActivityFullFromJSONTyped, + TrackActivityFullToJSON, +} from './TrackActivityFull'; import type { VersionMetadata } from './VersionMetadata'; import { VersionMetadataFromJSON, @@ -77,10 +77,10 @@ export interface HistoryResponseFull { version: VersionMetadata; /** * - * @type {Array} + * @type {Array} * @memberof HistoryResponseFull */ - data?: Array; + data?: Array; } /** @@ -116,7 +116,7 @@ export function HistoryResponseFullFromJSONTyped(json: any, ignoreDiscriminator: 'signature': json['signature'], 'timestamp': json['timestamp'], 'version': VersionMetadataFromJSON(json['version']), - 'data': !exists(json, 'data') ? undefined : ((json['data'] as Array).map(ActivityFullFromJSON)), + 'data': !exists(json, 'data') ? undefined : ((json['data'] as Array).map(TrackActivityFullFromJSON)), }; } @@ -136,7 +136,7 @@ export function HistoryResponseFullToJSON(value?: HistoryResponseFull | null): a 'signature': value.signature, 'timestamp': value.timestamp, 'version': VersionMetadataToJSON(value.version), - 'data': value.data === undefined ? undefined : ((value.data as Array).map(ActivityFullToJSON)), + 'data': value.data === undefined ? undefined : ((value.data as Array).map(TrackActivityFullToJSON)), }; }