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)
| 549 | // @Failure 500 {object} responses.InternalServerError |
| 550 | // @Router /messages/search [get] |
| 551 | func (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 | } |
nothing calls this directly
no test coverage detected