feat: GET /lists now returns total items and completed items of that list

This commit is contained in:
2026-08-21 21:10:17 +02:00
parent d2f0f1a4cf
commit be588dd405
2 changed files with 8 additions and 6 deletions
+6 -4
View File
@@ -18,10 +18,12 @@ var (
) )
type List struct { type List struct {
ID string `json:"id"` ID string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
ModifiedAt time.Time `json:"modified_at"` ModifiedAt time.Time `json:"modified_at"`
TotalItems int `json:"total_items"`
CompletedItems int `json:"completed_items"`
} }
type ListItem struct { type ListItem struct {
+2 -2
View File
@@ -61,7 +61,7 @@ func (r *ListRepo) CreateList(ctx context.Context, name string, userIDs []string
func (r *ListRepo) GetLists(ctx context.Context, userID string) ([]domain.List, error) { func (r *ListRepo) GetLists(ctx context.Context, userID string) ([]domain.List, error) {
rows, err := r.db.QueryContext(ctx, rows, err := r.db.QueryContext(ctx,
"SELECT id, name, lists.created_at, modified_at, COUNT(*) FROM lists INNER JOIN list_users ON lists.id=list_users.list_id WHERE list_users.user_id = $1", "SELECT l.id, l.name, l.created_at, l.modified_at, (SELECT COUNT(*) FROM list_items WHERE list_id=l.id), (SELECT COUNT(*) FROM list_items WHERE list_id=l.id AND is_completed=true) FROM lists AS l INNER JOIN list_users ON lists.id=list_users.list_id WHERE list_users.user_id = $1",
userID, userID,
) )
if err != nil { if err != nil {
@@ -75,7 +75,7 @@ func (r *ListRepo) GetLists(ctx context.Context, userID string) ([]domain.List,
var lists []domain.List var lists []domain.List
for rows.Next() { for rows.Next() {
var l domain.List var l domain.List
err = rows.Scan(&l.ID, &l.Name, &l.CreatedAt, &l.ModifiedAt) err = rows.Scan(&l.ID, &l.Name, &l.CreatedAt, &l.ModifiedAt, &l.TotalItems, &l.CompletedItems)
if err != nil { if err != nil {
return nil, err return nil, err
} }