fix(api): align user data with response model in user detail endpoint

This commit is contained in:
ReturnFI
2025-09-13 14:45:24 +00:00
parent 842b78c4a4
commit 6ef5f6d65e

View File

@ -126,11 +126,18 @@ async def get_user_api(username: str):
HTTPException: if the user is not found, or if an error occurs.
"""
try:
if res := cli_api.get_user(username):
return res
user_data = cli_api.get_user(username)
if not user_data:
raise HTTPException(status_code=404, detail=f'User {username} not found.')
if '_id' in user_data:
user_data['username'] = user_data.pop('_id')
return user_data
except json.JSONDecodeError as e:
raise HTTPException(status_code=500, detail=f"Failed to parse user data from CLI: {e}")
except Exception as e:
raise HTTPException(status_code=400, detail=f'Error: {str(e)}')
raise HTTPException(status_code=500, detail=f'An unexpected error occurred: {str(e)}')
@router.patch('/{username}', response_model=DetailResponse)