Add database functions for AddCampsite and EditCampsite

This commit is contained in:
jordi fita mas 2024-01-25 20:48:39 +01:00
parent 8d49857dae
commit ad161f57b2
2 changed files with 15 additions and 2 deletions

View File

@ -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)
}

View File

@ -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)
}