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)