File size: 1,755 Bytes
2da7ed3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
27
28
29
30
31
32
33
34
35
36
37
from fastapi import APIRouter, Body, Request, status
from typing import List
import sys
# sys.path.append('/Users/benolojo/DCU/CA4/ca400_FinalYearProject/2024-ca400-olojob2-majdap2/src/backend/src/')
from ..models.users import User, UpdateUser
from ..operations import users as users

router = APIRouter(prefix="/user",
    tags=["User"])

@router.post("/", response_description="Create a new user", status_code=status.HTTP_201_CREATED, response_model=User)
async def create_user(request: Request, user: User = Body(...)):  
    return users.create_user(request,user)

@router.get("/", response_description="List users", response_model=List[User])
async def list_users(request: Request):
    return users.list_users(request, 100)

@router.put("/{user_id}", response_description="Update a User", response_model=UpdateUser)
async def update_user(request: Request, user_id: str, user: UpdateUser = Body(...)):
    return users.update_user(request, user_id, user)

@router.get("/{user_id}", response_description="Get a single user by id", response_model=User)
async def find_user(request: Request, user_id: str):    
    return users.find_user(request, user_id)

@router.get("/name/{user_name}", response_description="Get a single user by name", response_model=User)
async def find_user_name(request: Request, name: str):    
    return users.find_user_name(request, name)

@router.get("/email/{email_addr}", response_description="Get a single user by email", response_model=User)
async def find_user_email(request: Request, email: str):    
    return users.find_user_email(request, email)

@router.delete("/{user_id}", response_description="Delete a user")
async def delete_user(request: Request, user_id:str):
    return users.delete_user(request, user_id)