Gregniuki commited on
Commit
c81f3a9
1 Parent(s): 846543a

Create main.py

Browse files
Files changed (1) hide show
  1. routes/main.py +15 -0
routes/main.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import APIRouter, Depends, HTTPException
2
+ from fastapi.security import OAuth2PasswordBearer
3
+ from sqlalchemy.orm import Session
4
+ from app.database import get_db
5
+ from app.models import User
6
+
7
+ router = APIRouter()
8
+
9
+ # Define specific routes and request handlers
10
+ @router.get("/user/{user_id}", response_model=User)
11
+ def read_user(user_id: int, db: Session = Depends(get_db)):
12
+ user = db.query(User).filter(User.id == user_id).first()
13
+ if user is None:
14
+ raise HTTPException(status_code=404, detail="User not found")
15
+ return user