Merge branch 'hay-kot:main' into server-price-total

This commit is contained in:
JackBailey 2024-02-29 16:30:23 +00:00 committed by GitHub
commit ae7b857bbc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 459 additions and 119 deletions

View file

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

View file

@ -261,12 +261,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
@ -289,10 +297,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
}