@Summary Create a new api key @Description Create a new api key @Tags framework/api-keys @Accept application/json @Param apikey body models.ApiInputApiKey true "json" @Success 200 {object} models.ApiOutputApiKey @Failure 400 {string} errcode.Error "Bad Request" @Failure 500 {string} errcode.Error
(c *gin.Context)
| 122 | // @Failure 500 {string} errcode.Error "Internal Error" |
| 123 | // @Router /api-keys [post] |
| 124 | func PostApiKey(c *gin.Context) { |
| 125 | apiKeyInput := &models.ApiInputApiKey{} |
| 126 | err := c.ShouldBind(apiKeyInput) |
| 127 | if err != nil { |
| 128 | shared.ApiOutputError(c, errors.BadInput.Wrap(err, shared.BadRequestBody)) |
| 129 | return |
| 130 | } |
| 131 | user, exist := shared.GetUser(c) |
| 132 | if !exist { |
| 133 | logruslog.Global.Warn(nil, "user doesn't exist") |
| 134 | } |
| 135 | apiKeyOutput, err := services.CreateApiKey(user, apiKeyInput) |
| 136 | if err != nil { |
| 137 | shared.ApiOutputError(c, errors.Default.Wrap(err, "error creating api key")) |
| 138 | return |
| 139 | } |
| 140 | |
| 141 | shared.ApiOutputSuccess(c, apiKeyOutput, http.StatusCreated) |
| 142 | } |