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

Method GetOutstanding

api/pkg/handlers/message_handler.go:193–227  ·  view source on GitHub ↗

GetOutstanding returns an entities.Message which is still to be sent by the mobile phone @Summary Get an outstanding message @Description Get an outstanding message to be sent by an android phone @Security ApiKeyAuth @Tags Messages @Accept json @Produce json @Param m

(c fiber.Ctx)

Source from the content-addressed store, hash-verified

191// @Failure 500 {object} responses.InternalServerError
192// @Router /messages/outstanding [get]
193func (h *MessageHandler) GetOutstanding(c fiber.Ctx) error {
194 ctx, span := h.tracer.StartFromFiberCtx(c)
195 defer span.End()
196
197 timestamp := time.Now().UTC()
198 ctxLogger := h.tracer.CtxLogger(h.logger, span)
199
200 var request requests.MessageOutstanding
201 if err := c.Bind().Query(&request); err != nil {
202 msg := fmt.Sprintf("cannot marshall params [%s] into %T", c.OriginalURL(), request)
203 ctxLogger.Warn(stacktrace.Propagate(err, msg))
204 return h.responseBadRequest(c, err)
205 }
206
207 if errors := h.validator.ValidateMessageOutstanding(ctx, request.Sanitize()); len(errors) != 0 {
208 msg := fmt.Sprintf("validation errors [%s], while fetching outstanding messages [%s]", spew.Sdump(errors), c.OriginalURL())
209 ctxLogger.Warn(stacktrace.NewError(msg))
210 return h.responseUnprocessableEntity(c, errors, "validation errors while fetching outstanding messages")
211 }
212
213 message, err := h.service.GetOutstanding(ctx, request.ToGetOutstandingParams(c.Path(), h.userFromContext(c), timestamp))
214 if stacktrace.GetCode(err) == repositories.ErrCodeNotFound {
215 msg := fmt.Sprintf("Cannot find outstanding message with ID [%s]", request.MessageID)
216 ctxLogger.Warn(stacktrace.Propagate(err, msg))
217 return h.responseNotFound(c, msg)
218 }
219
220 if err != nil {
221 msg := fmt.Sprintf("cannot get outstanding messgage with ID [%s]", request.MessageID)
222 ctxLogger.Error(stacktrace.Propagate(err, msg))
223 return h.responseInternalServerError(c)
224 }
225
226 return h.responseOK(c, "outstanding message fetched successfully", message)
227}
228
229// Index returns messages sent between 2 phone numbers
230// @Summary Get messages which are sent between 2 phone numbers

Callers

nothing calls this directly

Calls 14

SanitizeMethod · 0.95
responseBadRequestMethod · 0.80
userFromContextMethod · 0.80
responseNotFoundMethod · 0.80
responseOKMethod · 0.80
StartFromFiberCtxMethod · 0.65
CtxLoggerMethod · 0.65
WarnMethod · 0.65

Tested by

no test coverage detected