@@ -2,21 +2,37 @@ package issuer
22
33import (
44 "context"
5- "github.com/nuts-foundation/go-did/vc"
5+ "encoding/json"
6+ "strings"
7+ "time"
8+
69 "github.com/nuts-foundation/go-nuts-client/nuts"
710 "github.com/nuts-foundation/go-nuts-client/nuts/vcr"
811 "github.com/nuts-foundation/nuts-admin/identity"
912 "github.com/nuts-foundation/nuts-admin/model"
10- "strings"
1113)
1214
1315type Service struct {
1416 IdentityService identity.Service
1517 VCRClient * vcr.Client
1618}
1719
18- func (s Service ) GetIssuedCredentials (ctx context.Context , issuer string , credentialTypes []string ) ([]model.VerifiableCredential , error ) {
19- var result []vc.VerifiableCredential
20+ func (s Service ) GetIssuedCredentials (ctx context.Context , issuer string , credentialTypes []string ) ([]model.IssuedCredential , error ) {
21+ // Get all identities for lookup
22+ identities , err := s .IdentityService .List (ctx )
23+ if err != nil {
24+ return nil , err
25+ }
26+
27+ // Create a map of DID to subject name
28+ didToSubject := make (map [string ]string )
29+ for _ , ident := range identities {
30+ for _ , did := range ident .DIDs {
31+ didToSubject [did ] = ident .Subject
32+ }
33+ }
34+
35+ var result []model.IssuedCredential
2036 for _ , credentialType := range credentialTypes {
2137 credentialType = strings .TrimSpace (credentialType )
2238 if credentialType == "" {
@@ -31,8 +47,21 @@ func (s Service) GetIssuedCredentials(ctx context.Context, issuer string, creden
3147 return nil , err
3248 }
3349 for _ , searchResult := range response .JSON200 .VerifiableCredentials {
34- result = append (result , searchResult .VerifiableCredential )
50+ data , _ := json .Marshal (searchResult )
51+ println (string (data ))
52+ currentResult := model.IssuedCredential {
53+ VerifiableCredential : model .ToModel (searchResult .VerifiableCredential ),
54+ IssuerSubject : didToSubject [searchResult .VerifiableCredential .Issuer .String ()],
55+ }
56+ if searchResult .Revocation != nil {
57+ currentResult .Status = "revoked"
58+ } else if searchResult .VerifiableCredential .ExpirationDate != nil && searchResult .VerifiableCredential .ExpirationDate .Before (time .Now ()) {
59+ currentResult .Status = "expired"
60+ } else {
61+ currentResult .Status = "active"
62+ }
63+ result = append (result , currentResult )
3564 }
3665 }
37- return model . ToModel ( result ) , nil
66+ return result , nil
3867}
0 commit comments