UsageHistory returns the usage history of a user @Summary Get billing usage history. @Description Get billing usage records of sent and received messages for a user in the past. It will be sorted by timestamp in descending order. @Security ApiKeyAuth @Tags Billing @Accept json @
(c fiber.Ctx)
| 58 | // @Failure 500 {object} responses.InternalServerError |
| 59 | // @Router /billing/usage-history [get] |
| 60 | func (h *BillingHandler) UsageHistory(c fiber.Ctx) error { |
| 61 | ctx, span := h.tracer.StartFromFiberCtx(c) |
| 62 | defer span.End() |
| 63 | |
| 64 | ctxLogger := h.tracer.CtxLogger(h.logger, span) |
| 65 | |
| 66 | var request requests.BillingUsageHistory |
| 67 | if err := c.Bind().Query(&request); err != nil { |
| 68 | msg := fmt.Sprintf("cannot marshall params [%s] into %T", c.Body(), request) |
| 69 | ctxLogger.Warn(stacktrace.Propagate(err, msg)) |
| 70 | return h.responseBadRequest(c, err) |
| 71 | } |
| 72 | |
| 73 | if errors := h.validator.ValidateHistory(ctx, request.Sanitize()); len(errors) != 0 { |
| 74 | msg := fmt.Sprintf("validation errors [%s], while fetching heartbeats [%+#v]", spew.Sdump(errors), request) |
| 75 | ctxLogger.Warn(stacktrace.NewError(msg)) |
| 76 | return h.responseUnprocessableEntity(c, errors, "validation errors while fetching usage history") |
| 77 | } |
| 78 | |
| 79 | heartbeats, err := h.service.GetUsageHistory(ctx, h.userIDFomContext(c), request.ToIndexParams()) |
| 80 | if err != nil { |
| 81 | msg := fmt.Sprintf("cannot get billing usage history with params [%+#v]", request) |
| 82 | ctxLogger.Error(stacktrace.Propagate(err, msg)) |
| 83 | return h.responseInternalServerError(c) |
| 84 | } |
| 85 | |
| 86 | return h.responseOK(c, fmt.Sprintf("fetched %d billing usage %s", len(*heartbeats), h.pluralize("record", len(*heartbeats))), heartbeats) |
| 87 | } |
| 88 | |
| 89 | // Usage returns the current usage history of a user |
| 90 | // @Summary Get Billing Usage. |
nothing calls this directly
no test coverage detected