36 lines
816 B
Go
36 lines
816 B
Go
package application
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func (h *Handler) SendSMSHTTPHandler() http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != "POST" {
|
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
|
return
|
|
}
|
|
|
|
referer := r.Referer()
|
|
|
|
if err := r.ParseForm(); err != nil {
|
|
log.Error().Err(err).Msg("Bad request")
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
message := r.PostFormValue("message")
|
|
beneficiaryID := r.PostFormValue("beneficiaryid")
|
|
|
|
err := h.applicationHandler.SendSMS(r.Context(), beneficiaryID, message)
|
|
if err != nil {
|
|
log.Error().Err(err).Msg("error sending SMS")
|
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
http.Redirect(w, r, referer, http.StatusFound)
|
|
}
|
|
} |