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
|
2023-08-25 15:43:15 +00:00
|
|
|
id int
|
2022-10-28 22:54:59 +00:00
|
|
|
url string
|
|
|
|
name string
|
|
|
|
menus [7]Menu
|
|
|
|
permanent []Meal
|
|
|
|
}
|
|
|
|
|
|
|
|
type RestaurantJSON struct {
|
2023-08-25 15:43:15 +00:00
|
|
|
Id int `json:"id"`
|
2022-10-28 22:54:59 +00:00
|
|
|
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{
|
2023-08-25 15:43:15 +00:00
|
|
|
Id: restaurant.id,
|
2022-10-28 22:54:59 +00:00
|
|
|
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
|
|
|
|
}
|