fix: rename dish to meal (#3)

Reviewed-on: #3
Co-authored-by: bdoerfchen <git@bissendorf.co>
Co-committed-by: bdoerfchen <git@bissendorf.co>
This commit is contained in:
2025-07-20 18:01:26 +00:00
committed by bissendorf
parent da2d507629
commit e395b0b4ca
6 changed files with 40 additions and 37 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
unifood
__bin*
__bin*
__debug*

View File

@ -3,7 +3,7 @@ package cmd
import (
"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/params"
"git.bissendorf.co/bissendorf/unifood/m/v2/core/services/stwhbclient"
@ -16,17 +16,17 @@ var availableResources = []interfaces.ResourceCommand[any]{
{
Name: "resources",
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},
Handler: &registeredResourcesHandler{},
},
{
Name: "dishes",
Aliases: []string{"dish", "d"},
Description: "A dish represents a cooked combination of ingredients that can be bought and consumed",
Name: "meals",
Aliases: []string{"meal", "m"},
Description: "A meal represents a cooked combination of ingredients that can be bought and consumed",
Verbs: []interfaces.Verb{interfaces.VerbGet},
Handler: &dishes.DishesHandler{
QueryClient: stwhbclient.New[[]stwbremen.Dish](),
Handler: &meals.MealsHandler{
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) {
return &interfaces.ResourceList{
ItemKind: "",
ItemKind: resources.ResourceResource,
Items: util.Transform(availableResources, func(i *interfaces.ResourceCommand[any]) interfaces.Resource {
return &resources.Resource{
ResourceName: i.Name,

View File

@ -1,4 +1,4 @@
package dishes
package meals
import (
"context"
@ -12,11 +12,11 @@ import (
"git.bissendorf.co/bissendorf/unifood/m/v2/util"
)
type DishesHandler struct {
type MealsHandler struct {
interfaces.ResourceHandler
interfaces.GetHandler
QueryClient interfaces.QueryClient[[]stwbremen.Dish]
QueryClient interfaces.QueryClient[[]stwbremen.Meal]
}
const (
@ -24,7 +24,7 @@ const (
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
p, err := params.GetValue(paramDate)
if err != nil {
@ -45,7 +45,7 @@ func (h *DishesHandler) Get(ctx context.Context, params params.Container) (*inte
)
// Run query
dishes, err := h.QueryClient.Get(ctx,
meals, err := h.QueryClient.Get(ctx,
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"}`,
false,
@ -56,11 +56,11 @@ func (h *DishesHandler) Get(ctx context.Context, params params.Container) (*inte
// Return
return &interfaces.ResourceList{
ItemKind: resources.ResourceDish,
Items: util.Transform(*dishes, func(i *stwbremen.Dish) interfaces.Resource {
d, err := resources.DishFromDTO(*i)
ItemKind: resources.ResourceMeal,
Items: util.Transform(*meals, func(i *stwbremen.Meal) interfaces.Resource {
d, err := resources.MealFromDTO(*i)
if err != nil {
return &resources.Dish{}
return &resources.Meal{}
}
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{
{
Name: paramDate,

View File

@ -1,6 +1,6 @@
package stwbremen
type Dish struct {
type Meal struct {
Title string `json:"title"`
Ingredients []Ingredient `json:"ingredients"`
Prices []Price `json:"prices"`

View File

@ -10,26 +10,26 @@ import (
"git.bissendorf.co/bissendorf/unifood/m/v2/util"
)
func DishFromDTO(dish stwbremen.Dish) (*Dish, error) {
date, err := time.Parse(time.DateOnly, dish.Date)
func MealFromDTO(meal stwbremen.Meal) (*Meal, error) {
date, err := time.Parse(time.DateOnly, meal.Date)
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{
Title: dish.Title,
Location: dish.Location,
return &Meal{
Title: meal.Title,
Location: meal.Location,
Date: date,
Tags: strings.Split(strings.Replace(dish.Tags, " ", "", -1), ","),
Counter: dish.Counter,
Prices: util.Map(dish.Prices, func(i *stwbremen.Price) (string, float32) {
Tags: strings.Split(strings.Replace(meal.Tags, " ", "", -1), ","),
Counter: meal.Counter,
Prices: util.Map(meal.Prices, func(i *stwbremen.Price) (string, float32) {
p, err := strconv.ParseFloat(strings.Trim(i.Price, " "), 32)
if err != nil {
p = 0
}
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{
Name: i.Label,
Additionals: i.Additionals,
@ -38,9 +38,9 @@ func DishFromDTO(dish stwbremen.Dish) (*Dish, error) {
}, nil
}
const ResourceDish = "dish"
const ResourceMeal = "meal"
type Dish struct {
type Meal struct {
Title string
Location string
Ingredients []ingredient
@ -55,10 +55,10 @@ type ingredient struct {
Additionals []string
}
func (d *Dish) Kind() string { return ResourceDish }
func (d *Dish) Name() string { return d.Title }
func (d *Meal) Kind() string { return ResourceMeal }
func (d *Meal) Name() string { return d.Title }
func (d *Dish) ColumnNames() []string { return []string{"Location", "Date", "Counter", "Price"} }
func (d *Dish) Columns() []any {
func (d *Meal) ColumnNames() []string { return []string{"Location", "Date", "Counter", "Price"} }
func (d *Meal) Columns() []any {
return []any{d.Location, d.Date.Format(time.DateOnly), d.Counter, d.Prices["Studierende"]}
}

View File

@ -2,13 +2,15 @@ package resources
import "strings"
const ResourceResource = "resource"
type Resource struct {
ResourceName string
Aliases []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) ColumnNames() []string { return []string{"Aliases", "Description"} }