Replace raw call to remove_campsite_type_carousel_slide with Go func

This commit is contained in:
jordi fita mas 2024-01-22 20:56:48 +01:00
parent b704f2789d
commit 17aaf045bb
2 changed files with 9 additions and 2 deletions

View File

@ -195,12 +195,14 @@ func editSlide(w http.ResponseWriter, r *http.Request, user *auth.User, company
}) })
} }
func deleteSlide(w http.ResponseWriter, r *http.Request, user *auth.User, conn *database.Conn, typeSlug string, mediaId int) { func deleteSlide(w http.ResponseWriter, r *http.Request, user *auth.User, conn *database.Conn, typeSlug string, mediaID int) {
if err := user.VerifyCSRFToken(r); err != nil { if err := user.VerifyCSRFToken(r); err != nil {
http.Error(w, err.Error(), http.StatusForbidden) http.Error(w, err.Error(), http.StatusForbidden)
return return
} }
conn.MustExec(r.Context(), "select remove_campsite_type_carousel_slide($1, $2)", typeSlug, mediaId) if err := conn.RemoveCampsiteTypeCarouselSlide(r.Context(), typeSlug, mediaID); err != nil {
panic(err)
}
httplib.Redirect(w, r, "/admin/campsites/types/"+typeSlug+"/slides", http.StatusSeeOther) httplib.Redirect(w, r, "/admin/campsites/types/"+typeSlug+"/slides", http.StatusSeeOther)
} }

View File

@ -94,6 +94,11 @@ func (tx *Tx) TranslateCampsiteTypeCarouselSlide(ctx context.Context, typeSlug s
return err return err
} }
func (c *Conn) RemoveCampsiteTypeCarouselSlide(ctx context.Context, typeSlug string, mediaID int) error {
_, err := c.Exec(ctx, "select remove_campsite_type_carousel_slide($1, $2)", typeSlug, mediaID)
return err
}
func (c *Conn) SetupRedsys(ctx context.Context, companyID int, merchantCode string, terminalNumber int, environment string, integration string, encryptKey string) error { func (c *Conn) SetupRedsys(ctx context.Context, companyID int, merchantCode string, terminalNumber int, environment string, integration string, encryptKey string) error {
var encryptKeyParam interface{} var encryptKeyParam interface{}
if encryptKey != "" { if encryptKey != "" {