CreateAPIKey creates a new API key for the authenticated user Parameters: - c: The Gin context containing the request and response Responses: - 400 Bad Request: If there's an error in the request body - 201 Created: If the API key is successfully created
(c *gin.Context)
| 17 | // - 400 Bad Request: If there's an error in the request body |
| 18 | // - 201 Created: If the API key is successfully created |
| 19 | func (a Api) CreateAPIKey(c *gin.Context) { |
| 20 | var req model.CreateAPIKeyRequest |
| 21 | if err := c.ShouldBindJSON(&req); err != nil { |
| 22 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 23 | return |
| 24 | } |
| 25 | |
| 26 | apiKey, err := a.ledgerforge.CreateAPIKey(c.Request.Context(), req.Name, req.Owner, req.Scopes, req.ExpiresAt) |
| 27 | if err != nil { |
| 28 | c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) |
| 29 | return |
| 30 | } |
| 31 | |
| 32 | c.JSON(http.StatusCreated, apiKey) |
| 33 | } |
| 34 | |
| 35 | // ListAPIKeys lists all API keys for the authenticated user |
| 36 | // |
nothing calls this directly
no test coverage detected