GetTokenizedFields returns a list of fields that are currently tokenized for an identity. Parameters: - c: The Gin context containing the request and response. Responses: - 400 Bad Request: If the ID is missing or there's an error retrieving the identity. - 200 OK: Returns the list of tokenized fi
(c *gin.Context)
| 400 | // - 400 Bad Request: If the ID is missing or there's an error retrieving the identity. |
| 401 | // - 200 OK: Returns the list of tokenized fields. |
| 402 | func (a Api) GetTokenizedFields(c *gin.Context) { |
| 403 | id, passed := c.Params.Get("id") |
| 404 | if !passed { |
| 405 | c.JSON(http.StatusBadRequest, gin.H{"error": "identity ID is required"}) |
| 406 | return |
| 407 | } |
| 408 | |
| 409 | identity, err := a.ledgerforge.GetIdentity(id) |
| 410 | if err != nil { |
| 411 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 412 | return |
| 413 | } |
| 414 | |
| 415 | tokenizedFields := make([]string, 0) |
| 416 | |
| 417 | // Debug the metadata structure |
| 418 | if identity.MetaData != nil { |
| 419 | tokenizedFieldsRaw, exists := identity.MetaData["tokenized_fields"] |
| 420 | if exists { |
| 421 | // Try map[string]bool first |
| 422 | if tokenizedMap, ok := tokenizedFieldsRaw.(map[string]bool); ok { |
| 423 | for field, isTokenized := range tokenizedMap { |
| 424 | if isTokenized { |
| 425 | tokenizedFields = append(tokenizedFields, field) |
| 426 | } |
| 427 | } |
| 428 | } else if tokenizedMap, ok := tokenizedFieldsRaw.(map[string]interface{}); ok { |
| 429 | // Try map[string]interface{} with boolean values |
| 430 | for field, val := range tokenizedMap { |
| 431 | if boolVal, ok := val.(bool); ok && boolVal { |
| 432 | tokenizedFields = append(tokenizedFields, field) |
| 433 | } |
| 434 | } |
| 435 | } else { |
| 436 | c.JSON(http.StatusOK, gin.H{ |
| 437 | "tokenized_fields": tokenizedFields, |
| 438 | "debug_info": gin.H{ |
| 439 | "has_metadata": true, |
| 440 | "tokenized_field_type": fmt.Sprintf("%T", tokenizedFieldsRaw), |
| 441 | "raw_metadata": identity.MetaData, |
| 442 | }, |
| 443 | }) |
| 444 | return |
| 445 | } |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | c.JSON(http.StatusOK, gin.H{"tokenized_fields": tokenizedFields}) |
| 450 | } |
nothing calls this directly
no test coverage detected