Skip to content

Commit

Permalink
Merge pull request #101 from whyphi/feat/analytics-detail-view-ZAP
Browse files Browse the repository at this point in the history
Feat/analytics detail view zap
  • Loading branch information
wderocco8 authored Aug 15, 2024
2 parents 47f62a5 + e343ecf commit 0217dbe
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
5 changes: 3 additions & 2 deletions chalicelib/api/events_rush.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ def get_rush_events():
return events_rush_service.get_rush_categories_and_events()


@events_rush_api.route("/events/rush/{event_id}", methods=["GET"], cors=True)
@events_rush_api.route("/events/rush/{event_id}", methods=["POST"], cors=True)
def get_rush_event(event_id):
return events_rush_service.get_rush_event(event_id)
data = events_rush_api.current_request.json_body
return events_rush_service.get_rush_event(event_id=event_id, data=data)


@events_rush_api.route("/events/rush/category", methods=["POST"], cors=True)
Expand Down
32 changes: 24 additions & 8 deletions chalicelib/services/EventsRushService.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,19 @@ def modify_rush_settings(self, data: dict):

return

def get_rush_event(self, event_id: str, hide_attendees: bool = True):
def get_rush_event(self, event_id: str, data: dict):
hide_attendees = data.get("hideAttendees", True)
hide_code = data.get("hideCode", True)

event = self.mongo_module.get_document_by_id(
f"{self.collection_prefix}rush-event", event_id
)

if hide_attendees:
event.pop("attendeesId", None)

event.pop("code")
if hide_code:
event.pop("code")

return json.dumps(event, cls=self.BSONEncoder)

Expand Down Expand Up @@ -342,19 +346,31 @@ def get_rush_category_analytics(self, category_id: str):
# attendees : dict of all users (user: { name, email, eventsAttended: list of objects })
attendees = {}

# events: list of objects (event: { name, eventId })
events = []

for event in category["events"]:
new_event = {
"eventId": event["_id"],
"eventName": event["name"]
}

# accumulate list of events
events.append(new_event)

# accumulate attendance
for attendee in event["attendees"]:
email =attendee["email"]
new_event = {
"eventId": event["_id"],
"eventName": event["name"]
}
email = attendee["email"]
if email in attendees:
attendees[email]["eventsAttended"].append(new_event)
else:
attendees[email] = { **attendee, "eventsAttended": [new_event] }

result = { "categoryName": category["name"], "attendees": attendees }
result = {
"categoryName": category["name"],
"attendees": attendees,
"events": events,
}

return json.dumps(result, cls=self.BSONEncoder)

Expand Down
3 changes: 2 additions & 1 deletion tests/api/test_events_rush.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ def test_get_rush_event():
"chalicelib.services.EventsRushService.events_rush_service.get_rush_event",
) as mock_get_rush_event:
mock_get_rush_event.return_value = SAMPLE_RUSH_EVENT
response = client.http.get(
response = client.http.post(
"/events/rush/test_event_id",
body={ "hideCode": False, "hideAttendees": False },
headers={"Authorization": "Bearer SAMPLE_TOKEN_STRING"},
)

Expand Down

0 comments on commit 0217dbe

Please sign in to comment.