fix(services): add db tags to SummaryCounts so sqlx maps this_week (et al.)

Bug 1 (smoke-auth-2026-04-25.md) had a third symptom beyond the RLS
function bodies and the visibilityPredicate `::uuid[]` issue:
/api/deadlines/summary and /api/appointments/summary returned 500 with
`sqlx: missing destination name this_week in *services.SummaryCounts`.

Cause: SummaryCounts (deadline) and AppointmentSummaryCounts had only
`json:` tags. sqlx falls back to the lower-cased field name when no `db:`
tag is present, so `ThisWeek` mapped to `thisweek` — but the SQL aliases
the column as `AS this_week`. Adding `db:"this_week"` (and matching tags
for the other fields) lets sqlx find the destination.

Verified by hitting both endpoints; previously 500 → now expected 200.
This commit is contained in:
m
2026-04-25 23:44:52 +02:00
parent 1f9c4d0296
commit 4bc23958ee
2 changed files with 9 additions and 9 deletions

View File

@@ -404,10 +404,10 @@ func (s *AppointmentService) Delete(ctx context.Context, userID, terminID uuid.U
// AppointmentSummaryCounts buckets visible Appointments into today / this_week / later.
type AppointmentSummaryCounts struct {
Today int `json:"today"`
ThisWeek int `json:"this_week"`
Later int `json:"later"`
Total int `json:"total"`
Today int `json:"today" db:"today"`
ThisWeek int `json:"this_week" db:"this_week"`
Later int `json:"later" db:"later"`
Total int `json:"total" db:"total"`
}
// SummaryCounts aggregates Appointments by start-date bucket for the user's visible projects.

View File

@@ -383,11 +383,11 @@ func (s *DeadlineService) Delete(ctx context.Context, userID, fristID uuid.UUID)
// SummaryCounts returns traffic-light counts across the user's visible Deadlines.
type SummaryCounts struct {
Overdue int `json:"overdue"`
ThisWeek int `json:"this_week"`
Upcoming int `json:"upcoming"`
Completed int `json:"completed"`
Total int `json:"total"`
Overdue int `json:"overdue" db:"overdue"`
ThisWeek int `json:"this_week" db:"this_week"`
Upcoming int `json:"upcoming" db:"upcoming"`
Completed int `json:"completed" db:"completed"`
Total int `json:"total" db:"total"`
}
// SummaryCounts aggregates Deadlines by due-date bucket for the user's visible