Update code in endpoints/login.post.py
This commit is contained in:
parent
5f5da9fc88
commit
5f18e055b5
@ -1,37 +1,36 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from pydantic import BaseModel
|
||||
from datetime import timedelta
|
||||
from core.database import get_db
|
||||
from sqlalchemy.orm import Session
|
||||
from core.auth import verify_password, create_access_token
|
||||
from models.user import User
|
||||
from fastapi import APIRouter, HTTPException
|
||||
import uuid
|
||||
|
||||
playlists = [] # In-memory storage
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class UserAuth(BaseModel):
|
||||
username: str
|
||||
password: str
|
||||
|
||||
@router.post("/login")
|
||||
async def login(
|
||||
user_data: UserAuth,
|
||||
db: Session = Depends(get_db)
|
||||
async def create_playlist(
|
||||
name: str = "My Playlist",
|
||||
description: str = "My awesome playlist",
|
||||
user_id: str = "user_123"
|
||||
):
|
||||
"""User authentication endpoint"""
|
||||
user = db.query(User).filter(User.username == user_data.username).first()
|
||||
"""Create new playlist endpoint"""
|
||||
playlist_id = str(uuid.uuid4())
|
||||
|
||||
if not user or not verify_password(user_data.password, user.hashed_password):
|
||||
raise HTTPException(status_code=400, detail="Invalid credentials")
|
||||
|
||||
# Generate token with expiration
|
||||
access_token = create_access_token(
|
||||
data={"sub": user.id},
|
||||
expires_delta=timedelta(hours=1)
|
||||
)
|
||||
|
||||
return {
|
||||
"access_token": access_token,
|
||||
"token_type": "bearer",
|
||||
"user_id": user.id,
|
||||
"username": user.username
|
||||
playlist = {
|
||||
"id": playlist_id,
|
||||
"name": name,
|
||||
"description": description,
|
||||
"user_id": user_id,
|
||||
"tracks": [],
|
||||
"created_at": "2024-01-01T00:00:00Z"
|
||||
}
|
||||
|
||||
playlists.append(playlist)
|
||||
|
||||
return {
|
||||
"message": "Playlist created successfully",
|
||||
"playlist_id": playlist_id,
|
||||
"name": name,
|
||||
"features": {
|
||||
"max_tracks": 100,
|
||||
"visibility": "public"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user