From c9e64254ba1a1a9020915c81585eb15e886e9823 Mon Sep 17 00:00:00 2001 From: Federico Pacheco Date: Fri, 19 Apr 2024 17:39:05 -0300 Subject: [PATCH] refactor map of ids --- app/controller/Users.py | 4 +++- app/main.py | 8 +------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/app/controller/Users.py b/app/controller/Users.py index ab956d7..30fbeea 100644 --- a/app/controller/Users.py +++ b/app/controller/Users.py @@ -21,8 +21,10 @@ def handle_get_user(self, user_id: int): ), ) - def handle_get_all_users(self, ids: list = None): + def handle_get_all_users(self, ids: list | None = None): if ids: + ids = ids[0].split(",") + ids = [x for x in ids if x.isdigit()] users = self.users_service.get_users_by_ids(ids) return JSONResponse( status_code=status.HTTP_200_OK, diff --git a/app/main.py b/app/main.py index 0cd3465..2ecab21 100644 --- a/app/main.py +++ b/app/main.py @@ -24,13 +24,7 @@ def get_users(user_id: int): @app.get("/users") def get_all_users(ids: Annotated[Union[List[str], None], Query()] = None): - if ids: - ids = ids[0].split(",") - if len(ids) > 0: - ids = filter(lambda x: x.isdigit(), ids) - return users_controller.handle_get_all_users(ids) - - return users_controller.handle_get_all_users() + return users_controller.handle_get_all_users(ids) @app.post("/users")