CreateIdentity creates a new identity record in the system. It binds the incoming JSON request to an Identity object, validates it, and then creates the identity record. If any errors occur during validation or creation, it responds with an appropriate error message. Parameters: - c: The Gin contex
(c *gin.Context)
| 37 | // - 400 Bad Request: If there's an error in binding JSON or creating the identity. |
| 38 | // - 201 Created: If the identity is successfully created. |
| 39 | func (a Api) CreateIdentity(c *gin.Context) { |
| 40 | var identity model.Identity |
| 41 | if err := c.ShouldBindJSON(&identity); err != nil { |
| 42 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 43 | return |
| 44 | } |
| 45 | |
| 46 | resp, err := a.ledgerforge.CreateIdentity(identity) |
| 47 | if err != nil { |
| 48 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 49 | return |
| 50 | } |
| 51 | |
| 52 | c.JSON(http.StatusCreated, resp) |
| 53 | } |
| 54 | |
| 55 | // GetIdentity retrieves an identity record by its ID. |
| 56 | // It extracts the ID from the route parameters and fetches the identity record. |
nothing calls this directly
no test coverage detected