From 61f688e321329aeadfc3c965e14f96d9c79dd1b0 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Tue, 18 Mar 2025 20:56:24 +0000 Subject: [PATCH] Update code in endpoints/api/v1/endpoint.post.py --- endpoints/api/v1/endpoint.post.py | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 endpoints/api/v1/endpoint.post.py diff --git a/endpoints/api/v1/endpoint.post.py b/endpoints/api/v1/endpoint.post.py new file mode 100644 index 0000000..cb17f50 --- /dev/null +++ b/endpoints/api/v1/endpoint.post.py @@ -0,0 +1,45 @@ +from fastapi import APIRouter, Depends, HTTPException +from core.database import fake_users_db +from typing import List, Optional +from uuid import UUID + +router = APIRouter() + +@router.post("/api/v1/endpoint") +async def fetch_playlist_songs( + playlist_id: str, + limit: Optional[int] = 50, + offset: Optional[int] = 0 +): + """Fetch songs from a specified playlist""" + + # Demo playlist database + fake_playlists_db = { + "playlist1": [ + {"id": "1", "title": "Song 1", "artist": "Artist 1", "duration": "3:45"}, + {"id": "2", "title": "Song 2", "artist": "Artist 2", "duration": "4:20"}, + ] + } + + if playlist_id not in fake_playlists_db: + raise HTTPException(status_code=404, detail="Playlist not found") + + playlist_songs = fake_playlists_db[playlist_id] + total_songs = len(playlist_songs) + + # Apply pagination + paginated_songs = playlist_songs[offset:offset + limit] + + return { + "message": "Songs fetched successfully", + "data": { + "playlist_id": playlist_id, + "songs": paginated_songs, + "total_songs": total_songs + }, + "metadata": { + "limit": limit, + "offset": offset, + "has_more": (offset + limit) < total_songs + } + } \ No newline at end of file