Skip to content

Commit

Permalink
Add non-hackers to /participants endpoint (#366)
Browse files Browse the repository at this point in the history
* update: add non-hackers to /participants endpoint

* refactor: use inclusive instead of exclusive query

* refactor non-hacker roles into globl var

* update: set default Participant status to REVIEWED
  • Loading branch information
samderanova authored Jan 26, 2024
1 parent 7ccce0c commit fbbc82d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
30 changes: 20 additions & 10 deletions apps/api/src/admin/participant_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@

log = getLogger(__name__)

NON_HACKER_ROLES = (
Role.MENTOR,
Role.VOLUNTEER,
Role.SPONSOR,
Role.JUDGE,
Role.WORKSHOP_LEAD,
)


class Participant(UserRecord):
"""Participants attending the event."""

first_name: str
last_name: str
status: Union[Status, Decision]
status: Union[Status, Decision] = Status.REVIEWED


async def get_hackers() -> list[Participant]:
Expand Down Expand Up @@ -47,6 +55,16 @@ async def get_hackers() -> list[Participant]:
return [Participant(**user, **user["application_data"]) for user in records]


async def get_non_hackers() -> list[Participant]:
"""Fetch all non-hackers participating in the event."""
records: list[dict[str, Any]] = await mongodb_handler.retrieve(
Collection.USERS,
{"role": {"$in": NON_HACKER_ROLES}},
["_id", "status", "role", "first_name", "last_name"],
)
return [Participant(**user) for user in records]


async def check_in_participant(uid: str, associate: User) -> None:
"""Check in participant at IrvineHacks"""
record: Optional[dict[str, object]] = await mongodb_handler.retrieve_one(
Expand Down Expand Up @@ -76,20 +94,12 @@ async def check_in_participant(uid: str, associate: User) -> None:

async def confirm_attendance_non_hacker(uid: str, director: User) -> None:
"""Update status for Role.Attending for non-hackers."""
allowed_roles = (
Role.MENTOR,
Role.ORGANIZER,
Role.VOLUNTEER,
Role.SPONSOR,
Role.JUDGE,
Role.WORKSHOP_LEAD,
)

record: Optional[dict[str, object]] = await mongodb_handler.retrieve_one(
Collection.USERS, {"_id": uid, "status": Status.WAIVER_SIGNED}
)

if not record or record["role"] not in allowed_roles:
if not record or record["role"] not in NON_HACKER_ROLES:
raise ValueError

update_status = await mongodb_handler.raw_update_one(
Expand Down
5 changes: 3 additions & 2 deletions apps/api/src/routers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,9 @@ async def waitlist_release(uid: str) -> None:
@router.get("/participants", dependencies=[Depends(require_checkin_associate)])
async def participants() -> list[Participant]:
"""Get list of participants."""
# TODO: non-hackers
return await participant_manager.get_hackers()
hackers = await participant_manager.get_hackers()
non_hackers = await participant_manager.get_non_hackers()
return hackers + non_hackers


@router.post("/checkin/{uid}")
Expand Down

0 comments on commit fbbc82d

Please sign in to comment.