Create Go functions for PostgreSQL functions for campsite type option
I am going to base these to create the function for campsite type feature, and since i intend to
This commit is contained in:
parent
a174837aea
commit
d784291a04
|
@ -125,7 +125,9 @@ func editOptionL10n(w http.ResponseWriter, r *http.Request, user *auth.User, com
|
|||
l10n.MustRender(w, r, user, company)
|
||||
return
|
||||
}
|
||||
conn.MustExec(r.Context(), "select translate_campsite_type_option($1, $2, $3)", l10n.ID, l10n.Locale.Language, l10n.Name)
|
||||
if err := conn.TranslateCampsiteTypeOption(r.Context(), l10n.ID, l10n.Locale.Language, l10n.Name.Val); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
httplib.Redirect(w, r, "/admin/campsites/types/"+l10n.TypeSlug+"/options", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
|
|
|
@ -181,7 +181,7 @@ func addOption(w http.ResponseWriter, r *http.Request, user *auth.User, company
|
|||
panic(err)
|
||||
}
|
||||
processOptionForm(w, r, user, company, conn, f, func(ctx context.Context, tx *database.Tx) error {
|
||||
id, err := tx.GetInt(ctx, "select add_campsite_type_option($1, $2, $3, $4)", typeSlug, f.Name, f.Min, f.Max)
|
||||
id, err := tx.AddCampsiteTypeOption(ctx, typeSlug, f.Name.Val, f.Min.Int(), f.Max.Int())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ func addOption(w http.ResponseWriter, r *http.Request, user *auth.User, company
|
|||
|
||||
func editOption(w http.ResponseWriter, r *http.Request, user *auth.User, company *auth.Company, conn *database.Conn, f *optionForm) {
|
||||
processOptionForm(w, r, user, company, conn, f, func(ctx context.Context, tx *database.Tx) error {
|
||||
if _, err := conn.Exec(ctx, "select edit_campsite_type_option($1, $2, $3, $4)", f.ID, f.Name, f.Min, f.Max); err != nil {
|
||||
if _, err := tx.EditCampsiteTypeOption(ctx, f.ID, f.Name.Val, f.Min.Int(), f.Max.Int()); err != nil {
|
||||
return err
|
||||
}
|
||||
return setOptionPrices(ctx, tx, f.ID, f.Prices)
|
||||
|
@ -222,7 +222,7 @@ func processOptionForm(w http.ResponseWriter, r *http.Request, user *auth.User,
|
|||
|
||||
func setOptionPrices(ctx context.Context, tx *database.Tx, id int, prices map[int]*optionPriceForm) error {
|
||||
for seasonID, p := range prices {
|
||||
if _, err := tx.Exec(ctx, "select set_campsite_type_option_cost($1, $2, $3)", id, seasonID, p.PricePerNight); err != nil {
|
||||
if err := tx.SetCampsiteTypeOptionCost(ctx, id, seasonID, p.PricePerNight.Val); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,3 +27,21 @@ func (tx *Tx) SetCampsiteTypeCost(ctx context.Context, slug string, seasonID int
|
|||
_, err := tx.Exec(ctx, "select set_campsite_type_cost($1, $2, $3, $4)", slug, seasonID, minNights, costPerNight)
|
||||
return err
|
||||
}
|
||||
|
||||
func (tx *Tx) AddCampsiteTypeOption(ctx context.Context, typeSlug string, name string, min int, max int) (int, error) {
|
||||
return tx.GetInt(ctx, "select add_campsite_type_option($1, $2, $3, $4)", typeSlug, name, min, max)
|
||||
}
|
||||
|
||||
func (tx *Tx) EditCampsiteTypeOption(ctx context.Context, id int, name string, min int, max int) (int, error) {
|
||||
return tx.GetInt(ctx, "select edit_campsite_type_option($1, $2, $3, $4)", id, name, min, max)
|
||||
}
|
||||
|
||||
func (tx *Tx) SetCampsiteTypeOptionCost(ctx context.Context, id int, seasonID int, pricePerNight string) error {
|
||||
_, err := tx.Exec(ctx, "select set_campsite_type_option_cost($1, $2, $3)", id, seasonID, pricePerNight)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Conn) TranslateCampsiteTypeOption(ctx context.Context, id int, langTag language.Tag, name string) error {
|
||||
_, err := c.Exec(ctx, "select translate_campsite_type_option($1, $2, $3)", id, langTag, name)
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue