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