project.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package models
  2. import (
  3. "gorm.io/gorm"
  4. )
  5. // Project type that extends gorm.Model
  6. type Project struct {
  7. gorm.Model
  8. Name string `json:"name"`
  9. Roles []Role `json:"roles"`
  10. RepoClients []RepoClient `json:"repo_clients,omitempty"`
  11. ServiceAccountCandidates []ServiceAccountCandidate `json:"sa_candidates"`
  12. ServiceAccounts []ServiceAccount `json:"serviceaccounts"`
  13. }
  14. // ProjectExternal represents the Project type that is sent over REST
  15. type ProjectExternal struct {
  16. ID uint `json:"id"`
  17. Name string `json:"name"`
  18. Roles []RoleExternal `json:"roles"`
  19. RepoClients []RepoClientExternal `json:"repo_clients,omitempty"`
  20. }
  21. // Externalize generates an external Project to be shared over REST
  22. func (p *Project) Externalize() *ProjectExternal {
  23. roles := make([]RoleExternal, 0)
  24. for _, role := range p.Roles {
  25. roles = append(roles, *role.Externalize())
  26. }
  27. repoClients := make([]RepoClientExternal, 0)
  28. for _, repoClient := range p.RepoClients {
  29. repoClients = append(repoClients, *repoClient.Externalize())
  30. }
  31. return &ProjectExternal{
  32. ID: p.ID,
  33. Name: p.Name,
  34. Roles: roles,
  35. RepoClients: repoClients,
  36. }
  37. }