feat: meals with id and better search
This commit is contained in:
1
model/external/stwbremen/meal.go
vendored
1
model/external/stwbremen/meal.go
vendored
@ -2,6 +2,7 @@ package stwbremen
|
||||
|
||||
type Meal struct {
|
||||
Title string `json:"title"`
|
||||
ID string `json:"id"`
|
||||
Ingredients []Ingredient `json:"ingredients"`
|
||||
Prices []Price `json:"prices"`
|
||||
Location string `json:"location"`
|
||||
|
||||
@ -16,12 +16,15 @@ func MealFromDTO(meal stwbremen.Meal) (*Meal, error) {
|
||||
return nil, fmt.Errorf("unable to parse meal date: %w", err)
|
||||
}
|
||||
|
||||
id, _ := strings.CutPrefix(meal.ID, "meals/")
|
||||
|
||||
return &Meal{
|
||||
Title: meal.Title,
|
||||
Location: meal.Location,
|
||||
Date: date,
|
||||
Tags: strings.Split(strings.Replace(meal.Tags, " ", "", -1), ","),
|
||||
Counter: meal.Counter,
|
||||
Title: meal.Title,
|
||||
RestaurantID: meal.Location,
|
||||
ID: id,
|
||||
Date: date,
|
||||
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 {
|
||||
@ -41,13 +44,14 @@ func MealFromDTO(meal stwbremen.Meal) (*Meal, error) {
|
||||
const ResourceMeal = "meal"
|
||||
|
||||
type Meal struct {
|
||||
Title string
|
||||
Location string
|
||||
Ingredients []ingredient
|
||||
Prices map[string]float32
|
||||
Date time.Time
|
||||
Counter string
|
||||
Tags []string
|
||||
Title string
|
||||
ID string
|
||||
RestaurantID string
|
||||
Ingredients []ingredient
|
||||
Prices map[string]float32
|
||||
Date time.Time
|
||||
Counter string
|
||||
Tags []string
|
||||
}
|
||||
|
||||
type ingredient struct {
|
||||
@ -56,10 +60,12 @@ type ingredient struct {
|
||||
}
|
||||
|
||||
func (d *Meal) Kind() string { return ResourceMeal }
|
||||
func (d *Meal) ItemName() string { return d.Title }
|
||||
func (d *Meal) ItemName() string { return d.ID }
|
||||
|
||||
// Table output
|
||||
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"]}
|
||||
func (d *Meal) ColumnNames() []string {
|
||||
return []string{"Date", "Restaurant", "Title", "Counter", "Price"}
|
||||
}
|
||||
func (d *Meal) Columns() []any {
|
||||
return []any{d.Date.Format(time.DateOnly), d.RestaurantID, d.Title, d.Counter, d.Prices["Studierende"]}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user