Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/src/models/program_classes.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type TodaysScheduleItem struct {
Date string `json:"date"`
StartTime string `json:"start_time"`
Room string `json:"room"`
HasAttendance bool `json:"has_attendance"`
}

func (c *ProgramClass) BeforeCreate(tx *gorm.DB) error {
Expand Down
19 changes: 19 additions & 0 deletions backend/src/services/classes.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,25 @@ func (svc *ClassesService) GetTodaysSchedule(args *models.QueryContext, facility
}
}

if len(items) > 0 {
eventIDs := make([]uint, 0, len(items))
dates := make([]string, 0, len(items))
for _, item := range items {
eventIDs = append(eventIDs, item.EventID)
dates = append(dates, item.Date)
}
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)]
}
}
Comment on lines +346 to +355

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

Suggested change
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.

}

sort.Slice(items, func(i, j int) bool {
if items[i].Date == items[j].Date { //sorting by date, time, then by name
if items[i].StartTime == items[j].StartTime {
Expand Down
14 changes: 12 additions & 2 deletions frontend/src/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,23 @@ function TodaysSchedule({
</div>
<Button
size="sm"
variant={
item.has_attendance
? 'outline'
: 'default'
}
onClick={(e) => {
e.stopPropagation();
onNavigate(item);
}}
className="bg-brand hover:bg-brand-dark text-white w-full sm:w-auto"
className={
item.has_attendance
? 'border-gray-300 w-full sm:w-auto'
: 'bg-brand hover:bg-brand-dark text-white w-full sm:w-auto'
}
>
Take Attendance
{item.has_attendance ? 'Edit' : 'Take'}{' '}
Attendance
</Button>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export interface TodaysScheduleItem {
date: string;
start_time: string;
room: string;
has_attendance?: boolean;
}

export interface ClassMetrics {
Expand Down
Loading