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

Method Index

api/pkg/handlers/message_thread_handler.go:66–95  ·  view source on GitHub ↗

Index returns message threads for a phone number @Summary Get message threads for a phone number @Description Get list of contacts which a phone number has communicated with (threads). It will be sorted by timestamp in descending order. @Security ApiKeyAuth @Tags MessageThreads @Accep

(c fiber.Ctx)

Source from the content-addressed store, hash-verified

64// @Failure 500 {object} responses.InternalServerError
65// @Router /message-threads [get]
66func (h *MessageThreadHandler) Index(c fiber.Ctx) error {
67 ctx, span := h.tracer.StartFromFiberCtx(c)
68 defer span.End()
69
70 ctxLogger := h.tracer.CtxLogger(h.logger, span)
71
72 ctxLogger.Info(c.OriginalURL())
73
74 var request requests.MessageThreadIndex
75 if err := c.Bind().Query(&request); err != nil {
76 msg := fmt.Sprintf("cannot marshall params [%s] into %T", c.OriginalURL(), request)
77 ctxLogger.Warn(stacktrace.Propagate(err, msg))
78 return h.responseBadRequest(c, err)
79 }
80
81 if errors := h.validator.ValidateMessageThreadIndex(ctx, request.Sanitize()); len(errors) != 0 {
82 msg := fmt.Sprintf("validation errors [%s], while fetching message threads [%+#v]", spew.Sdump(errors), request)
83 ctxLogger.Warn(stacktrace.NewError(msg))
84 return h.responseUnprocessableEntity(c, errors, "validation errors while fetching message threads")
85 }
86
87 threads, err := h.service.GetThreads(ctx, request.ToGetParams(h.userIDFomContext(c)))
88 if err != nil {
89 msg := fmt.Sprintf("cannot get message threads with params [%+#v]", request)
90 ctxLogger.Error(stacktrace.Propagate(err, msg))
91 return h.responseInternalServerError(c)
92 }
93
94 return h.responseOK(c, fmt.Sprintf("fetched %d message %s", len(*threads), h.pluralize("thread", len(*threads))), threads)
95}
96
97// Update an entities.MessageThread
98// @Summary Update a message thread

Callers

nothing calls this directly

Calls 15

SanitizeMethod · 0.95
ToGetParamsMethod · 0.95
responseBadRequestMethod · 0.80
GetThreadsMethod · 0.80
userIDFomContextMethod · 0.80
responseOKMethod · 0.80
pluralizeMethod · 0.80
StartFromFiberCtxMethod · 0.65
CtxLoggerMethod · 0.65

Tested by

no test coverage detected