fix(api): align user data with response model in user detail endpoint
This commit is contained in:
@ -126,11 +126,18 @@ async def get_user_api(username: str):
|
|||||||
HTTPException: if the user is not found, or if an error occurs.
|
HTTPException: if the user is not found, or if an error occurs.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
if res := cli_api.get_user(username):
|
user_data = cli_api.get_user(username)
|
||||||
return res
|
if not user_data:
|
||||||
raise HTTPException(status_code=404, detail=f'User {username} not found.')
|
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:
|
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)
|
@router.patch('/{username}', response_model=DetailResponse)
|
||||||
|
|||||||
Reference in New Issue
Block a user