From 4e60b4e69f1d00a8b71e3b323842f07f402be252 Mon Sep 17 00:00:00 2001 From: bdoerfchen Date: Sun, 20 Jul 2025 19:56:25 +0200 Subject: [PATCH 1/2] fix: rename dish to meal --- cmd/resources.go | 12 +++---- core/handler/{dishes => meals}/handler.go | 20 ++++++------ model/external/stwbremen/{dish.go => meal.go} | 2 +- model/resources/{dish.go => meals.go} | 32 +++++++++---------- 4 files changed, 33 insertions(+), 33 deletions(-) rename core/handler/{dishes => meals}/handler.go (78%) rename model/external/stwbremen/{dish.go => meal.go} (96%) rename model/resources/{dish.go => meals.go} (57%) diff --git a/cmd/resources.go b/cmd/resources.go index a55c015..d1fde41 100644 --- a/cmd/resources.go +++ b/cmd/resources.go @@ -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" @@ -21,12 +21,12 @@ var availableResources = []interfaces.ResourceCommand[any]{ Handler: ®isteredResourcesHandler{}, }, { - 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](), }, }, } diff --git a/core/handler/dishes/handler.go b/core/handler/meals/handler.go similarity index 78% rename from core/handler/dishes/handler.go rename to core/handler/meals/handler.go index a3fbea5..3e43286 100644 --- a/core/handler/dishes/handler.go +++ b/core/handler/meals/handler.go @@ -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, diff --git a/model/external/stwbremen/dish.go b/model/external/stwbremen/meal.go similarity index 96% rename from model/external/stwbremen/dish.go rename to model/external/stwbremen/meal.go index 84f48a8..9d0d84a 100644 --- a/model/external/stwbremen/dish.go +++ b/model/external/stwbremen/meal.go @@ -1,6 +1,6 @@ package stwbremen -type Dish struct { +type Meal struct { Title string `json:"title"` Ingredients []Ingredient `json:"ingredients"` Prices []Price `json:"prices"` diff --git a/model/resources/dish.go b/model/resources/meals.go similarity index 57% rename from model/resources/dish.go rename to model/resources/meals.go index 96601b8..4e02c3d 100644 --- a/model/resources/dish.go +++ b/model/resources/meals.go @@ -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"]} } -- 2.49.0 From 975fb67520777c4508eea502c69ce0d3064040c1 Mon Sep 17 00:00:00 2001 From: bdoerfchen Date: Sun, 20 Jul 2025 19:57:17 +0200 Subject: [PATCH 2/2] fix: resource const --- .gitignore | 3 ++- cmd/resources.go | 4 ++-- model/resources/resources.go | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 90af283..e5567bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ unifood -__bin* \ No newline at end of file +__bin* +__debug* \ No newline at end of file diff --git a/cmd/resources.go b/cmd/resources.go index d1fde41..c21a7dc 100644 --- a/cmd/resources.go +++ b/cmd/resources.go @@ -16,7 +16,7 @@ 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: ®isteredResourcesHandler{}, }, @@ -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, diff --git a/model/resources/resources.go b/model/resources/resources.go index 1917c79..a915266 100644 --- a/model/resources/resources.go +++ b/model/resources/resources.go @@ -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"} } -- 2.49.0