parcoursmob/servers/web/application/support.go

40 lines
1.1 KiB
Go

package application
import (
"net/http"
"git.coopgo.io/coopgo-apps/parcoursmob/core/utils/identification"
"github.com/rs/zerolog/log"
)
func (h *Handler) SupportSendHTTPHandler() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
c := r.Context().Value(identification.ClaimsKey)
if c == nil {
log.Error().Msg("no current user claims")
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
currentUserClaims := c.(map[string]any)
if r.Method == "POST" {
// Parse form data
comment := r.PostFormValue("comment")
userEmail := currentUserClaims["email"].(string)
err := h.applicationHandler.SendSupportMessage(r.Context(), comment, userEmail)
if err != nil {
log.Error().Err(err).Msg("error sending support message")
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/app/", http.StatusFound)
return
}
// GET request - show form
comment := r.FormValue("comment")
h.renderer.SupportSend(w, r, comment, currentUserClaims)
}
}