Skip to content

A continuation of HomeBox the inventory and organization system built for the Home User

fix: use item quantity as count mechanism (#304)

Hayden3ac6c7c8587c
diff --git a/backend/internal/data/repo/repo_locations.go b/backend/internal/data/repo/repo_locations.go
index 2d3ea568..25a17f07 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)
}