DetokenizeIdentity detokenizes multiple fields in an identity. It binds the incoming JSON request containing the list of fields to detokenize, detokenizes each field, and responds with the original values. Parameters: - c: The Gin context containing the request and response. Responses: - 400 Bad R
(c *gin.Context)
| 353 | // - 400 Bad Request: If the ID is missing, there's an error binding JSON, or there's an error detokenizing fields. |
| 354 | // - 200 OK: If the fields are successfully detokenized, returning the original values. |
| 355 | func (a Api) DetokenizeIdentity(c *gin.Context) { |
| 356 | id, passed := c.Params.Get("id") |
| 357 | if !passed { |
| 358 | c.JSON(http.StatusBadRequest, gin.H{"error": "identity ID is required"}) |
| 359 | return |
| 360 | } |
| 361 | |
| 362 | var request apimodel.DetokenizeRequest |
| 363 | if err := c.ShouldBindJSON(&request); err != nil { |
| 364 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 365 | return |
| 366 | } |
| 367 | |
| 368 | // If no specific fields are provided, detokenize all tokenized fields |
| 369 | if len(request.Fields) == 0 { |
| 370 | detokenizedFields, err := a.ledgerforge.DetokenizeIdentity(id) |
| 371 | if err != nil { |
| 372 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 373 | return |
| 374 | } |
| 375 | |
| 376 | c.JSON(http.StatusOK, gin.H{"fields": detokenizedFields}) |
| 377 | return |
| 378 | } |
| 379 | |
| 380 | // Detokenize specific fields |
| 381 | result := make(map[string]string) |
| 382 | for _, field := range request.Fields { |
| 383 | value, err := a.ledgerforge.DetokenizeIdentityField(id, field) |
| 384 | if err != nil { |
| 385 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 386 | return |
| 387 | } |
| 388 | result[field] = value |
| 389 | } |
| 390 | |
| 391 | c.JSON(http.StatusOK, gin.H{"fields": result}) |
| 392 | } |
| 393 | |
| 394 | // GetTokenizedFields returns a list of fields that are currently tokenized for an identity. |
| 395 | // |
nothing calls this directly
no test coverage detected