fix: rename dish to meal

This commit is contained in:
2025-07-20 19:56:25 +02:00
parent da2d507629
commit 4e60b4e69f
4 changed files with 33 additions and 33 deletions

View File

@ -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"
@ -21,12 +21,12 @@ var availableResources = []interfaces.ResourceCommand[any]{
Handler: &registeredResourcesHandler{}, Handler: &registeredResourcesHandler{},
}, },
{ {
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](),
}, },
}, },
} }

View File

@ -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,

View File

@ -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"`

View File

@ -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"]}
} }