-
Notifications
You must be signed in to change notification settings - Fork 927
/
organizations.go
47 lines (38 loc) · 1.21 KB
/
organizations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package resources
import "github.com/cloudfoundry/cli/cf/models"
type OrganizationResource struct {
Resource
Entity OrganizationEntity
}
type OrganizationEntity struct {
Name string
QuotaDefinition QuotaResource `json:"quota_definition"`
Spaces []SpaceResource
Domains []DomainResource
SpaceQuotas []SpaceQuotaResource `json:"space_quota_definitions"`
}
func (resource OrganizationResource) ToFields() (fields models.OrganizationFields) {
fields.Name = resource.Entity.Name
fields.Guid = resource.Metadata.Guid
fields.QuotaDefinition = resource.Entity.QuotaDefinition.ToFields()
return
}
func (resource OrganizationResource) ToModel() (org models.Organization) {
org.OrganizationFields = resource.ToFields()
spaces := []models.SpaceFields{}
for _, s := range resource.Entity.Spaces {
spaces = append(spaces, s.ToFields())
}
org.Spaces = spaces
domains := []models.DomainFields{}
for _, d := range resource.Entity.Domains {
domains = append(domains, d.ToFields())
}
org.Domains = domains
spaceQuotas := []models.SpaceQuota{}
for _, sq := range resource.Entity.SpaceQuotas {
spaceQuotas = append(spaceQuotas, sq.ToModel())
}
org.SpaceQuotas = spaceQuotas
return
}