mirror of
https://github.com/StepanovPlaton/torrent_backend.git
synced 2026-04-03 20:30:38 +04:00
Connect to database and add first models
This commit is contained in:
22
main.py
Normal file
22
main.py
Normal file
@@ -0,0 +1,22 @@
|
||||
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
|
||||
Reference in New Issue
Block a user