-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.go
50 lines (38 loc) · 849 Bytes
/
role.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
package entity
import (
"github.com/a-aslani/golang_agency_clean_architecture/internal/support/model/vo"
)
type Role struct {
ID vo.RoleID `bson:"_id" json:"id"`
Code vo.RoleCode `bson:"code" json:"code"`
Name vo.RoleName `bson:"name" json:"name"`
}
type RoleCreateRequest struct {
ID string `json:"-"`
Code vo.RoleCode `json:"code"`
Name vo.RoleName `json:"name"`
}
func (r RoleCreateRequest) Validate() error {
if err := r.Code.Validate(); err != nil {
return err
}
if err := r.Name.Validate(); err != nil {
return err
}
return nil
}
func NewRole(req RoleCreateRequest) (*Role, error) {
err := req.Validate()
if err != nil {
return nil, err
}
id, err := vo.NewRoleID(req.ID)
if err != nil {
return nil, err
}
var obj Role
obj.ID = id
obj.Code = req.Code
obj.Name = req.Name
return &obj, nil
}