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

Method Search

api/pkg/handlers/message_handler.go:551–579  ·  view source on GitHub ↗

Search returns a filtered list of messages of a user @Summary Search all messages of a user @Description This returns the list of all messages based on the filter criteria including missed calls @Security ApiKeyAuth @Tags Messages @Accept json @Produce json @Param to

(c fiber.Ctx)

Source from the content-addressed store, hash-verified

549// @Failure 500 {object} responses.InternalServerError
550// @Router /messages/search [get]
551func (h *MessageHandler) Search(c fiber.Ctx) error {
552 ctx, span, ctxLogger := h.tracer.StartFromFiberCtxWithLogger(c, h.logger)
553 defer span.End()
554
555 var request requests.MessageSearch
556 if err := c.Bind().Query(&request); err != nil {
557 msg := fmt.Sprintf("cannot marshall params in [%s] into [%T]", c.OriginalURL(), request)
558 ctxLogger.Warn(stacktrace.Propagate(err, msg))
559 return h.responseBadRequest(c, err)
560 }
561
562 request.IPAddress = c.IP()
563 request.Token = c.Get("token")
564
565 if errors := h.validator.ValidateMessageSearch(ctx, request.Sanitize()); len(errors) != 0 {
566 msg := fmt.Sprintf("validation errors [%s], while searching messages [%+#v]", spew.Sdump(errors), request)
567 ctxLogger.Warn(stacktrace.NewError(msg))
568 return h.responseUnprocessableEntity(c, errors, "validation errors while searching messages")
569 }
570
571 messages, err := h.service.SearchMessages(ctx, request.ToSearchParams(h.userIDFomContext(c)))
572 if err != nil {
573 msg := fmt.Sprintf("cannot search messages with params [%+#v]", request)
574 ctxLogger.Error(stacktrace.Propagate(err, msg))
575 return h.responseInternalServerError(c)
576 }
577
578 return h.responseOK(c, fmt.Sprintf("found %d %s", len(messages), h.pluralize("message", len(messages))), messages)
579}

Callers

nothing calls this directly

Calls 14

SanitizeMethod · 0.95
ToSearchParamsMethod · 0.95
responseBadRequestMethod · 0.80
ValidateMessageSearchMethod · 0.80
SearchMessagesMethod · 0.80
userIDFomContextMethod · 0.80
responseOKMethod · 0.80
pluralizeMethod · 0.80
WarnMethod · 0.65

Tested by

no test coverage detected