From 30abdd4d367e3128b38ae2d7ea318eee4c132081 Mon Sep 17 00:00:00 2001 From: Matt Kilgore Date: Sat, 22 Jun 2024 16:15:22 -0400 Subject: [PATCH] chore(backend): removed extra unneeded property to pagination --- backend/app/api/handlers/v1/v1_ctrl_items.go | 7 +++---- backend/app/api/handlers/v1/v1_ctrl_locations.go | 5 ++--- backend/internal/data/repo/pagination.go | 1 - docs/docs/api/openapi-2.0.json | 6 ++---- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/backend/app/api/handlers/v1/v1_ctrl_items.go b/backend/app/api/handlers/v1/v1_ctrl_items.go index ec78c7b0..857f49f6 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_items.go +++ b/backend/app/api/handlers/v1/v1_ctrl_items.go @@ -4,9 +4,9 @@ import ( "database/sql" "encoding/csv" "errors" + "math/big" "net/http" "strings" - "math/big" "github.com/google/uuid" "github.com/hay-kot/httpkit/errchain" @@ -83,13 +83,12 @@ func (ctrl *V1Controller) HandleItemsGetAll() errchain.HandlerFunc { items, err := ctrl.repo.Items.QueryByGroup(ctx, ctx.GID, extractQuery(r)) totalPrice := new(big.Int) for _, item := range items.Items { - totalPrice.Add(totalPrice, big.NewInt(int64(item.PurchasePrice * 100))) + totalPrice.Add(totalPrice, big.NewInt(int64(item.PurchasePrice*100))) } totalPriceFloat := new(big.Float).SetInt(totalPrice) totalPriceFloat.Quo(totalPriceFloat, big.NewFloat(100)) - items.TotalPrice, _ = totalPriceFloat.Float64() - + if err != nil { if errors.Is(err, sql.ErrNoRows) { return server.JSON(w, http.StatusOK, repo.PaginationResult[repo.ItemSummary]{ diff --git a/backend/app/api/handlers/v1/v1_ctrl_locations.go b/backend/app/api/handlers/v1/v1_ctrl_locations.go index 632e9d36..eff6e9c8 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_locations.go +++ b/backend/app/api/handlers/v1/v1_ctrl_locations.go @@ -1,10 +1,9 @@ package v1 import ( - "net/http" - "fmt" "context" "math/big" + "net/http" "github.com/google/uuid" "github.com/hay-kot/httpkit/errchain" @@ -93,7 +92,7 @@ func (ctrl *V1Controller) GetLocationWithPrice(auth context.Context, GID uuid.UU totalPrice := new(big.Int) items, err := ctrl.repo.Items.QueryByGroup(auth, GID, repo.ItemQuery{LocationIDs: []uuid.UUID{ID}}) for _, item := range items.Items { - totalPrice.Add(totalPrice, big.NewInt(int64(item.PurchasePrice * 100))) + totalPrice.Add(totalPrice, big.NewInt(int64(item.PurchasePrice*100))) } totalPriceFloat := new(big.Float).SetInt(totalPrice) diff --git a/backend/internal/data/repo/pagination.go b/backend/internal/data/repo/pagination.go index 5f540ee4..d8878d02 100644 --- a/backend/internal/data/repo/pagination.go +++ b/backend/internal/data/repo/pagination.go @@ -5,7 +5,6 @@ type PaginationResult[T any] struct { PageSize int `json:"pageSize"` Total int `json:"total"` Items []T `json:"items"` - TotalPrice float64 `json:"totalPrice"` } func calculateOffset(page, pageSize int) int { diff --git a/docs/docs/api/openapi-2.0.json b/docs/docs/api/openapi-2.0.json index dab7ef77..d517beac 100644 --- a/docs/docs/api/openapi-2.0.json +++ b/docs/docs/api/openapi-2.0.json @@ -1683,14 +1683,12 @@ "parameters": [ { "type": "string", - "example": "admin@admin.com", "description": "string", "name": "username", "in": "formData" }, { "type": "string", - "example": "admin", "description": "string", "name": "password", "in": "formData" @@ -2711,8 +2709,8 @@ "total": { "type": "integer" }, - "updatedAt": { - "type": "string" + "totalPrice": { + "type": "number" } } },