From a5a00668ec6e27ba45ca81bcf4f43ef79fb0c741 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Sat, 18 Feb 2023 09:51:26 -0900 Subject: [PATCH] use item quantity as count mechanism --- backend/internal/data/repo/repo_locations.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/internal/data/repo/repo_locations.go b/backend/internal/data/repo/repo_locations.go index 2d3ea56..25a17f0 100644 --- a/backend/internal/data/repo/repo_locations.go +++ b/backend/internal/data/repo/repo_locations.go @@ -105,7 +105,7 @@ func (r *LocationRepository) GetAll(ctx context.Context, GID uuid.UUID, filter L updated_at, ( SELECT - COUNT(*) + SUM(items.quantity) FROM items WHERE @@ -135,11 +135,17 @@ func (r *LocationRepository) GetAll(ctx context.Context, GID uuid.UUID, filter L for rows.Next() { var ct LocationOutCount - err := rows.Scan(&ct.ID, &ct.Name, &ct.Description, &ct.CreatedAt, &ct.UpdatedAt, &ct.ItemCount) + var maybeCount *int + + err := rows.Scan(&ct.ID, &ct.Name, &ct.Description, &ct.CreatedAt, &ct.UpdatedAt, &maybeCount) if err != nil { return nil, err } + if maybeCount != nil { + ct.ItemCount = *maybeCount + } + list = append(list, ct) }