project.go 931 B

12345678910111213141516171819202122232425262728293031323334353637
  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. ServiceAccountCandidates []ServiceAccountCandidate `json:"sa_candidates"`
  11. ServiceAccounts []ServiceAccount `json:"serviceaccounts"`
  12. }
  13. // ProjectExternal represents the Project type that is sent over REST
  14. type ProjectExternal struct {
  15. ID uint `json:"id"`
  16. Name string `json:"name"`
  17. Roles []RoleExternal `json:"roles"`
  18. }
  19. // Externalize generates an external Project to be shared over REST
  20. func (p *Project) Externalize() *ProjectExternal {
  21. roles := make([]RoleExternal, 0)
  22. for _, role := range p.Roles {
  23. roles = append(roles, *role.Externalize())
  24. }
  25. return &ProjectExternal{
  26. ID: p.ID,
  27. Name: p.Name,
  28. Roles: roles,
  29. }
  30. }