Skip to content

Commit

Permalink
add metadata model
Browse files Browse the repository at this point in the history
  • Loading branch information
Toktar committed Jul 18, 2022
1 parent d73873a commit 5035c9c
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions types/did_doc_metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package types

import (
cheqd "github.com/cheqd/cheqd-node/x/cheqd/types"
resource "github.com/cheqd/cheqd-node/x/resource/types"
)

type ResolutionDidDocMetadata struct {
Created string `json:"created,omitempty"`
Updated string `json:"updated,omitempty"`
Deactivated bool `json:"deactivated,omitempty"`
VersionId string `json:"versionId,omitempty"`
Resources []ResourcePreview `json:"resources,omitempty"`
}

type ResourcePreview struct {
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
ResourceType string `json:"resourceType,omitempty"`
MediaType string `json:"mediaType,omitempty"`
Created string `json:"created,omitempty"`
}


func NewResolutionDidDocMetadata(metadata cheqd.Metadata, resources []*resource.ResourceHeader) ResolutionDidDocMetadata {
newMetadata := ResolutionDidDocMetadata{
metadata.Created,
metadata.Updated,
metadata.Deactivated,
metadata.VersionId,
[]ResourcePreview(nil),
}
if metadata.Resources == nil {
return newMetadata
}
for _, r := range resources {
resourcePreview := ResourcePreview {
r.Id,
r.Name,
r.ResourceType,
r.MediaType,
r.Created,
}
newMetadata.Resources = append(newMetadata.Resources, resourcePreview)
}
return newMetadata
}

func TransformToFragmentMetadata(metadata ResolutionDidDocMetadata) ResolutionDidDocMetadata {
metadata.Resources = nil
return metadata
}



0 comments on commit 5035c9c

Please sign in to comment.