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

This commit is contained in:
Hayden 2023-02-18 09:57:09 -09:00 committed by GitHub
parent 859d3b9ffe
commit 3ac6c7c858
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -105,7 +105,7 @@ func (r *LocationRepository) GetAll(ctx context.Context, GID uuid.UUID, filter L
updated_at, updated_at,
( (
SELECT SELECT
COUNT(*) SUM(items.quantity)
FROM FROM
items items
WHERE WHERE
@ -135,11 +135,17 @@ func (r *LocationRepository) GetAll(ctx context.Context, GID uuid.UUID, filter L
for rows.Next() { for rows.Next() {
var ct LocationOutCount 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 { if err != nil {
return nil, err return nil, err
} }
if maybeCount != nil {
ct.ItemCount = *maybeCount
}
list = append(list, ct) list = append(list, ct)
} }