diff --git a/endpoints/login.post.py b/endpoints/login.post.py index 1a2cedf..d367927 100644 --- a/endpoints/login.post.py +++ b/endpoints/login.post.py @@ -1,39 +1,44 @@ from fastapi import APIRouter, Depends, HTTPException from core.database import fake_users_db -from fastapi.security import OAuth2PasswordRequestForm +from typing import List, Optional router = APIRouter() -@router.post("/login") -async def login_handler( - form_data: OAuth2PasswordRequestForm = Depends() +# 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 ): - """Authenticate user and return token""" - user = fake_users_db.get(form_data.username) + """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] - if not user or user["password"] != form_data.password: - raise HTTPException( - status_code=401, - detail="Incorrect username or password", - headers={"WWW-Authenticate": "Bearer"}, - ) - - if user.get("disabled"): - raise HTTPException( - status_code=400, - detail="Inactive user" - ) - return { - "message": "Login successful", - "access_token": "dummy_jwt_token_" + form_data.username, - "token_type": "bearer", - "user": { - "username": form_data.username, - "email": user["email"] + "message": "Songs fetched successfully", + "data": { + "playlist_name": playlist["name"], + "songs": songs, + "total_songs": len(playlist["songs"]) }, - "features": { - "rate_limit": 100, - "expires_in": 3600 + "metadata": { + "limit": limit, + "offset": offset, + "has_more": (offset + limit) < len(playlist["songs"]) } } \ No newline at end of file