-
Notifications
You must be signed in to change notification settings - Fork 177
/
repository.go
119 lines (103 loc) · 3.71 KB
/
repository.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright 2020 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package account
import (
"github.com/ZupIT/horusec/development-kit/pkg/entities/roles"
"time"
accountEnum "github.com/ZupIT/horusec/development-kit/pkg/enums/account"
"github.com/go-ozzo/ozzo-validation/v4/is"
validation "github.com/go-ozzo/ozzo-validation/v4"
"github.com/google/uuid"
)
type Repository struct {
RepositoryID uuid.UUID `json:"repositoryID" gorm:"primary_key" swaggerignore:"true"`
CompanyID uuid.UUID `json:"companyID" swaggerignore:"true"`
Name string `json:"name"`
Description string `json:"description"`
AuthzMember string `json:"authzMember"`
AuthzAdmin string `json:"authzAdmin"`
AuthzSupervisor string `json:"authzSupervisor"`
CreatedAt time.Time `json:"createdAt" swaggerignore:"true"`
UpdatedAt time.Time `json:"updatedAt" swaggerignore:"true"`
}
type RepositoryResponse struct {
CompanyID uuid.UUID `json:"companyID"`
RepositoryID uuid.UUID `json:"repositoryID"`
Name string `json:"name"`
Role accountEnum.Role `json:"role"`
Description string `json:"description"`
AuthzMember string `json:"authzMember"`
AuthzAdmin string `json:"authzAdmin"`
AuthzSupervisor string `json:"authzSupervisor"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (r *Repository) Validate() error {
return validation.ValidateStruct(r,
validation.Field(&r.CompanyID, validation.Required, is.UUID),
validation.Field(&r.Name, validation.Required, validation.Length(1, 255)),
)
}
func (r *Repository) SetCreateData(companyID uuid.UUID) *Repository {
r.RepositoryID = uuid.New()
r.CreatedAt = time.Now()
r.UpdatedAt = time.Now()
r.CompanyID = companyID
return r
}
func (r *Repository) SetUpdateData(
name, description, authzAdmin, authzMember, authzSupervisor string) *Repository {
r.UpdatedAt = time.Now()
r.Name = name
r.Description = description
r.AuthzAdmin = authzAdmin
r.AuthzMember = authzMember
r.AuthzSupervisor = authzSupervisor
return r
}
func (r *Repository) GetTable() string {
return "repositories"
}
func (r *Repository) ToAccountRepository(role accountEnum.Role, accountID uuid.UUID) *roles.AccountRepository {
accountRepository := &roles.AccountRepository{
RepositoryID: r.RepositoryID,
CompanyID: r.CompanyID,
AccountID: accountID,
Role: role,
}
return accountRepository.SetCreateData()
}
func (r *Repository) ToRepositoryResponse(role accountEnum.Role) *RepositoryResponse {
return &RepositoryResponse{
RepositoryID: r.RepositoryID,
CompanyID: r.CompanyID,
Name: r.Name,
Role: role,
AuthzAdmin: r.AuthzAdmin,
AuthzMember: r.AuthzMember,
AuthzSupervisor: r.AuthzSupervisor,
Description: r.Description,
CreatedAt: r.CreatedAt,
UpdatedAt: r.UpdatedAt,
}
}
func (r *Repository) GetAuthzMember() string {
return r.AuthzMember
}
func (r *Repository) GetAuthzAdmin() string {
return r.AuthzAdmin
}
func (r *Repository) GetAuthzSupervisor() string {
return r.AuthzSupervisor
}