Skip to content

Commit

Permalink
refactor map of ids
Browse files Browse the repository at this point in the history
  • Loading branch information
fjpacheco committed Apr 19, 2024
1 parent 796dff3 commit c9e6425
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
4 changes: 3 additions & 1 deletion app/controller/Users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 1 addition & 7 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit c9e6425

Please sign in to comment.