GetAllIdentities retrieves all identity records in the system. It fetches the identity records and responds with the list of identities. Supports advanced filtering via query parameters in the format: field_operator=value Example filters: - first_name_eq=John - category_in=individual,corporate - cre
(c *gin.Context)
| 156 | // - 400 Bad Request: If there's an error retrieving the identities or invalid filters. |
| 157 | // - 200 OK: If the identities are successfully retrieved. |
| 158 | func (a Api) GetAllIdentities(c *gin.Context) { |
| 159 | // Extract limit and offset from query parameters |
| 160 | limitStr := c.DefaultQuery("limit", "20") |
| 161 | offsetStr := c.DefaultQuery("offset", "0") |
| 162 | |
| 163 | limitInt, err := strconv.Atoi(limitStr) |
| 164 | if err != nil || limitInt <= 0 { |
| 165 | limitInt = 20 |
| 166 | } |
| 167 | |
| 168 | offsetInt, err := strconv.Atoi(offsetStr) |
| 169 | if err != nil || offsetInt < 0 { |
| 170 | offsetInt = 0 |
| 171 | } |
| 172 | |
| 173 | // Check if advanced filters are present |
| 174 | if HasFilters(c) { |
| 175 | filters, parseErrors := ParseFiltersFromContext(c, nil) |
| 176 | if len(parseErrors) > 0 { |
| 177 | c.JSON(http.StatusBadRequest, gin.H{"errors": parseErrors}) |
| 178 | return |
| 179 | } |
| 180 | |
| 181 | // Use the new filter method |
| 182 | resp, err := a.ledgerforge.GetAllIdentitiesWithFilter(c.Request.Context(), filters, limitInt, offsetInt) |
| 183 | if err != nil { |
| 184 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 185 | return |
| 186 | } |
| 187 | |
| 188 | c.JSON(http.StatusOK, resp) |
| 189 | return |
| 190 | } |
| 191 | |
| 192 | // Fall back to the legacy method when no filters are present |
| 193 | identities, err := a.ledgerforge.GetAllIdentities() |
| 194 | if err != nil { |
| 195 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 196 | return |
| 197 | } |
| 198 | |
| 199 | c.JSON(http.StatusOK, identities) |
| 200 | } |
| 201 | |
| 202 | // FilterIdentities filters identities using a JSON request body. |
| 203 | // This endpoint accepts a POST request with filters specified in JSON format. |
nothing calls this directly
no test coverage detected