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

Method Index

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

Index returns the phones of a user @Summary Get phones of a user @Description Get list of phones which a user has registered on the http sms application @Security ApiKeyAuth @Tags Phones @Accept json @Produce json @Param skip query int false "number of heartbeats

(c fiber.Ctx)

Source from the content-addressed store, hash-verified

67// @Failure 500 {object} responses.InternalServerError
68// @Router /phones [get]
69func (h *PhoneHandler) 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.PhoneIndex
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 phones [%+#v]", spew.Sdump(errors), request)
84 ctxLogger.Warn(stacktrace.NewError(msg))
85 return h.responseUnprocessableEntity(c, errors, "validation errors while fetching phones")
86 }
87
88 phones, err := h.service.Index(ctx, h.userFromContext(c), request.ToIndexParams())
89 if err != nil {
90 msg := fmt.Sprintf("cannot index phones 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(*phones), h.pluralize("phone", len(*phones))), phones)
96}
97
98// Upsert a phone
99// @Summary Upsert Phone

Callers

nothing calls this directly

Calls 14

SanitizeMethod · 0.95
ToIndexParamsMethod · 0.95
responseBadRequestMethod · 0.80
userFromContextMethod · 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