feat: base implementation
This commit is contained in:
21
model/external/stwbremen/dish.go
vendored
Normal file
21
model/external/stwbremen/dish.go
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
package stwbremen
|
||||
|
||||
type Dish struct {
|
||||
Title string `json:"title"`
|
||||
Ingredients []Ingredient `json:"ingredients"`
|
||||
Prices []Price `json:"prices"`
|
||||
Location string `json:"location"`
|
||||
Date string `json:"date"` // YYYY-MM-DD
|
||||
Counter string `json:"counter"`
|
||||
Tags string `json:"mealadds"`
|
||||
}
|
||||
|
||||
type Ingredient struct {
|
||||
Label string `json:"label"`
|
||||
Additionals []string `json:"additionals"`
|
||||
}
|
||||
|
||||
type Price struct {
|
||||
Label string `json:"label"`
|
||||
Price string `json:"price"`
|
||||
}
|
||||
7
model/external/stwbremen/result.go
vendored
Normal file
7
model/external/stwbremen/result.go
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
package stwbremen
|
||||
|
||||
type Result[T any] struct {
|
||||
Code uint16 `json:"code"`
|
||||
Status string `json:"status"`
|
||||
Result T `json:"result"`
|
||||
}
|
||||
65
model/resources/menu.go
Normal file
65
model/resources/menu.go
Normal file
@ -0,0 +1,65 @@
|
||||
package resources
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.bissendorf.co/bissendorf/unifood/m/v2/model/external/stwbremen"
|
||||
"git.bissendorf.co/bissendorf/unifood/m/v2/util"
|
||||
)
|
||||
|
||||
type Menu struct {
|
||||
Location string
|
||||
Dishes []Dish
|
||||
}
|
||||
|
||||
func DishFromDTO(dish stwbremen.Dish) (*Dish, error) {
|
||||
date, err := time.Parse(time.DateOnly, dish.Date)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse dish date: %w", err)
|
||||
}
|
||||
|
||||
return &Dish{
|
||||
Title: dish.Title,
|
||||
Date: date,
|
||||
Tags: strings.Split(strings.Replace(dish.Tags, " ", "", -1), ","),
|
||||
Counter: dish.Counter,
|
||||
Prices: util.Transform(dish.Prices, func(i *stwbremen.Price) price {
|
||||
p, err := strconv.ParseFloat(strings.Trim(i.Price, " "), 32)
|
||||
if err != nil {
|
||||
p = 0
|
||||
}
|
||||
return price{
|
||||
Label: i.Label,
|
||||
Price: float32(p),
|
||||
}
|
||||
}),
|
||||
Ingredients: util.Select(util.Transform(dish.Ingredients, func(i *stwbremen.Ingredient) ingredient {
|
||||
return ingredient{
|
||||
Name: i.Label,
|
||||
Additionals: i.Additionals,
|
||||
}
|
||||
}), func(i *ingredient) bool { return i.Name != "" }),
|
||||
}, nil
|
||||
}
|
||||
|
||||
type Dish struct {
|
||||
Title string
|
||||
Ingredients []ingredient
|
||||
Prices []price
|
||||
Date time.Time
|
||||
Counter string
|
||||
Tags []string
|
||||
}
|
||||
|
||||
type ingredient struct {
|
||||
Name string
|
||||
Additionals []string
|
||||
}
|
||||
|
||||
type price struct {
|
||||
Label string
|
||||
Price float32
|
||||
}
|
||||
Reference in New Issue
Block a user