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

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