feat(19-01): enrich TabloCardView with Progress field and wire batch progress query

- Add Progress int field to TabloCardView (D-05)
- Map row.Status into Tablo struct in TabloCardsFromUnreadRows
- Wire ListTabloProgressByIDs batch query in TablosListHandler (no N+1)
- Non-fatal error handling: progress defaults to 0 on query failure
This commit is contained in:
Arthur Belleville 2026-05-17 16:28:15 +02:00
parent c1928e312f
commit 47ba2f1797
No known key found for this signature in database
2 changed files with 24 additions and 0 deletions

View file

@ -51,6 +51,28 @@ func TablosListHandler(deps TablosDeps) http.HandlerFunc {
}
cardViews := templates.TabloCardsFromUnreadRows(tabloRows)
// Batch progress query: one query for all tablos (D-06, no N+1).
tabloIDs := make([]uuid.UUID, len(cardViews))
for i, cv := range cardViews {
tabloIDs[i] = cv.Tablo.ID
}
progressRows, progressErr := deps.Queries.ListTabloProgressByIDs(r.Context(), tabloIDs)
if progressErr != nil {
slog.Default().Error("tablos list: progress query failed", "user_id", user.ID, "err", progressErr)
// Non-fatal: proceed with Progress = 0 for all cards.
progressRows = nil
}
progressMap := make(map[uuid.UUID]int, len(progressRows))
for _, p := range progressRows {
if p.TotalTasks > 0 {
progressMap[p.TabloID] = int(p.DoneTasks * 100 / p.TotalTasks)
}
}
for i := range cardViews {
cardViews[i].Progress = progressMap[cardViews[i].Tablo.ID]
}
sidebarTablos := make([]sqlc.Tablo, 0, len(cardViews))
for _, cv := range cardViews {
sidebarTablos = append(sidebarTablos, cv.Tablo)

View file

@ -36,6 +36,7 @@ type DiscussionTabData struct {
type TabloCardView struct {
Tablo sqlc.Tablo
DiscussionUnreadCount int64
Progress int // 0100; 0 when no tasks (D-05)
}
func DiscussionPostURL(tabloID uuid.UUID) string {
@ -90,6 +91,7 @@ func TabloCardsFromUnreadRows(rows []sqlc.ListTablosByUserWithDiscussionUnreadRo
Color: row.Color,
CreatedAt: row.CreatedAt,
UpdatedAt: row.UpdatedAt,
Status: row.Status,
},
DiscussionUnreadCount: row.DiscussionUnreadCount,
})