Loginauth / routes /main.py
Gregniuki's picture
Create main.py
c81f3a9
raw
history blame
547 Bytes
from fastapi import APIRouter, Depends, HTTPException
from fastapi.security import OAuth2PasswordBearer
from sqlalchemy.orm import Session
from app.database import get_db
from app.models import User
router = APIRouter()
# Define specific routes and request handlers
@router.get("/user/{user_id}", response_model=User)
def read_user(user_id: int, db: Session = Depends(get_db)):
user = db.query(User).filter(User.id == user_id).first()
if user is None:
raise HTTPException(status_code=404, detail="User not found")
return user