lunch-go/pkg/restaurants/restaurant.go

74 lines
1.7 KiB
Go
Raw Permalink Normal View History

2022-10-28 22:54:59 +00:00
package restaurants
import "encoding/json"
type RestaurantInterface interface {
// public
GetMenus() [7]Menu
Parse()
AddPermanentMeal(meal Meal)
MarshalJSON() ([]byte, error)
GetSpecificDayObject(days []int) RestaurantJSON
// private
clearMenus()
}
type Restaurant struct {
RestaurantInterface
url string
name string
menus [7]Menu
permanent []Meal
}
type RestaurantJSON struct {
Restaurant string `json:"restaurant"`
DailyMenus []Menu `json:"dailymenus"`
PermanentMeals []Meal `json:"permanentmeals"`
}
2022-10-29 12:40:18 +00:00
func (restaurant *Restaurant) SetDefaultValues() {
restaurant.url = ""
restaurant.name = ""
restaurant.menus = [7]Menu{}
restaurant.permanent = []Meal{}
}
2022-10-28 22:54:59 +00:00
func (restaurant *Restaurant) AddPermanent(isSoup bool, name string, desc string, price int) {
restaurant.AddPermanentMeal(MakeMeal(isSoup, name, desc, price))
}
func (restaurant *Restaurant) AddPermanentMeal(meal Meal) {
restaurant.permanent = append(restaurant.permanent, meal)
}
func (restaurant Restaurant) GetMenus() [7]Menu {
return restaurant.menus
}
func (restaurant *Restaurant) clearMenus() {
for i := 0; i < 7; i++ {
2022-10-29 12:40:18 +00:00
restaurant.menus[i] = MakeMenuDefault()
2022-10-28 22:54:59 +00:00
}
}
func (restaurant *Restaurant) MarshalJSON() ([]byte, error) {
return json.Marshal(&RestaurantJSON{
Restaurant: restaurant.name,
DailyMenus: restaurant.menus[:],
PermanentMeals: restaurant.permanent,
})
}
func (restaurant *Restaurant) GetSpecificDayObject(days []int) RestaurantJSON {
obj := RestaurantJSON{
Restaurant: restaurant.name,
PermanentMeals: restaurant.permanent,
}
for _, index := range days {
obj.DailyMenus = append(obj.DailyMenus, restaurant.menus[index])
}
return obj
}