lot of new functionalities
This commit is contained in:
40
servers/web/application/support.go
Normal file
40
servers/web/application/support.go
Normal file
@@ -0,0 +1,40 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user