diff --git a/pkg/campsite/admin.go b/pkg/campsite/admin.go index 6b95e81..f5612e9 100644 --- a/pkg/campsite/admin.go +++ b/pkg/campsite/admin.go @@ -149,7 +149,9 @@ func addCampsite(w http.ResponseWriter, r *http.Request, user *auth.User, compan f.MustRender(w, r, user, company) return } - conn.MustExec(r.Context(), "select add_campsite($1, $2)", f.CampsiteType, f.Label) + if _, err := conn.AddCampsite(r.Context(), f.CampsiteType.String(), f.Label.Val); err != nil { + panic(err) + } httplib.Redirect(w, r, "/admin/campsites", http.StatusSeeOther) } @@ -169,7 +171,9 @@ func editCampsite(w http.ResponseWriter, r *http.Request, user *auth.User, compa f.MustRender(w, r, user, company) return } - conn.MustExec(r.Context(), "select edit_campsite($1, $2, $3, $4)", f.ID, f.CampsiteType, f.Label, f.Active) + if err := conn.EditCampsite(r.Context(), f.ID, f.CampsiteType.String(), f.Label.Val, f.Active.Checked); err != nil { + panic(err) + } httplib.Redirect(w, r, "/admin/campsites", http.StatusSeeOther) } diff --git a/pkg/database/funcs.go b/pkg/database/funcs.go index 66c94d4..64a562f 100644 --- a/pkg/database/funcs.go +++ b/pkg/database/funcs.go @@ -11,6 +11,15 @@ import ( "golang.org/x/text/language" ) +func (c *Conn) AddCampsite(ctx context.Context, typeSlug string, label string) (int, error) { + return c.GetInt(ctx, "select add_campsite($1, $2)", typeSlug, label) +} + +func (c *Conn) EditCampsite(ctx context.Context, id int, typeSlug string, label string, active bool) error { + _, err := c.Exec(ctx, "select edit_campsite($1, $2, $3, $4)", id, typeSlug, label, active) + return err +} + func (tx *Tx) AddCampsiteType(ctx context.Context, companyID int, mediaID int, name string, spiel string, info string, facilities string, description string, additionalInfo string, checkIn string, checkOut string, maxCampers int, dogsAllowed bool) (string, error) { return tx.GetText(ctx, "select add_campsite_type($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)", companyID, mediaID, name, spiel, info, facilities, description, additionalInfo, checkIn, checkOut, maxCampers, dogsAllowed) }