Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Add total price to label and location pages #722

Open
wants to merge 107 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
a042496
chore: bump all go deps (#507)
hay-kot Jul 23, 2023
dc94465
fix(deps): update module github.com/swaggo/http-swagger to v2 (#506)
renovate[bot] Jul 23, 2023
27dad0e
fix(deps): update module github.com/swaggo/http-swagger to v2 (#508)
renovate[bot] Jul 23, 2023
06eb6c1
fix 3 places where API URLs were not constructed by function route (#…
db8200 Jul 23, 2023
0167809
ui: rework location/labels pages (#475)
hay-kot Jul 27, 2023
371fc0a
chore(deps): update dependency mkdocs-material to v9.1.21 (#512)
renovate[bot] Jul 29, 2023
c5ae6b1
feat: more currency support (#520)
hay-kot Jul 31, 2023
02ce52d
fix: assert/asserts (#521)
hay-kot Jul 31, 2023
895017b
fix: label prop not being passed to password input (#522)
hay-kot Jul 31, 2023
5a219f6
feat: support cmd+s / ctrl+s and rework button display on edit (#523)
hay-kot Jul 31, 2023
8c7d91e
fix: prevent resetting dialog state on error (#524)
hay-kot Jul 31, 2023
22bbaae
feat: add support for create + add more for all create modals and sup…
hay-kot Jul 31, 2023
3f0e65a
include rootless dockerfile
hay-kot Aug 2, 2023
275e106
build nightly rootless
hay-kot Aug 2, 2023
272cc5a
chore(deps): update dependency vitest to ^0.34.0 (#529)
renovate[bot] Aug 2, 2023
2e2eed1
try node 18
hay-kot Aug 2, 2023
cceec06
specify h3 dependency
hay-kot Aug 2, 2023
2cbcc8b
feat: WebSocket based implementation of server sent events for cache …
hay-kot Aug 2, 2023
b5987f2
feat: set cookies' expires attribute and fix remember me (#530)
gucheen Aug 10, 2023
9fa17be
update lock file
hay-kot Aug 10, 2023
5438898
feat: add currencies XAG and XAU (#535)
tctlrd Aug 23, 2023
0876deb
fix websocket over secure connection (#542)
hay-kot Aug 24, 2023
94fd9c3
fix: mobile "Create and Add Another" goes off screen (#540)
JonathanGawrych Aug 31, 2023
c89aa73
fix(deps): update module github.com/rs/zerolog to v1.30.0 (#517)
renovate[bot] Sep 14, 2023
5f41960
fix(deps): update module modernc.org/sqlite to v1.25.0 (#531)
renovate[bot] Sep 14, 2023
5739b20
chore(deps): update dependency eslint-config-prettier to v9 (#533)
renovate[bot] Sep 14, 2023
fbc7e6e
fix: minor typo (#546)
Aaron-von-Awesome Sep 14, 2023
455163d
fix(deps): update module golang.org/x/crypto to v0.13.0 (#532)
renovate[bot] Sep 14, 2023
fc56984
fix(deps): update module github.com/google/uuid to v1.3.1 (#551)
renovate[bot] Sep 14, 2023
744a5bb
fix(deps): update module github.com/swaggo/swag to v1.16.2 (#552)
renovate[bot] Sep 14, 2023
e68b7cf
fix(deps): update module github.com/go-playground/validator/v10 to v1…
renovate[bot] Oct 6, 2023
a9712c4
chore(deps): update dependency mkdocs-material to v9.4.4 (#553)
renovate[bot] Oct 6, 2023
f13bf29
pr: fixed incorrect sum of the total items price (#568)
hay-kot Oct 6, 2023
a33cf54
fix(deps): update module github.com/containrrr/shoutrrr to v0.8.0 (#555)
renovate[bot] Oct 6, 2023
b28bb2c
fix(deps): update module github.com/yeqown/go-qrcode/writer/standard …
renovate[bot] Oct 6, 2023
f3f9672
fix: ensure loading in toggled (#571)
hay-kot Oct 6, 2023
2b31d46
fix(deps): update module github.com/rs/zerolog to v1.31.0 (#569)
renovate[bot] Oct 6, 2023
1952b9f
fix(deps): update module golang.org/x/crypto to v0.14.0 (#570)
renovate[bot] Oct 6, 2023
db16d3f
feat: make selectables clearable (#572)
hay-kot Oct 6, 2023
63a966c
fix: field values request fails (#573)
hay-kot Oct 6, 2023
318b8be
feat: primary images (#576)
hay-kot Oct 7, 2023
0dc4fa5
fix(deps): update module modernc.org/sqlite to v1.26.0 (#574)
renovate[bot] Oct 7, 2023
2cd3c15
chore(deps): update dependency nuxt to v3.7.4 (#554)
renovate[bot] Oct 7, 2023
1365bdf
refactor: rewrite to cookie based auth (#578)
hay-kot Oct 7, 2023
d8482f3
Revert "chore(deps): update dependency nuxt to v3.7.4 (#554)" (#580)
hay-kot Oct 7, 2023
ae4b953
fix: infinite redirect issue (#583)
hay-kot Oct 10, 2023
0995478
fix: restore location section (#587)
hay-kot Oct 15, 2023
e5f66d9
chore(deps): update dependency mkdocs-material to v9.4.8 (#592)
renovate[bot] Nov 15, 2023
3e2ab29
chore(deps): update docker/setup-buildx-action action to v3 (#579)
renovate[bot] Nov 15, 2023
b08e521
chore(deps): update actions/checkout action to v4 (#575)
renovate[bot] Nov 15, 2023
4738a9b
chore: rewrite generator to resolve strange name generation (#612)
hay-kot Nov 16, 2023
c0e8e34
chore: bump all go dependencies (#614)
hay-kot Nov 16, 2023
b408318
fix: filepath sep on windows (#615)
hay-kot Nov 16, 2023
51ba15f
fix: ensure urls isn't encoded (#618)
hay-kot Nov 16, 2023
da22074
feat : Validate bark, ntfy, generic+ shortcut (#591)
chessmango Nov 16, 2023
db27d34
chore(deps): update pnpm/action-setup action to v2.4.0 (#511)
renovate[bot] Nov 16, 2023
80e2071
fix: use theme aware background color (#619)
hay-kot Nov 16, 2023
a70ee33
chore(deps): update actions/setup-node action to v4 (#621)
renovate[bot] Nov 16, 2023
eeae790
feat: expose timeout variables (#622)
hay-kot Nov 16, 2023
e65d44f
fix(deps): update dependency @pinia/nuxt to ^0.5.0 (#620)
renovate[bot] Nov 16, 2023
2eafa8e
chore(deps): update dependency @vite-pwa/nuxt to ^0.2.0 (#616)
renovate[bot] Nov 16, 2023
2594d4c
chore(deps): update dependency @types/markdown-it to v13 (#577)
renovate[bot] Nov 16, 2023
afbc6a4
fix: images in child items (#623)
hay-kot Nov 16, 2023
8cc0f30
fix: allow zeroing out asset ids (#624)
hay-kot Nov 16, 2023
9edbda3
feat: set version flag (#632)
hay-kot Nov 24, 2023
10c030a
docs: Fix a bunch of grammar and spelling, rephrased some sentences t…
kevinholtkamp Nov 30, 2023
7ec22ed
chore(deps): update dependency mkdocs-material to v9.4.14 (#630)
renovate[bot] Nov 30, 2023
db00e7a
chore(deps): update goreleaser/goreleaser-action action to v5 (#626)
renovate[bot] Nov 30, 2023
d1d98bc
chore(deps): update docker/setup-qemu-action action to v3 (#625)
renovate[bot] Nov 30, 2023
321a83b
fix/feat: primary photo auto set and auto-set primary photo (#651)
hay-kot Dec 1, 2023
4d9131b
fix: loading causing stale data to present in form(#650)
hay-kot Dec 1, 2023
f2363b8
fix: ignore /api paths from service workers (#649)
hay-kot Dec 1, 2023
014fdea
fix(deps): update module github.com/hay-kot/httpkit to v0.0.5 (#643)
renovate[bot] Dec 1, 2023
126c06a
fix(deps): update module golang.org/x/crypto to v0.16.0 (#645)
renovate[bot] Dec 1, 2023
b559216
fix(deps): update github.com/gocarina/gocsv digest to b87c2d0 (#629)
renovate[bot] Dec 1, 2023
8a85b18
chore(deps): update dependency mkdocs-material to v9.5.2 (#654)
renovate[bot] Dec 12, 2023
0bc3969
chore(deps): update actions/setup-go action to v5 (#653)
renovate[bot] Dec 12, 2023
ff2577a
chore(deps): update dependency vitest to v1 (#652)
renovate[bot] Dec 12, 2023
5229436
fix(deps): update dependency markdown-it to v14 (#655)
renovate[bot] Dec 12, 2023
8538877
feat: extract auth into provider (#663)
hay-kot Dec 12, 2023
85c8e47
fix: ensure rows are closed (#670)
hay-kot Dec 16, 2023
3ee150e
feat: add log statements + remove auto redirect (#671)
hay-kot Dec 16, 2023
b918310
fix: Render newlines in markdown fields (#682)
zebrapurring Dec 25, 2023
e8449b3
fix: inaccruate 401 & sql busy error (#679)
hay-kot Jan 4, 2024
f3f2116
fix(deps): update module golang.org/x/crypto to v0.17.0 [security] (#…
renovate[bot] Jan 4, 2024
d8e4962
feat: show quantity in card view if quantity == 0 (hay-kot/homebox#67…
bee-eater Jan 4, 2024
8ede42f
fix(deps): update module github.com/google/uuid to v1.5.0 (#664)
renovate[bot] Jan 4, 2024
6d8260b
fix(deps): update module github.com/go-chi/chi/v5 to v5.0.11 (#698)
renovate[bot] Jan 4, 2024
d920e1e
chore(deps): update dependency mkdocs-material to v9.5.3 (#697)
renovate[bot] Jan 4, 2024
d2bde3f
fix: task swag (#710)
quoing Jan 17, 2024
c4b9238
feat: user defined currencies (#700)
hay-kot Jan 18, 2024
f2f7809
feat: enable search by serial number or model number (#677)
zebrapurring Jan 18, 2024
d374fae
fix(deps): update module golang.org/x/crypto to v0.18.0 (#706)
renovate[bot] Jan 18, 2024
b3b81a3
chore(deps): update dependency mkdocs-material to v9.5.4 (#716)
renovate[bot] Jan 19, 2024
6ee4103
fix(deps): update module github.com/mattn/go-sqlite3 to v1.14.19 (#668)
renovate[bot] Jan 19, 2024
94399a9
fix(deps): update module github.com/go-playground/validator/v10 to v1…
renovate[bot] Jan 20, 2024
de4081d
fix(deps): update module modernc.org/sqlite to v1.28.0 (#667)
renovate[bot] Jan 20, 2024
b8b706e
chore(deps): update dependency mkdocs-material to v9.5.5 (#720)
renovate[bot] Jan 24, 2024
59a5a17
fix(deps): update module github.com/google/uuid to v1.6.0 (#719)
renovate[bot] Jan 24, 2024
f67c986
Add label and location total price
JackBailey Jan 25, 2024
26c0e33
Fix typo
JackBailey Jan 25, 2024
baad90c
Merge branch 'hay-kot:main' into server-price-total
JackBailey Jan 25, 2024
94c57cf
Merge branch 'main' into server-price-total
JackBailey Jan 31, 2024
026660d
Update API docs
JackBailey Jan 31, 2024
af160df
Fix label page (Result of slightly wrong merge)
JackBailey Jan 31, 2024
2b2f715
Merge branch 'hay-kot:main' into server-price-total
JackBailey Feb 8, 2024
ae7b857
Merge branch 'hay-kot:main' into server-price-total
JackBailey Feb 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added backend/api
Binary file not shown.
11 changes: 11 additions & 0 deletions backend/app/api/handlers/v1/v1_ctrl_items.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"net/http"
"strings"
"math/big"

"github.com/google/uuid"
"github.com/hay-kot/homebox/backend/internal/core/services"
Expand Down Expand Up @@ -79,7 +80,17 @@ func (ctrl *V1Controller) HandleItemsGetAll() errchain.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) error {
ctx := services.NewContext(r.Context())

// deal with floating point precision
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)))
}

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]{
Expand Down
33 changes: 32 additions & 1 deletion backend/app/api/handlers/v1/v1_ctrl_locations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package v1

import (
"net/http"
"fmt"
"context"
"math/big"

"github.com/google/uuid"
"github.com/hay-kot/homebox/backend/internal/core/services"
Expand Down Expand Up @@ -83,6 +86,32 @@ func (ctrl *V1Controller) HandleLocationDelete() errchain.HandlerFunc {
return adapters.CommandID("id", fn, http.StatusNoContent)
}

func (ctrl *V1Controller) GetLocationWithPrice(auth context.Context, GID uuid.UUID, ID uuid.UUID) (repo.LocationOut, error) {
var location, err = ctrl.repo.Locations.GetOneByGroup(auth, GID, ID)

// Add direct child items price
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)))
}

totalPriceFloat := new(big.Float).SetInt(totalPrice)
totalPriceFloat.Quo(totalPriceFloat, big.NewFloat(100))
location.TotalPrice, _ = totalPriceFloat.Float64()

// Add price from child locations
for _, childLocation := range location.Children {
var childLocation, err = ctrl.GetLocationWithPrice(auth, GID, childLocation.ID)
if err != nil {
fmt.Println(err)
}
location.TotalPrice += childLocation.TotalPrice
}

return location, err
}

// HandleLocationGet godoc
//
// @Summary Get Location
Expand All @@ -95,7 +124,9 @@ func (ctrl *V1Controller) HandleLocationDelete() errchain.HandlerFunc {
func (ctrl *V1Controller) HandleLocationGet() errchain.HandlerFunc {
fn := func(r *http.Request, ID uuid.UUID) (repo.LocationOut, error) {
auth := services.NewContext(r.Context())
return ctrl.repo.Locations.GetOneByGroup(auth, auth.GID, ID)
var location, err = ctrl.GetLocationWithPrice(auth, auth.GID, ID)

return location, err
}

return adapters.CommandID("id", fn, http.StatusOK)
Expand Down
6 changes: 6 additions & 0 deletions backend/app/api/static/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2469,6 +2469,9 @@
"parent": {
"$ref": "#/definitions/repo.LocationSummary"
},
"totalPrice": {
"type": "number"
},
"updatedAt": {
"type": "string"
}
Expand Down Expand Up @@ -2707,6 +2710,9 @@
},
"total": {
"type": "integer"
},
"totalPrice": {
"type": "number"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions backend/internal/data/repo/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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 {
Expand Down
1 change: 1 addition & 0 deletions backend/internal/data/repo/repo_locations.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type (
Parent *LocationSummary `json:"parent,omitempty"`
LocationSummary
Children []LocationSummary `json:"children"`
TotalPrice float64 `json:"totalPrice"`
}
)

Expand Down
6 changes: 6 additions & 0 deletions docs/docs/api/openapi-2.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -2469,6 +2469,9 @@
"parent": {
"$ref": "#/definitions/repo.LocationSummary"
},
"totalPrice": {
"type": "number"
},
"updatedAt": {
"type": "string"
}
Expand Down Expand Up @@ -2707,6 +2710,9 @@
},
"total": {
"type": "integer"
},
"totalPrice": {
"type": "number"
}
}
},
Expand Down
2 changes: 2 additions & 0 deletions frontend/lib/api/types/data-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export interface LocationOut {
id: string;
name: string;
parent: LocationSummary;
totalPrice: number;
updatedAt: Date | string;
}

Expand Down Expand Up @@ -329,6 +330,7 @@ export interface PaginationResultItemSummary {
page: number;
pageSize: number;
total: number;
totalPrice: number;
}

export interface TotalsByOrganizer {
Expand Down
15 changes: 12 additions & 3 deletions frontend/pages/label/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
return [];
}

return resp.data.items;
return resp.data;
});
</script>

Expand All @@ -111,8 +111,17 @@
</div>
</div>
<div>
<h1 class="text-2xl pb-1">
<h1 class="text-2xl pb-1 flex items-center gap-3">
{{ label ? label.name : "" }}

<div
v-if="items && items.totalPrice"
class="text-xs bg-secondary text-secondary-content rounded-full px-2 py-1"
>
<div>
<Currency :amount="items.totalPrice" />
</div>
</div>
</h1>
<div class="flex gap-1 flex-wrap text-xs">
<div>
Expand Down Expand Up @@ -140,7 +149,7 @@
<Markdown v-if="label && label.description" class="text-base" :source="label.description"> </Markdown>
</div>
<section v-if="label && items">
<ItemViewSelectable :items="items" />
<ItemViewSelectable :items="items.items" />
</section>
</BaseContainer>
</BaseContainer>
Expand Down
11 changes: 10 additions & 1 deletion frontend/pages/location/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,17 @@
<li>{{ location.name }}</li>
</ul>
</div>
<h1 class="text-2xl pb-1">
<h1 class="text-2xl pb-1 flex items-center gap-3">
{{ location ? location.name : "" }}

<div
v-if="location && location.totalPrice"
class="text-xs bg-secondary text-secondary-content rounded-full px-2 py-1"
>
<div>
<Currency :amount="location.totalPrice" />
</div>
</div>
</h1>
<div class="flex gap-1 flex-wrap text-xs">
<div>
Expand Down