This commit is contained in:
+27
-1
@@ -25,6 +25,14 @@ type speciesInput struct {
|
||||
WinterProtection *string `json:"winter_protection"`
|
||||
SpacingCM *int `json:"spacing_cm"`
|
||||
HeightCM *int `json:"height_cm"`
|
||||
HeightCMFrom *int `json:"height_cm_from"`
|
||||
HeightCMTo *int `json:"height_cm_to"`
|
||||
WidthCMFrom *int `json:"width_cm_from"`
|
||||
WidthCMTo *int `json:"width_cm_to"`
|
||||
ClearHeightCMFrom bool `json:"clear_height_cm_from"`
|
||||
ClearHeightCMTo bool `json:"clear_height_cm_to"`
|
||||
ClearWidthCMFrom bool `json:"clear_width_cm_from"`
|
||||
ClearWidthCMTo bool `json:"clear_width_cm_to"`
|
||||
SowMonthFrom *int `json:"sow_month_from"`
|
||||
SowDayFrom *int `json:"sow_day_from"`
|
||||
ClearSowDayFrom bool `json:"clear_sow_day_from"`
|
||||
@@ -70,7 +78,19 @@ func (input speciesInput) apply(species *storage.Species) {
|
||||
assignStringPointer(input.SoilReaction, &species.SoilReaction)
|
||||
assignStringPointer(input.WinterProtection, &species.WinterProtection)
|
||||
assignIntPointer(input.SpacingCM, &species.SpacingCM)
|
||||
assignIntPointer(input.HeightCM, &species.HeightCM)
|
||||
assignIntPointer(input.HeightCMFrom, &species.HeightCMFrom)
|
||||
if input.HeightCMTo != nil {
|
||||
assignIntPointer(input.HeightCMTo, &species.HeightCMTo)
|
||||
} else {
|
||||
assignIntPointer(input.HeightCM, &species.HeightCMTo)
|
||||
}
|
||||
assignIntPointer(input.WidthCMFrom, &species.WidthCMFrom)
|
||||
assignIntPointer(input.WidthCMTo, &species.WidthCMTo)
|
||||
clearIntPointer(input.ClearHeightCMFrom, &species.HeightCMFrom)
|
||||
clearIntPointer(input.ClearHeightCMTo, &species.HeightCMTo)
|
||||
clearIntPointer(input.ClearWidthCMFrom, &species.WidthCMFrom)
|
||||
clearIntPointer(input.ClearWidthCMTo, &species.WidthCMTo)
|
||||
species.HeightCM = species.HeightCMTo
|
||||
assignIntPointer(input.SowMonthFrom, &species.SowMonthFrom)
|
||||
assignIntPointer(input.SowDayFrom, &species.SowDayFrom)
|
||||
assignIntPointer(input.SowMonthTo, &species.SowMonthTo)
|
||||
@@ -138,6 +158,12 @@ func assignIntPointer(input *int, destination **int) {
|
||||
}
|
||||
}
|
||||
|
||||
func clearIntPointer(clear bool, destination **int) {
|
||||
if clear {
|
||||
*destination = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (app *application) createSpeciesHandler(w http.ResponseWriter, r *http.Request) {
|
||||
gardenID, _ := app.readGardenIDParam(r)
|
||||
var input speciesInput
|
||||
|
||||
Reference in New Issue
Block a user