Compare commits
2 Commits
feat/timeo
...
975fb67520
| Author | SHA1 | Date | |
|---|---|---|---|
| 975fb67520 | |||
| 4e60b4e69f |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
unifood
|
unifood
|
||||||
__bin*
|
__bin*
|
||||||
|
__debug*
|
||||||
@ -3,7 +3,7 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.bissendorf.co/bissendorf/unifood/m/v2/core/handler/dishes"
|
"git.bissendorf.co/bissendorf/unifood/m/v2/core/handler/meals"
|
||||||
"git.bissendorf.co/bissendorf/unifood/m/v2/core/interfaces"
|
"git.bissendorf.co/bissendorf/unifood/m/v2/core/interfaces"
|
||||||
"git.bissendorf.co/bissendorf/unifood/m/v2/core/interfaces/params"
|
"git.bissendorf.co/bissendorf/unifood/m/v2/core/interfaces/params"
|
||||||
"git.bissendorf.co/bissendorf/unifood/m/v2/core/services/stwhbclient"
|
"git.bissendorf.co/bissendorf/unifood/m/v2/core/services/stwhbclient"
|
||||||
@ -16,17 +16,17 @@ var availableResources = []interfaces.ResourceCommand[any]{
|
|||||||
{
|
{
|
||||||
Name: "resources",
|
Name: "resources",
|
||||||
Aliases: []string{"resource", "r"},
|
Aliases: []string{"resource", "r"},
|
||||||
Description: "A meta representation of a usable resources of this CLI",
|
Description: "A meta resource representing all other object kinds of this CLI",
|
||||||
Verbs: []interfaces.Verb{interfaces.VerbGet},
|
Verbs: []interfaces.Verb{interfaces.VerbGet},
|
||||||
Handler: ®isteredResourcesHandler{},
|
Handler: ®isteredResourcesHandler{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "dishes",
|
Name: "meals",
|
||||||
Aliases: []string{"dish", "d"},
|
Aliases: []string{"meal", "m"},
|
||||||
Description: "A dish represents a cooked combination of ingredients that can be bought and consumed",
|
Description: "A meal represents a cooked combination of ingredients that can be bought and consumed",
|
||||||
Verbs: []interfaces.Verb{interfaces.VerbGet},
|
Verbs: []interfaces.Verb{interfaces.VerbGet},
|
||||||
Handler: &dishes.DishesHandler{
|
Handler: &meals.MealsHandler{
|
||||||
QueryClient: stwhbclient.New[[]stwbremen.Dish](),
|
QueryClient: stwhbclient.New[[]stwbremen.Meal](),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ type registeredResourcesHandler struct{}
|
|||||||
|
|
||||||
func (h *registeredResourcesHandler) Get(ctx context.Context, params params.Container) (*interfaces.ResourceList, error) {
|
func (h *registeredResourcesHandler) Get(ctx context.Context, params params.Container) (*interfaces.ResourceList, error) {
|
||||||
return &interfaces.ResourceList{
|
return &interfaces.ResourceList{
|
||||||
ItemKind: "",
|
ItemKind: resources.ResourceResource,
|
||||||
Items: util.Transform(availableResources, func(i *interfaces.ResourceCommand[any]) interfaces.Resource {
|
Items: util.Transform(availableResources, func(i *interfaces.ResourceCommand[any]) interfaces.Resource {
|
||||||
return &resources.Resource{
|
return &resources.Resource{
|
||||||
ResourceName: i.Name,
|
ResourceName: i.Name,
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
package dishes
|
package meals
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -12,11 +12,11 @@ import (
|
|||||||
"git.bissendorf.co/bissendorf/unifood/m/v2/util"
|
"git.bissendorf.co/bissendorf/unifood/m/v2/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DishesHandler struct {
|
type MealsHandler struct {
|
||||||
interfaces.ResourceHandler
|
interfaces.ResourceHandler
|
||||||
interfaces.GetHandler
|
interfaces.GetHandler
|
||||||
|
|
||||||
QueryClient interfaces.QueryClient[[]stwbremen.Dish]
|
QueryClient interfaces.QueryClient[[]stwbremen.Meal]
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -24,7 +24,7 @@ const (
|
|||||||
paramLocation = "location"
|
paramLocation = "location"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *DishesHandler) Get(ctx context.Context, params params.Container) (*interfaces.ResourceList, error) {
|
func (h *MealsHandler) Get(ctx context.Context, params params.Container) (*interfaces.ResourceList, error) {
|
||||||
// Read parameters
|
// Read parameters
|
||||||
p, err := params.GetValue(paramDate)
|
p, err := params.GetValue(paramDate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -45,7 +45,7 @@ func (h *DishesHandler) Get(ctx context.Context, params params.Container) (*inte
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Run query
|
// Run query
|
||||||
dishes, err := h.QueryClient.Get(ctx,
|
meals, err := h.QueryClient.Get(ctx,
|
||||||
query,
|
query,
|
||||||
`{"title":true,"ingredients":"page.ingredients.toObject","prices":"page.prices.toObject","location":true,"counter":true,"date":true,"mealadds":true,"mark":true,"frei3":true,"printonly":true,"kombicategory":true,"categories":"page.categories.split"}`,
|
`{"title":true,"ingredients":"page.ingredients.toObject","prices":"page.prices.toObject","location":true,"counter":true,"date":true,"mealadds":true,"mark":true,"frei3":true,"printonly":true,"kombicategory":true,"categories":"page.categories.split"}`,
|
||||||
false,
|
false,
|
||||||
@ -56,11 +56,11 @@ func (h *DishesHandler) Get(ctx context.Context, params params.Container) (*inte
|
|||||||
|
|
||||||
// Return
|
// Return
|
||||||
return &interfaces.ResourceList{
|
return &interfaces.ResourceList{
|
||||||
ItemKind: resources.ResourceDish,
|
ItemKind: resources.ResourceMeal,
|
||||||
Items: util.Transform(*dishes, func(i *stwbremen.Dish) interfaces.Resource {
|
Items: util.Transform(*meals, func(i *stwbremen.Meal) interfaces.Resource {
|
||||||
d, err := resources.DishFromDTO(*i)
|
d, err := resources.MealFromDTO(*i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &resources.Dish{}
|
return &resources.Meal{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return d
|
return d
|
||||||
@ -69,7 +69,7 @@ func (h *DishesHandler) Get(ctx context.Context, params params.Container) (*inte
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *DishesHandler) GetParametersForVerb(verb interfaces.Verb) []params.Registration {
|
func (h *MealsHandler) GetParametersForVerb(verb interfaces.Verb) []params.Registration {
|
||||||
return []params.Registration{
|
return []params.Registration{
|
||||||
{
|
{
|
||||||
Name: paramDate,
|
Name: paramDate,
|
||||||
@ -1,6 +1,6 @@
|
|||||||
package stwbremen
|
package stwbremen
|
||||||
|
|
||||||
type Dish struct {
|
type Meal struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Ingredients []Ingredient `json:"ingredients"`
|
Ingredients []Ingredient `json:"ingredients"`
|
||||||
Prices []Price `json:"prices"`
|
Prices []Price `json:"prices"`
|
||||||
@ -10,26 +10,26 @@ import (
|
|||||||
"git.bissendorf.co/bissendorf/unifood/m/v2/util"
|
"git.bissendorf.co/bissendorf/unifood/m/v2/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DishFromDTO(dish stwbremen.Dish) (*Dish, error) {
|
func MealFromDTO(meal stwbremen.Meal) (*Meal, error) {
|
||||||
date, err := time.Parse(time.DateOnly, dish.Date)
|
date, err := time.Parse(time.DateOnly, meal.Date)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to parse dish date: %w", err)
|
return nil, fmt.Errorf("unable to parse meal date: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Dish{
|
return &Meal{
|
||||||
Title: dish.Title,
|
Title: meal.Title,
|
||||||
Location: dish.Location,
|
Location: meal.Location,
|
||||||
Date: date,
|
Date: date,
|
||||||
Tags: strings.Split(strings.Replace(dish.Tags, " ", "", -1), ","),
|
Tags: strings.Split(strings.Replace(meal.Tags, " ", "", -1), ","),
|
||||||
Counter: dish.Counter,
|
Counter: meal.Counter,
|
||||||
Prices: util.Map(dish.Prices, func(i *stwbremen.Price) (string, float32) {
|
Prices: util.Map(meal.Prices, func(i *stwbremen.Price) (string, float32) {
|
||||||
p, err := strconv.ParseFloat(strings.Trim(i.Price, " "), 32)
|
p, err := strconv.ParseFloat(strings.Trim(i.Price, " "), 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p = 0
|
p = 0
|
||||||
}
|
}
|
||||||
return i.Label, float32(p)
|
return i.Label, float32(p)
|
||||||
}),
|
}),
|
||||||
Ingredients: util.Select(util.Transform(dish.Ingredients, func(i *stwbremen.Ingredient) ingredient {
|
Ingredients: util.Select(util.Transform(meal.Ingredients, func(i *stwbremen.Ingredient) ingredient {
|
||||||
return ingredient{
|
return ingredient{
|
||||||
Name: i.Label,
|
Name: i.Label,
|
||||||
Additionals: i.Additionals,
|
Additionals: i.Additionals,
|
||||||
@ -38,9 +38,9 @@ func DishFromDTO(dish stwbremen.Dish) (*Dish, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const ResourceDish = "dish"
|
const ResourceMeal = "meal"
|
||||||
|
|
||||||
type Dish struct {
|
type Meal struct {
|
||||||
Title string
|
Title string
|
||||||
Location string
|
Location string
|
||||||
Ingredients []ingredient
|
Ingredients []ingredient
|
||||||
@ -55,10 +55,10 @@ type ingredient struct {
|
|||||||
Additionals []string
|
Additionals []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dish) Kind() string { return ResourceDish }
|
func (d *Meal) Kind() string { return ResourceMeal }
|
||||||
func (d *Dish) Name() string { return d.Title }
|
func (d *Meal) Name() string { return d.Title }
|
||||||
|
|
||||||
func (d *Dish) ColumnNames() []string { return []string{"Location", "Date", "Counter", "Price"} }
|
func (d *Meal) ColumnNames() []string { return []string{"Location", "Date", "Counter", "Price"} }
|
||||||
func (d *Dish) Columns() []any {
|
func (d *Meal) Columns() []any {
|
||||||
return []any{d.Location, d.Date.Format(time.DateOnly), d.Counter, d.Prices["Studierende"]}
|
return []any{d.Location, d.Date.Format(time.DateOnly), d.Counter, d.Prices["Studierende"]}
|
||||||
}
|
}
|
||||||
@ -2,13 +2,15 @@ package resources
|
|||||||
|
|
||||||
import "strings"
|
import "strings"
|
||||||
|
|
||||||
|
const ResourceResource = "resource"
|
||||||
|
|
||||||
type Resource struct {
|
type Resource struct {
|
||||||
ResourceName string
|
ResourceName string
|
||||||
Aliases []string
|
Aliases []string
|
||||||
Description string
|
Description string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Resource) Kind() string { return "Resource" }
|
func (r *Resource) Kind() string { return ResourceResource }
|
||||||
func (r *Resource) Name() string { return r.ResourceName }
|
func (r *Resource) Name() string { return r.ResourceName }
|
||||||
|
|
||||||
func (r *Resource) ColumnNames() []string { return []string{"Aliases", "Description"} }
|
func (r *Resource) ColumnNames() []string { return []string{"Aliases", "Description"} }
|
||||||
|
|||||||
Reference in New Issue
Block a user