Store a webhook @Summary Store a webhook @Description Store a webhook for the authenticated user @Security ApiKeyAuth @Tags Webhooks @Accept json @Produce json @Param payload body requests.WebhookStore true "Payload of the webhook request" @Success 200
(c fiber.Ctx)
| 141 | // @Failure 500 {object} responses.InternalServerError |
| 142 | // @Router /webhooks [post] |
| 143 | func (h *WebhookHandler) Store(c fiber.Ctx) error { |
| 144 | ctx, span := h.tracer.StartFromFiberCtx(c) |
| 145 | defer span.End() |
| 146 | |
| 147 | ctxLogger := h.tracer.CtxLogger(h.logger, span) |
| 148 | |
| 149 | var request requests.WebhookStore |
| 150 | if err := c.Bind().Body(&request); err != nil { |
| 151 | msg := fmt.Sprintf("cannot marshall body [%s] into [%T]", c.Body(), request) |
| 152 | ctxLogger.Warn(stacktrace.Propagate(err, msg)) |
| 153 | return h.responseBadRequest(c, err) |
| 154 | } |
| 155 | |
| 156 | if errors := h.validator.ValidateStore(ctx, h.userIDFomContext(c), request.Sanitize()); len(errors) != 0 { |
| 157 | msg := fmt.Sprintf("validation errors [%s], while storing webhook [%+#v]", spew.Sdump(errors), request) |
| 158 | ctxLogger.Warn(stacktrace.NewError(msg)) |
| 159 | return h.responseUnprocessableEntity(c, errors, "validation errors while storing webhook") |
| 160 | } |
| 161 | |
| 162 | webhooks, err := h.service.Index(ctx, h.userIDFomContext(c), repositories.IndexParams{Skip: 0, Limit: 10}) |
| 163 | if err != nil { |
| 164 | ctxLogger.Error(stacktrace.Propagate(err, fmt.Sprintf("cannot index webhooks for user [%s]", h.userIDFomContext(c)))) |
| 165 | return h.responseInternalServerError(c) |
| 166 | } |
| 167 | |
| 168 | if len(webhooks) == 10 { |
| 169 | ctxLogger.Warn(stacktrace.NewError(fmt.Sprintf("user with ID [%s] wants to create more than 5 webhooks", h.userIDFomContext(c)))) |
| 170 | return h.responsePaymentRequired(c, "You can't create more than 10 webhooks contact us to upgrade to our enterprise plan.") |
| 171 | } |
| 172 | |
| 173 | webhook, err := h.service.Store(ctx, request.ToStoreParams(h.userFromContext(c))) |
| 174 | if err != nil { |
| 175 | msg := fmt.Sprintf("cannot store webhoook with params [%+#v]", request) |
| 176 | ctxLogger.Error(stacktrace.Propagate(err, msg)) |
| 177 | return h.responseInternalServerError(c) |
| 178 | } |
| 179 | |
| 180 | return h.responseCreated(c, "webhook created successfully", webhook) |
| 181 | } |
| 182 | |
| 183 | // Update an entities.Webhook |
| 184 | // @Summary Update a webhook |
nothing calls this directly
no test coverage detected