File size: 884 Bytes
dad4394
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from fastapi import APIRouter, Depends
from fastapi.responses import JSONResponse
from fastapi.requests import Request
from fastapi.encoders import jsonable_encoder
from app.crud.user import create_user, get_users, get_user, update_user
from app.schema.user import UserSchema
from app.main import get_db

router = APIRouter()

@router.post("/users/")
async def create_user_endpoint(user: UserSchema, db: Session = Depends(get_db)):
    return create_user(db, user)

@router.get("/users/")
async def get_users_endpoint(db: Session = Depends(get_db)):
    return get_users(db)

@router.get("/users/{user_id}")
async def get_user_endpoint(user_id: int, db: Session = Depends(get_db)):
    return get_user(db, user_id)

@router.put("/users/{user_id}")
async def update_user_endpoint(user_id: int, user: UserSchema, db: Session = Depends(get_db)):
    return update_user(db, user_id, user)