@Summary Store phone API key @Description Creates a new phone API key which can be used to log in to the httpSMS app on your Android phone @Security ApiKeyAuth @Tags PhoneAPIKeys @Accept json @Produce json @Param payload body requests.PhoneAPIKeyStoreRequest tr
(c fiber.Ctx)
| 108 | // @Failure 500 {object} responses.InternalServerError |
| 109 | // @Router /phone-api-keys [post] |
| 110 | func (h *PhoneAPIKeyHandler) store(c fiber.Ctx) error { |
| 111 | ctx, span, ctxLogger := h.tracer.StartFromFiberCtxWithLogger(c, h.logger) |
| 112 | defer span.End() |
| 113 | |
| 114 | userID := h.userIDFomContext(c) |
| 115 | |
| 116 | result, err := h.entitlementService.Check(ctx, userID, entities.EntityNamePhoneAPIKey, func() (int, error) { |
| 117 | return h.service.CountByUser(ctx, userID) |
| 118 | }) |
| 119 | if err != nil { |
| 120 | ctxLogger.Error(stacktrace.Propagate(err, fmt.Sprintf("cannot check entitlement for phone API keys for user [%s]", userID))) |
| 121 | return h.responseInternalServerError(c) |
| 122 | } |
| 123 | if !result.Allowed { |
| 124 | return h.responsePaymentRequired(c, result.Message) |
| 125 | } |
| 126 | |
| 127 | var request requests.PhoneAPIKeyStoreRequest |
| 128 | if err := c.Bind().Body(&request); err != nil { |
| 129 | msg := fmt.Sprintf("cannot marshall params [%s] into %T", c.OriginalURL(), request) |
| 130 | ctxLogger.Warn(stacktrace.Propagate(err, msg)) |
| 131 | return h.responseBadRequest(c, err) |
| 132 | } |
| 133 | |
| 134 | if errors := h.validator.ValidateStore(ctx, request.Sanitize()); len(errors) != 0 { |
| 135 | msg := fmt.Sprintf("validation errors [%s], while updating phones [%+#v]", spew.Sdump(errors), request) |
| 136 | ctxLogger.Warn(stacktrace.NewError(msg)) |
| 137 | return h.responseUnprocessableEntity(c, errors, "validation errors while updating phones") |
| 138 | } |
| 139 | |
| 140 | phoneAPIKey, err := h.service.Create(ctx, h.userFromContext(c), request.Name) |
| 141 | if err != nil { |
| 142 | msg := fmt.Sprintf("cannot update phones with params [%+#v]", request) |
| 143 | ctxLogger.Error(stacktrace.Propagate(err, msg)) |
| 144 | return h.responseInternalServerError(c) |
| 145 | } |
| 146 | |
| 147 | return h.responseOK(c, "phone API key created successfully", phoneAPIKey) |
| 148 | } |
| 149 | |
| 150 | // @Summary Delete a phone API key from the database. |
| 151 | // @Description Delete a phone API Key from the database and cannot be used for authentication anymore. |
nothing calls this directly
no test coverage detected