From 6ef5f6d65eb9a362bf54f90e5dab8c0dbbd3784d Mon Sep 17 00:00:00 2001 From: ReturnFI <151555003+ReturnFI@users.noreply.github.com> Date: Sat, 13 Sep 2025 14:45:24 +0000 Subject: [PATCH] fix(api): align user data with response model in user detail endpoint --- core/scripts/webpanel/routers/api/v1/user.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/core/scripts/webpanel/routers/api/v1/user.py b/core/scripts/webpanel/routers/api/v1/user.py index 8c01fea..6224cc9 100644 --- a/core/scripts/webpanel/routers/api/v1/user.py +++ b/core/scripts/webpanel/routers/api/v1/user.py @@ -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 - raise HTTPException(status_code=404, detail=f'User {username} not found.') + 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)