This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
project.go
54 lines (49 loc) · 1.47 KB
/
project.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
48
49
50
51
52
53
54
package transformers
import (
"github.com/flyteorg/flyteadmin/pkg/repositories/models"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
"github.com/golang/protobuf/proto"
)
type CreateProjectModelInput struct {
Identifier string
Name string
Description string
}
func CreateProjectModel(project *admin.Project) models.Project {
stateInt := int32(project.State)
projectBytes, err := proto.Marshal(project)
if err != nil {
return models.Project{}
}
return models.Project{
Identifier: project.Id,
Name: project.Name,
Description: project.Description,
Labels: projectBytes,
State: &stateInt,
}
}
func FromProjectModel(projectModel models.Project, domains []*admin.Domain) admin.Project {
projectDeserialized := &admin.Project{}
err := proto.Unmarshal(projectModel.Labels, projectDeserialized)
if err != nil {
return admin.Project{}
}
project := admin.Project{
Id: projectModel.Identifier,
Name: projectModel.Name,
Description: projectModel.Description,
Labels: projectDeserialized.Labels,
State: admin.Project_ProjectState(*projectModel.State),
}
project.Domains = domains
return project
}
func FromProjectModels(projectModels []models.Project, domains []*admin.Domain) []*admin.Project {
projects := make([]*admin.Project, len(projectModels))
for index, projectModel := range projectModels {
project := FromProjectModel(projectModel, domains)
projects[index] = &project
}
return projects
}