Conversation
Created two services to return a list of participants with a status. Now we don't need to use 4 services to get accepted, rejected, pending and pendingGrouped. With this two services, the idea is to list ans clasyfy in frontend using status field. function in service_utils is to clasify id fast.
Creada funció amb lambda per tal de retorna de forma directa la estructura a retorna juntament amb el status de cada hacker. Implementat aixo en 1 servei, per a testejar. Si funciona correctament, s'implementarà en el servei restant
S'ha optimitzat el codi utilitzant una lambda function per tal definida al service_utils per tal de retornar la estructura de les dades sense repetirles continuament. S'ha arreglat un error on en ves de crear la estructura a partir de hackers, es creaba a partir de la hacker id buscant atributs que no es podrien trobar. Actualitzat el gitignore per a no incloure el pyproject.toml i el uv.lock
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ckers-participants-list-with-status
…ttps://github.com/LleidaHack/LleidaHackBackend into BACK-95-get-hackers-participants-list-with-status
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…nts-list-with-status Creat 2 serveis per a obtindre llistat de participants clasificats per status
Co-authored-by: Big-Lolo <95545807+Big-Lolo@users.noreply.github.com>
Fix missing get_hacker_info import causing new routers to fail
There was a problem hiding this comment.
Pull Request Overview
This PR adds functionality to retrieve participant lists for events with their status (pending, accepted, or rejected). The changes introduce utility functions to determine hacker status and extract hacker information, along with two new API endpoints for retrieving participant lists in both grouped and ungrouped formats.
Key Changes
- Added utility functions
get_hacker_statusandget_hacker_infoto determine and extract hacker information with status - Implemented two new service methods to retrieve participant lists in grouped and ungrouped formats
- Added two new router endpoints to expose the participant list functionality
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/utils/service_utils.py | Added utility functions for determining hacker status and extracting hacker information with a predefined attribute list |
| src/impl/Event/service.py | Implemented two new service methods for retrieving participant lists and updated imports to include new utility functions |
| src/impl/Event/router_v1.py | Added two new GET endpoints for accessing grouped and ungrouped participant lists |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| "shirt_size", | ||
| ] | ||
|
|
||
| def get_hacker_info(hacker, pending_hackers_ids, accepted_hackers_ids, rejected_hackers_ids): |
There was a problem hiding this comment.
The function parameters lack type hints. Consider adding type hints for hacker (likely a Hacker model object) and the ID list parameters (List[int]) to improve code clarity and enable better IDE support.
| def get_hacker_status(hacker_id, pending_hackers_ids, accepted_hackers_ids, | ||
| rejected_hackers_ids): |
There was a problem hiding this comment.
The function parameters lack type hints. Consider adding type hints for all parameters to improve code clarity and enable better static type checking.
| @BaseService.needs_service("HackerGroupService") | ||
| def get_hackers_participants_list( | ||
| self, event_id: int, data: BaseToken | ||
| ): ##Servei per obtindre la llista de participants amb status acceptat, rechazat o pending. |
There was a problem hiding this comment.
Corrected spelling of 'rechazat' to 'rebutjat' (Catalan) or 'rechazado' (Spanish), and 'obtindre' to 'obtenir' (Catalan) or 'obtener' (Spanish).
| ): ##Servei per obtindre la llista de participants amb status acceptat, rechazat o pending. | |
| ): ##Servei per obtenir la llista de participants amb status acceptat, rebutjat o pending. |
| @BaseService.needs_service("HackerGroupService") | ||
| def get_hackers_participants_list( | ||
| self, event_id: int, data: BaseToken | ||
| ): ##Servei per obtindre la llista de participants amb status acceptat, rechazat o pending. |
There was a problem hiding this comment.
Use a proper docstring instead of an inline comment for function documentation. This comment should be formatted as a docstring below the function signature, similar to other methods in the file.
| ): ##Servei per obtindre la llista de participants amb status acceptat, rechazat o pending. | |
| ): | |
| """ | |
| Servei per obtindre la llista de participants amb status acceptat, rechazat o pending. | |
| """ |
| pending_hackers_ids = [ | ||
| h.id | ||
| for h in subtract_lists( | ||
| subtract_lists(event.registered_hackers, event.accepted_hackers), | ||
| event.rejected_hackers, | ||
| ) | ||
| ] | ||
| registered_hackers = event.registered_hackers | ||
| # Accepted hackers | ||
| accepted_hackers_ids = [h.id for h in event.accepted_hackers] | ||
| # Rejected hackers | ||
| rejected_hackers_ids = [h.id for h in event.rejected_hackers] |
There was a problem hiding this comment.
This nested subtract_lists operation is inefficient and duplicated across both new methods. The logic performs list membership checks (O(n)) for each element. Consider creating a helper function or using set operations for better performance: set(registered) - set(accepted) - set(rejected).
| pending_hackers_ids = [ | |
| h.id | |
| for h in subtract_lists( | |
| subtract_lists(event.registered_hackers, event.accepted_hackers), | |
| event.rejected_hackers, | |
| ) | |
| ] | |
| registered_hackers = event.registered_hackers | |
| # Accepted hackers | |
| accepted_hackers_ids = [h.id for h in event.accepted_hackers] | |
| # Rejected hackers | |
| rejected_hackers_ids = [h.id for h in event.rejected_hackers] | |
| registered_hackers = event.registered_hackers | |
| accepted_hackers_ids = {h.id for h in event.accepted_hackers} | |
| rejected_hackers_ids = {h.id for h in event.rejected_hackers} | |
| registered_hackers_ids = {h.id for h in registered_hackers} | |
| pending_hackers_ids = list(registered_hackers_ids - accepted_hackers_ids - rejected_hackers_ids) |
| pending_hackers_ids = [ | ||
| h.id | ||
| for h in subtract_lists( | ||
| subtract_lists(event.registered_hackers, event.accepted_hackers), | ||
| event.rejected_hackers, | ||
| ) | ||
| ] |
There was a problem hiding this comment.
This logic for computing pending_hackers_ids is duplicated from the get_hackers_participants_list method (lines 573-579). Consider extracting this into a private helper method to avoid code duplication and improve maintainability.
No description provided.