fix: take attendance/ edit attendance#1172
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis PR adds a ChangesAttendance Status in Schedule Items
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend/src/services/classes.go`:
- Around line 346-355: The current code silently ignores errors from
svc.db.GetAttendanceCountsForEvents which can lead to incorrect HasAttendance
values; change the handler to propagate the error instead of swallowing it:
check the returned err from svc.db.GetAttendanceCountsForEvents (called as
attendanceCounts, err := svc.db.GetAttendanceCountsForEvents(...)) and if err !=
nil return that error (or wrap it with context) so the caller can handle it;
only run the map population and set items[i].HasAttendance when err == nil and
attendanceCounts is valid. Ensure you reference
svc.db.GetAttendanceCountsForEvents, attendanceCounts, items and HasAttendance
when updating the implementation.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 5df29b79-ce0d-494a-8c2d-279cd2f2735e
📒 Files selected for processing (4)
backend/src/models/program_classes.gobackend/src/services/classes.gofrontend/src/pages/Dashboard.tsxfrontend/src/types/program.ts
| attendanceCounts, err := svc.db.GetAttendanceCountsForEvents(args, eventIDs, dates) | ||
| if err == nil { | ||
| taken := make(map[string]bool) | ||
| for _, ac := range attendanceCounts { | ||
| taken[fmt.Sprintf("%d|%s", ac.EventID, ac.Date)] = true | ||
| } | ||
| for i, item := range items { | ||
| items[i].HasAttendance = taken[fmt.Sprintf("%d|%s", item.EventID, item.Date)] | ||
| } | ||
| } |
There was a problem hiding this comment.
Don’t silently ignore attendance enrichment DB failures.
Line 347 currently drops the error path, which can return incorrect has_attendance state and mislabel buttons in the dashboard. Handle the failure explicitly (prefer returning an error here).
Proposed fix
attendanceCounts, err := svc.db.GetAttendanceCountsForEvents(args, eventIDs, dates)
- if err == nil {
- taken := make(map[string]bool)
- for _, ac := range attendanceCounts {
- taken[fmt.Sprintf("%d|%s", ac.EventID, ac.Date)] = true
- }
- for i, item := range items {
- items[i].HasAttendance = taken[fmt.Sprintf("%d|%s", item.EventID, item.Date)]
- }
- }
+ if err != nil {
+ return nil, fmt.Errorf("get attendance counts for today's schedule: %w", err)
+ }
+ taken := make(map[string]bool, len(attendanceCounts))
+ for _, ac := range attendanceCounts {
+ taken[fmt.Sprintf("%d|%s", ac.EventID, ac.Date)] = true
+ }
+ for i, item := range items {
+ items[i].HasAttendance = taken[fmt.Sprintf("%d|%s", item.EventID, item.Date)]
+ }
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| attendanceCounts, err := svc.db.GetAttendanceCountsForEvents(args, eventIDs, dates) | |
| if err == nil { | |
| taken := make(map[string]bool) | |
| for _, ac := range attendanceCounts { | |
| taken[fmt.Sprintf("%d|%s", ac.EventID, ac.Date)] = true | |
| } | |
| for i, item := range items { | |
| items[i].HasAttendance = taken[fmt.Sprintf("%d|%s", item.EventID, item.Date)] | |
| } | |
| } | |
| attendanceCounts, err := svc.db.GetAttendanceCountsForEvents(args, eventIDs, dates) | |
| if err != nil { | |
| return nil, fmt.Errorf("get attendance counts for today's schedule: %w", err) | |
| } | |
| taken := make(map[string]bool, len(attendanceCounts)) | |
| for _, ac := range attendanceCounts { | |
| taken[fmt.Sprintf("%d|%s", ac.EventID, ac.Date)] = true | |
| } | |
| for i, item := range items { | |
| items[i].HasAttendance = taken[fmt.Sprintf("%d|%s", item.EventID, item.Date)] | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@backend/src/services/classes.go` around lines 346 - 355, The current code
silently ignores errors from svc.db.GetAttendanceCountsForEvents which can lead
to incorrect HasAttendance values; change the handler to propagate the error
instead of swallowing it: check the returned err from
svc.db.GetAttendanceCountsForEvents (called as attendanceCounts, err :=
svc.db.GetAttendanceCountsForEvents(...)) and if err != nil return that error
(or wrap it with context) so the caller can handle it; only run the map
population and set items[i].HasAttendance when err == nil and attendanceCounts
is valid. Ensure you reference svc.db.GetAttendanceCountsForEvents,
attendanceCounts, items and HasAttendance when updating the implementation.
Pre-Submission PR Checklist
Description of the change
After taking attendance for a class session on the Facility Dashboard, the "Take Attendance" button gave no visual indication that action had already been taken. This change makes the button dynamically reflect the real attendance state for each session in Today's Schedule.
Implementation:
GetTodaysSchedule()now calls the existingGetAttendanceCountsForEvents()DB function (already used by the missing-attendance flow) after building the schedule item list, and sets a newhas_attendancefield on each item. The frontend button renders conditionally based on that field. No new DB queries, no migration needed.Asana Task
Screenshot(s)