Show how many people saved an event #27
Labels
No labels
bug
chore
data
feature
frontend
good first issue
intermediate
needs/docs
needs/research
needs/upstream
type/bug
type/external
type/feature
type/refactor
urgency
high
urgency
immediate
urgency
low
urgency
medium
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
ScottyLabs/cal#27
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Goal
"Saved by 24 people" helps students spot popular events. Return a save count from the API and show it on Explore results and in the event popover.
What you'll learn
A SQL count in a Flask route, returning it in JSON, and displaying it in React.
Resources
Where to start
api/app/api/events.py,get_all_events(GET /api/events/): add asaved_countfield to each event. Use a correlated scalar subquery:select(func.count()).where(UserSavedEvent.event_id == Event.id).scalar_subquery().get_specific_events(GET /api/events/<id>): addsaved_countthere too.api/app/models/models.py:UserSavedEventhas one row per (user, event).web/src/app/types/EventType.ts: addsaved_count?: number.web/src/app/components/SearchResultSidebar.tsxandEventPopover.tsx: display it.Done when
saved_countas an integer, including 0api/tests/api/saves an event for two users and checks the count (the conftest gives you a SQLite database and signed tokens)Notes
Extend the existing responses; do not add a new route. Avoid a join plus
GROUP BY: the tag filter inget_all_eventsalready groups byEvent.id, and the subquery avoids that conflict. Return only the count, never who saved. Unblocks "Most saved" sorting in the Explore sort issue.