mirror of
https://github.com/StepanovPlaton/torrent_backend.git
synced 2026-04-03 12:20:38 +04:00
23 lines
555 B
Python
23 lines
555 B
Python
from typing import Union
|
|
|
|
from fastapi import Depends, FastAPI, HTTPException
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from database import *
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
@app.on_event("startup")
|
|
async def startup_event():
|
|
await init_models()
|
|
|
|
|
|
@app.get("/users/{user_id}", response_model=User)
|
|
async def read_user(user_id: int, db: AsyncSession = Depends(get_session)):
|
|
db_user = await get_user(db, user_id=user_id)
|
|
print(db_user)
|
|
if db_user is None:
|
|
raise HTTPException(status_code=404, detail="User not found")
|
|
return db_user
|