fix: profile bugs and add full path (#792)

* fix template rendering

* tidy

* fix missing currencies and profile errors

* endpoint for fullpath of an item

* endpoint test

* fix assertions
This commit is contained in:
Hayden 2024-02-25 16:04:24 -06:00 committed by GitHub
parent 3ed50f5a1b
commit c708b1759e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 416 additions and 105 deletions

View file

@ -74,18 +74,23 @@ func (cs *CurrencyRegistry) Slice() []Currency {
cs.mu.RLock()
defer cs.mu.RUnlock()
keys := make([]string, 0, len(cs.registry))
for key := range cs.registry {
keys = append(keys, key)
}
slices.Sort(keys)
out := make([]Currency, 0, len(cs.registry))
for i := range keys {
out = append(out, cs.registry[keys[i]])
for key := range cs.registry {
out = append(out, cs.registry[key])
}
slices.SortFunc(out, func(a, b Currency) int {
if a.Name < b.Name {
return -1
}
if a.Name > b.Name {
return 1
}
return 0
})
return out
}

View file

@ -1,4 +1,10 @@
[
{
"code": "USD",
"local": "United States",
"symbol": "$",
"name": "United States Dollar"
},
{
"code": "AED",
"local": "United Arab Emirates",

View file

@ -84,7 +84,7 @@ func (csf LocationString) String() string {
return strings.Join(csf, " / ")
}
func fromPathSlice(s []repo.LocationPath) LocationString {
func fromPathSlice(s []repo.ItemPath) LocationString {
v := make(LocationString, len(s))
for i := range s {

View file

@ -20,4 +20,4 @@ import "github.com/google/uuid"
}
{{ end }}
{{ end }}
{{ end }}

View file

@ -260,12 +260,20 @@ type TreeQuery struct {
WithItems bool `json:"withItems" schema:"withItems"`
}
type LocationPath struct {
type ItemType string
const (
ItemTypeLocation ItemType = "location"
ItemTypeItem ItemType = "item"
)
type ItemPath struct {
Type ItemType `json:"type"`
ID uuid.UUID `json:"id"`
Name string `json:"name"`
}
func (r *LocationRepository) PathForLoc(ctx context.Context, GID, locID uuid.UUID) ([]LocationPath, error) {
func (r *LocationRepository) PathForLoc(ctx context.Context, GID, locID uuid.UUID) ([]ItemPath, error) {
query := `WITH RECURSIVE location_path AS (
SELECT id, name, location_children
FROM locations
@ -288,10 +296,11 @@ func (r *LocationRepository) PathForLoc(ctx context.Context, GID, locID uuid.UUI
}
defer func() { _ = rows.Close() }()
var locations []LocationPath
var locations []ItemPath
for rows.Next() {
var location LocationPath
var location ItemPath
location.Type = ItemTypeLocation
if err := rows.Scan(&location.ID, &location.Name); err != nil {
return nil, err
}