From ce1cee98c9666ebce67a0c3183623188ab3359c2 Mon Sep 17 00:00:00 2001 From: Eduard0803 Date: Thu, 23 Nov 2023 20:21:34 -0300 Subject: [PATCH] add status 'analyzing' and route for enable user Co-Authored-by: Carlos Eduardo --- gestao/web/api/user/enums.py | 1 + gestao/web/api/user/views.py | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/gestao/web/api/user/enums.py b/gestao/web/api/user/enums.py index 430ded0..6d60828 100644 --- a/gestao/web/api/user/enums.py +++ b/gestao/web/api/user/enums.py @@ -4,3 +4,4 @@ class UserStatus(str, Enum): active = "active" inactive = "inactive" + analyzing = "analyzing" diff --git a/gestao/web/api/user/views.py b/gestao/web/api/user/views.py index a130a89..a04f36a 100644 --- a/gestao/web/api/user/views.py +++ b/gestao/web/api/user/views.py @@ -46,7 +46,7 @@ async def create_user(create_user: CreateUserDTO) -> User: dependents = create_user_dict.pop("dependents", []) user_id = str(uuid4()) await User.objects.create( - id=user_id, **create_user_dict, status=UserStatus.active + id=user_id, **create_user_dict, status=UserStatus.analyzing ) if dependents: await Dependent.objects.bulk_create( @@ -108,3 +108,17 @@ async def disable_user(user_id: str) -> None: status_code=404, detail="User not found", ) + + +@router.patch("/{user_id}/enable") +async def enable_user(user_id: str) -> None: + try: + user = await User.objects.get(id=user_id) + await user.update(status=UserStatus.active) + return {"detail": "User enable successfully"} + except Exception: + logging.error("User not found", exc_info=True) + raise HTTPException( + status_code=404, + detail="User not found", + )