lot of new functionalities
This commit is contained in:
21
servers/web/external/handler.go
vendored
Normal file
21
servers/web/external/handler.go
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
package external
|
||||
|
||||
import (
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/core/application"
|
||||
cache "git.coopgo.io/coopgo-apps/parcoursmob/core/utils/storage"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
cfg *viper.Viper
|
||||
applicationHandler *application.ApplicationHandler
|
||||
filestorage cache.FileStorage
|
||||
}
|
||||
|
||||
func NewHandler(cfg *viper.Viper, applicationHandler *application.ApplicationHandler, filestorage cache.FileStorage) *Handler {
|
||||
return &Handler{
|
||||
cfg: cfg,
|
||||
applicationHandler: applicationHandler,
|
||||
filestorage: filestorage,
|
||||
}
|
||||
}
|
||||
55
servers/web/external/solidarity_transport.go
vendored
Normal file
55
servers/web/external/solidarity_transport.go
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
package external
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/rs/zerolog/log"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/renderer"
|
||||
)
|
||||
|
||||
func (h *Handler) SolidarityTransportExternalBookingProposalHTTPHandler() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
bookingId := vars["bookingid"]
|
||||
|
||||
// Get booking data
|
||||
result, err := h.applicationHandler.GetSolidarityTransportBookingData(r.Context(), bookingId)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("could not get booking data")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Handle POST form submission
|
||||
if r.Method == "POST" {
|
||||
if err = r.ParseForm(); err != nil {
|
||||
log.Error().Err(err).Msg("error parsing form data")
|
||||
}
|
||||
message := r.FormValue("message")
|
||||
action := r.FormValue("action")
|
||||
|
||||
if action != "" {
|
||||
err := h.applicationHandler.UpdateSolidarityTransportBookingStatus(r.Context(), bookingId, action, "Refusé par le bénévole", message, true)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("update booking status issue")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Get updated booking data
|
||||
result, err = h.applicationHandler.GetSolidarityTransportBookingData(r.Context(), bookingId)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("could not get updated booking data")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create renderer temporarily to maintain functionality
|
||||
templates_root := h.cfg.GetString("templates.root")
|
||||
renderer := renderer.NewRenderer(h.cfg, templates_root, h.filestorage)
|
||||
renderer.SolidarityTransportExternalBookingDisplay(w, r, result.Booking, result.Driver, result.Passenger)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user