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

Method Index

api/pkg/handlers/heartbeat_handler.go:69–96  ·  view source on GitHub ↗

Index returns the heartbeats of a phone number @Summary Get heartbeats of an owner phone number @Description Get the last time a phone number requested for outstanding messages. It will be sorted by timestamp in descending order. @Security ApiKeyAuth @Tags Heartbeats @Accept jso

(c fiber.Ctx)

Source from the content-addressed store, hash-verified

67// @Failure 500 {object} responses.InternalServerError
68// @Router /heartbeats [get]
69func (h *HeartbeatHandler) Index(c fiber.Ctx) error {
70 ctx, span := h.tracer.StartFromFiberCtx(c)
71 defer span.End()
72
73 ctxLogger := h.tracer.CtxLogger(h.logger, span)
74
75 var request requests.HeartbeatIndex
76 if err := c.Bind().Query(&request); err != nil {
77 msg := fmt.Sprintf("cannot marshall params [%s] into %T", c.OriginalURL(), request)
78 ctxLogger.Warn(stacktrace.Propagate(err, msg))
79 return h.responseBadRequest(c, err)
80 }
81
82 if errors := h.validator.ValidateIndex(ctx, request.Sanitize()); len(errors) != 0 {
83 msg := fmt.Sprintf("validation errors [%s], while fetching heartbeats [%+#v]", spew.Sdump(errors), request)
84 ctxLogger.Warn(stacktrace.NewError(msg))
85 return h.responseUnprocessableEntity(c, errors, "validation errors while fetching heartbeats")
86 }
87
88 heartbeats, err := h.service.Index(ctx, h.userIDFomContext(c), request.Owner, request.ToIndexParams())
89 if err != nil {
90 msg := fmt.Sprintf("cannot get messgaes with params [%+#v]", request)
91 ctxLogger.Error(stacktrace.Propagate(err, msg))
92 return h.responseInternalServerError(c)
93 }
94
95 return h.responseOK(c, fmt.Sprintf("fetched %d %s", len(*heartbeats), h.pluralize("heartbeat", len(*heartbeats))), heartbeats)
96}
97
98// Store the heartbeat of a phone number
99// @Summary Register heartbeat of an owner phone number

Callers

nothing calls this directly

Calls 14

SanitizeMethod · 0.95
ToIndexParamsMethod · 0.95
responseBadRequestMethod · 0.80
userIDFomContextMethod · 0.80
responseOKMethod · 0.80
pluralizeMethod · 0.80
StartFromFiberCtxMethod · 0.65
CtxLoggerMethod · 0.65
WarnMethod · 0.65
IndexMethod · 0.65

Tested by

no test coverage detected