feat: resource list and table output formatter
This commit is contained in:
@ -17,19 +17,17 @@ func DishFromDTO(dish stwbremen.Dish) (*Dish, error) {
|
||||
}
|
||||
|
||||
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 {
|
||||
Title: dish.Title,
|
||||
Location: dish.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) {
|
||||
p, err := strconv.ParseFloat(strings.Trim(i.Price, " "), 32)
|
||||
if err != nil {
|
||||
p = 0
|
||||
}
|
||||
return price{
|
||||
Label: i.Label,
|
||||
Price: float32(p),
|
||||
}
|
||||
return i.Label, float32(p)
|
||||
}),
|
||||
Ingredients: util.Select(util.Transform(dish.Ingredients, func(i *stwbremen.Ingredient) ingredient {
|
||||
return ingredient{
|
||||
@ -40,10 +38,13 @@ func DishFromDTO(dish stwbremen.Dish) (*Dish, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
const ResourceDish = "dish"
|
||||
|
||||
type Dish struct {
|
||||
Title string
|
||||
Location string
|
||||
Ingredients []ingredient
|
||||
Prices []price
|
||||
Prices map[string]float32
|
||||
Date time.Time
|
||||
Counter string
|
||||
Tags []string
|
||||
@ -54,7 +55,10 @@ type ingredient struct {
|
||||
Additionals []string
|
||||
}
|
||||
|
||||
type price struct {
|
||||
Label string
|
||||
Price float32
|
||||
func (d *Dish) Kind() string { return ResourceDish }
|
||||
func (d *Dish) Name() string { return d.Title }
|
||||
|
||||
func (d *Dish) ColumnNames() []string { return []string{"Location", "Date", "Counter", "Price"} }
|
||||
func (d *Dish) Columns() []any {
|
||||
return []any{d.Location, d.Date.Format(time.DateOnly), d.Counter, d.Prices["Studierende"]}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user