CreateMatchingRule creates a new matching rule based on the provided rule details. It returns the created matching rule. Parameters: - c: The Gin context containing the request and response. Responses: - 400 Bad Request: If the request body is invalid. - 500 Internal Server Error: If there is an e
(c *gin.Context)
| 189 | // - 500 Internal Server Error: If there is an error creating the matching rule. |
| 190 | // - 201 Created: If the matching rule is successfully created. |
| 191 | func (a Api) CreateMatchingRule(c *gin.Context) { |
| 192 | var rule model.MatchingRule |
| 193 | if err := c.ShouldBindJSON(&rule); err != nil { |
| 194 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 195 | return |
| 196 | } |
| 197 | |
| 198 | createdRule, err := a.ledgerforge.CreateMatchingRule(c.Request.Context(), rule) |
| 199 | if err != nil { |
| 200 | logrus.Error(err) |
| 201 | c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to create matching rule"}) |
| 202 | return |
| 203 | } |
| 204 | |
| 205 | c.JSON(http.StatusCreated, createdRule) |
| 206 | } |
| 207 | |
| 208 | // UpdateMatchingRule updates an existing matching rule identified by its ID. |
| 209 | // It returns the updated matching rule. |