Fix API bug

This commit is contained in:
Iam54r1n4
2025-02-02 23:52:04 +00:00
parent 9819c54ddf
commit af5bde1128

View File

@ -25,6 +25,28 @@ async def list_users():
raise HTTPException(status_code=400, detail=f'Error: {str(e)}') raise HTTPException(status_code=400, detail=f'Error: {str(e)}')
@router.post('/', response_model=DetailResponse)
async def add_user(body: AddUserInputBody):
"""
Add a new user to the system.
Args:
body: An instance of AddUserInputBody containing the user's details.
Returns:
A DetailResponse with a message indicating the user has been added.
Raises:
HTTPException: if an error occurs while adding the user.
"""
try:
cli_api.add_user(body.username, body.traffic_limit, body.expiration_days, body.password, body.creation_date)
return DetailResponse(detail=f'User {body.username} has been added.')
except Exception as e:
raise HTTPException(status_code=400, detail=f'Error: {str(e)}')
@router.get('/{username}', response_model=UserInfoResponse) @router.get('/{username}', response_model=UserInfoResponse)
async def get_user(username: str): async def get_user(username: str):
""" """
@ -47,28 +69,6 @@ async def get_user(username: str):
raise HTTPException(status_code=400, detail=f'Error: {str(e)}') raise HTTPException(status_code=400, detail=f'Error: {str(e)}')
@router.post('', response_model=DetailResponse)
async def add_user(body: AddUserInputBody):
"""
Add a new user to the system.
Args:
body: An instance of AddUserInputBody containing the user's details.
Returns:
A DetailResponse with a message indicating the user has been added.
Raises:
HTTPException: if an error occurs while adding the user.
"""
try:
cli_api.add_user(body.username, body.traffic_limit, body.expiration_days, body.password, body.creation_date)
return DetailResponse(detail=f'User {body.username} has been added.')
except Exception as e:
raise HTTPException(status_code=400, detail=f'Error: {str(e)}')
@router.patch('/{username}', response_model=DetailResponse) @router.patch('/{username}', response_model=DetailResponse)
async def edit_user(username: str, body: EditUserInputBody): async def edit_user(username: str, body: EditUserInputBody):
""" """