MCPcopy Index your code
hub / github.com/NdoleStudio/httpsms / PostSend

Method PostSend

api/pkg/handlers/message_handler.go:83–115  ·  view source on GitHub ↗

PostSend a new entities.Message @Summary Send an SMS message @Description Add a new SMS message to be sent by your Android phone @Security ApiKeyAuth @Tags Messages @Accept json @Produce json @Param payload body requests.MessageSend true "Send message request pay

(c fiber.Ctx)

Source from the content-addressed store, hash-verified

81// @Failure 500 {object} responses.InternalServerError
82// @Router /messages/send [post]
83func (h *MessageHandler) PostSend(c fiber.Ctx) error {
84 ctx, span := h.tracer.StartFromFiberCtx(c)
85 defer span.End()
86
87 ctxLogger := h.tracer.CtxLogger(h.logger, span)
88
89 var request requests.MessageSend
90 if err := c.Bind().Body(&request); err != nil {
91 msg := fmt.Sprintf("cannot marshall [%s] into %T", c.Body(), request)
92 ctxLogger.Warn(stacktrace.Propagate(err, msg))
93 return h.responseBadRequest(c, err)
94 }
95
96 if errors := h.validator.ValidateMessageSend(ctx, h.userIDFomContext(c), request.Sanitize()); len(errors) != 0 {
97 msg := fmt.Sprintf("validation errors [%s], while sending payload [%s]", spew.Sdump(errors), c.Body())
98 ctxLogger.Warn(stacktrace.NewError(msg))
99 return h.responseUnprocessableEntity(c, errors, "validation errors while sending message")
100 }
101
102 if msg := h.billingService.IsEntitled(ctx, h.userIDFomContext(c)); msg != nil {
103 ctxLogger.Warn(stacktrace.NewError(fmt.Sprintf("user with ID [%s] can't send a message", h.userIDFomContext(c))))
104 return h.responsePaymentRequired(c, *msg)
105 }
106
107 message, err := h.service.SendMessage(ctx, request.ToMessageSendParams(h.userIDFomContext(c), c.OriginalURL()))
108 if err != nil {
109 msg := fmt.Sprintf("cannot send message with paylod [%s]", c.Body())
110 ctxLogger.Error(stacktrace.Propagate(err, msg))
111 return h.responseInternalServerError(c)
112 }
113
114 return h.responseOK(c, "message added to queue", message)
115}
116
117// BulkSend a bulk entities.Message
118// @Summary Send bulk SMS messages

Callers

nothing calls this directly

Calls 15

SanitizeMethod · 0.95
ToMessageSendParamsMethod · 0.95
responseBadRequestMethod · 0.80
ValidateMessageSendMethod · 0.80
userIDFomContextMethod · 0.80
SendMessageMethod · 0.80
responseOKMethod · 0.80
StartFromFiberCtxMethod · 0.65
CtxLoggerMethod · 0.65

Tested by

no test coverage detected