from fastapi import APIRouter, Depends, HTTPException, status from sqlalchemy.orm import Session from typing import List from core.database import get_db from models.user import User from schemas.user import UserSchema, UserCreate, UserLogin from helpers.user_helpers import authenticate_user router = APIRouter() @router.post("/login", status_code=200, response_model=UserSchema) async def login( user_data: UserLogin, db: Session = Depends(get_db) ): user = authenticate_user(db, user_data.email, user_data.password) if not user: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="Incorrect email or password", headers={"WWW-Authenticate": "Bearer"}, ) return user