2025-03-19 19:15:31 +00:00

44 lines
1.3 KiB
Python

from fastapi import APIRouter, Depends, HTTPException
from core.database import fake_users_db
from typing import List, Optional
router = APIRouter()
# Simulated playlist database
fake_playlists_db = {
"playlist1": {
"id": "playlist1",
"name": "My Favorites",
"songs": [
{"id": "song1", "title": "Song 1", "artist": "Artist 1", "duration": "3:45"},
{"id": "song2", "title": "Song 2", "artist": "Artist 2", "duration": "4:20"},
]
}
}
@router.post("/playlist/songs")
async def get_playlist_songs(
playlist_id: str,
limit: Optional[int] = 10,
offset: Optional[int] = 0
):
"""Fetch list of songs from a playlist"""
if playlist_id not in fake_playlists_db:
raise HTTPException(status_code=404, detail="Playlist not found")
playlist = fake_playlists_db[playlist_id]
songs = playlist["songs"][offset:offset + limit]
return {
"message": "Songs fetched successfully",
"data": {
"playlist_name": playlist["name"],
"songs": songs,
"total_songs": len(playlist["songs"])
},
"metadata": {
"limit": limit,
"offset": offset,
"has_more": (offset + limit) < len(playlist["songs"])
}
}