From 3ac6c7c8587c092be51841fd0921707f581fd3b0 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Sat, 18 Feb 2023 09:57:09 -0900 Subject: [PATCH] fix: use item quantity as count mechanism (#304) --- 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) }