Return empty arrays rather than null

This commit is contained in:
zv0n 2022-10-29 14:40:18 +02:00
parent 90b4ae7e75
commit b57959ac73
4 changed files with 16 additions and 1 deletions

View File

@ -17,6 +17,7 @@ type FreshRestaurant struct {
func MakeFreshRestaurant(url string, name string) FreshRestaurant {
restaurant := FreshRestaurant{}
restaurant.SetDefaultValues()
restaurant.url = url
restaurant.name = name
return restaurant
@ -24,6 +25,7 @@ func MakeFreshRestaurant(url string, name string) FreshRestaurant {
func NewFreshRestaurant(url string, name string) *FreshRestaurant {
restaurant := new(FreshRestaurant)
restaurant.SetDefaultValues()
restaurant.url = url
restaurant.name = name
return restaurant

View File

@ -16,6 +16,7 @@ type MenickaRestaurant struct {
func MakeMenickaRestaurant(url string, name string) MenickaRestaurant {
restaurant := MenickaRestaurant{}
restaurant.SetDefaultValues()
restaurant.url = url
restaurant.name = name
return restaurant
@ -23,6 +24,7 @@ func MakeMenickaRestaurant(url string, name string) MenickaRestaurant {
func NewMenickaRestaurant(url string, name string) *MenickaRestaurant {
restaurant := new(MenickaRestaurant)
restaurant.SetDefaultValues()
restaurant.url = url
restaurant.name = name
return restaurant

View File

@ -8,6 +8,10 @@ type Menu struct {
day string
}
func MakeMenuDefault() Menu {
return Menu{make([]Meal, 0), true, ""}
}
func MakeMenu(meals []Meal, day string) Menu {
return Menu{meals, true, day}
}

View File

@ -28,6 +28,13 @@ type RestaurantJSON struct {
PermanentMeals []Meal `json:"permanentmeals"`
}
func (restaurant *Restaurant) SetDefaultValues() {
restaurant.url = ""
restaurant.name = ""
restaurant.menus = [7]Menu{}
restaurant.permanent = []Meal{}
}
func (restaurant *Restaurant) AddPermanent(isSoup bool, name string, desc string, price int) {
restaurant.AddPermanentMeal(MakeMeal(isSoup, name, desc, price))
}
@ -42,7 +49,7 @@ func (restaurant Restaurant) GetMenus() [7]Menu {
func (restaurant *Restaurant) clearMenus() {
for i := 0; i < 7; i++ {
restaurant.menus[i] = Menu{}
restaurant.menus[i] = MakeMenuDefault()
}
}