Skip to content

Commit

Permalink
Update discovery api to return permalink with playlist objects (#4638)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabrina-kiam committed Jan 23, 2023
1 parent fa08b47 commit 00ad3dd
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions discovery-provider/src/api/v1/models/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
{
"artwork": fields.Nested(playlist_artwork, allow_null=True),
"description": fields.String,
"permalink": fields.String,
"id": fields.String(required=True),
"is_album": fields.Boolean(required=True),
"playlist_name": fields.String(required=True),
Expand Down
30 changes: 30 additions & 0 deletions discovery-provider/src/models/playlists/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from src.model_validator import ModelValidator
from src.models.base import Base
from src.models.model_utils import RepresentableMixin, validate_field_helper
from src.models.playlists.playlist_route import PlaylistRoute
from src.models.users.user import User


class Playlist(Base, RepresentableMixin):
Expand Down Expand Up @@ -42,9 +44,37 @@ class Playlist(Base, RepresentableMixin):
"Block", primaryjoin="Playlist.blocknumber == Block.number"
)

_routes = relationship( # type: ignore
PlaylistRoute,
primaryjoin="and_(\
remote(Playlist.playlist_id) == foreign(PlaylistRoute.playlist_id),\
PlaylistRoute.is_current)",
lazy="joined",
viewonly=True,
)

user = relationship( # type: ignore
User,
primaryjoin="and_(\
remote(Playlist.playlist_owner_id) == foreign(User.user_id),\
User.is_current)",
lazy="joined",
viewonly=True,
)

ModelValidator.init_model_schemas("Playlist")
fields = ["playlist_name", "description"]

@property
def _slug(self):
return self._routes[0].slug if self._routes else ""

@property
def permalink(self):
if self.user and self.user[0].handle and self._slug:
return f"/{self.user[0].handle}/playlist/{self._slug}"
return ""

# unpacking args into @validates
@validates(*fields)
def validate_field(self, field, value):
Expand Down
6 changes: 6 additions & 0 deletions libs/src/sdk/api/generated/default/models/Playlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export interface Playlist
* @type {string}
* @memberof Playlist
*/
permalink?: string;
/**
*
* @type {string}
* @memberof Playlist
*/
id: string;
/**
*
Expand Down
6 changes: 6 additions & 0 deletions libs/src/sdk/api/generated/full/models/PlaylistFull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ export interface PlaylistFull
* @type {string}
* @memberof PlaylistFull
*/
permalink?: string;
/**
*
* @type {string}
* @memberof PlaylistFull
*/
id: string;
/**
*
Expand Down

0 comments on commit 00ad3dd

Please sign in to comment.