|
| 1 | +package dto |
| 2 | + |
| 3 | +// TemplateListOptions represents options for listing templates |
| 4 | +type TemplateListOptions struct { |
| 5 | + SearchTerm string `json:"search_term,omitempty"` |
| 6 | + TemplateListType string `json:"template_list_type,omitempty"` |
| 7 | + PaginationOptions |
| 8 | +} |
| 9 | + |
| 10 | +// TemplateMetadataSummaryResponse represents a template metadata summary |
| 11 | +type TemplateMetadataSummaryResponse struct { |
| 12 | + Account string `json:"account,omitempty"` |
| 13 | + Org string `json:"org,omitempty"` |
| 14 | + Project string `json:"project,omitempty"` |
| 15 | + Identifier string `json:"identifier,omitempty"` |
| 16 | + Name string `json:"name,omitempty"` |
| 17 | + Description string `json:"description,omitempty"` |
| 18 | + Tags map[string]string `json:"tags,omitempty"` |
| 19 | + VersionLabel string `json:"version_label,omitempty"` |
| 20 | + EntityType string `json:"entity_type,omitempty"` |
| 21 | + ChildType string `json:"child_type,omitempty"` |
| 22 | + Scope string `json:"scope,omitempty"` |
| 23 | + Version int64 `json:"version,omitempty"` |
| 24 | + GitDetails *EntityGitDetails `json:"git_details,omitempty"` |
| 25 | + Updated int64 `json:"updated,omitempty"` |
| 26 | + StoreType string `json:"store_type,omitempty"` |
| 27 | + ConnectorRef string `json:"connector_ref,omitempty"` |
| 28 | + StableTemplate bool `json:"stable_template,omitempty"` |
| 29 | +} |
| 30 | + |
| 31 | +// EntityGitDetails represents git details for an entity |
| 32 | +type EntityGitDetails struct { |
| 33 | + ObjectID string `json:"object_id,omitempty"` |
| 34 | + BranchName string `json:"branch_name,omitempty"` |
| 35 | + FilePath string `json:"file_path,omitempty"` |
| 36 | + RepoName string `json:"repo_name,omitempty"` |
| 37 | + CommitID string `json:"commit_id,omitempty"` |
| 38 | + FileURL string `json:"file_url,omitempty"` |
| 39 | + RepoURL string `json:"repo_url,omitempty"` |
| 40 | +} |
| 41 | + |
| 42 | +// TemplateMetaDataList represents a list of template metadata |
| 43 | +type TemplateMetaDataList []TemplateMetadataSummaryResponse |
| 44 | + |
| 45 | +// TemplateOutput is a custom struct for template output with numeric timestamps |
| 46 | +type TemplateOutput struct { |
| 47 | + Account string `json:"account,omitempty"` |
| 48 | + Org string `json:"org,omitempty"` |
| 49 | + Project string `json:"project,omitempty"` |
| 50 | + Identifier string `json:"identifier,omitempty"` |
| 51 | + Name string `json:"name,omitempty"` |
| 52 | + Description string `json:"description,omitempty"` |
| 53 | + Tags map[string]string `json:"tags,omitempty"` |
| 54 | + VersionLabel string `json:"version_label,omitempty"` |
| 55 | + EntityType string `json:"entity_type,omitempty"` |
| 56 | + ChildType string `json:"child_type,omitempty"` |
| 57 | + Scope string `json:"scope,omitempty"` |
| 58 | + Version int64 `json:"version,omitempty"` |
| 59 | + GitDetails *EntityGitDetails `json:"git_details,omitempty"` |
| 60 | + Updated string `json:"updated,omitempty"` |
| 61 | + StoreType string `json:"store_type,omitempty"` |
| 62 | + ConnectorRef string `json:"connector_ref,omitempty"` |
| 63 | + StableTemplate bool `json:"stable_template,omitempty"` |
| 64 | +} |
| 65 | + |
| 66 | +// TemplateListOutput is a custom struct for template list output with numeric timestamps |
| 67 | +type TemplateListOutput struct { |
| 68 | + Templates []TemplateOutput `json:"templates"` |
| 69 | +} |
| 70 | + |
| 71 | +// ToTemplateResponse processes the raw API response and adds human-readable timestamps |
| 72 | +func ToTemplateResponse(data *TemplateMetaDataList) *TemplateListOutput { |
| 73 | + if data == nil { |
| 74 | + return &TemplateListOutput{Templates: []TemplateOutput{}} |
| 75 | + } |
| 76 | + |
| 77 | + result := &TemplateListOutput{ |
| 78 | + Templates: make([]TemplateOutput, len(*data)), |
| 79 | + } |
| 80 | + |
| 81 | + for i, template := range *data { |
| 82 | + // Copy all fields |
| 83 | + output := TemplateOutput{ |
| 84 | + Account: template.Account, |
| 85 | + Org: template.Org, |
| 86 | + Project: template.Project, |
| 87 | + Identifier: template.Identifier, |
| 88 | + Name: template.Name, |
| 89 | + Description: template.Description, |
| 90 | + Tags: template.Tags, |
| 91 | + VersionLabel: template.VersionLabel, |
| 92 | + EntityType: template.EntityType, |
| 93 | + ChildType: template.ChildType, |
| 94 | + Scope: template.Scope, |
| 95 | + Version: template.Version, |
| 96 | + GitDetails: template.GitDetails, |
| 97 | + Updated: FormatUnixMillisToMMDDYYYY(template.Updated), |
| 98 | + StoreType: template.StoreType, |
| 99 | + ConnectorRef: template.ConnectorRef, |
| 100 | + StableTemplate: template.StableTemplate, |
| 101 | + } |
| 102 | + |
| 103 | + result.Templates[i] = output |
| 104 | + } |
| 105 | + |
| 106 | + return result |
| 107 | +} |
0 commit comments