45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
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
|
|
}
|
|
} |