-
Notifications
You must be signed in to change notification settings - Fork 7
/
user.go
47 lines (39 loc) · 1.27 KB
/
user.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
package user
import (
"time"
"github.com/linzhengen/ddd-gin-admin/pkg/util/structure"
"github.com/linzhengen/ddd-gin-admin/app/domain/user"
)
type Model struct {
ID string `gorm:"column:id;primary_key;size:36;"`
UserName string `gorm:"column:user_name;size:64;index;default:'';not null;"`
RealName string `gorm:"column:real_name;size:64;index;default:'';not null;"`
Password string `gorm:"column:password;size:40;default:'';not null;"`
Email *string `gorm:"column:email;size:255;index;"`
Phone *string `gorm:"column:phone;size:20;index;"`
Status int `gorm:"column:status;index;default:0;not null;"`
Creator string `gorm:"column:creator;size:36;"`
CreatedAt time.Time `gorm:"column:created_at;index;"`
UpdatedAt time.Time `gorm:"column:updated_at;index;"`
DeletedAt *time.Time `gorm:"column:deleted_at;index;"`
}
func (Model) TableName() string {
return "users"
}
func (a Model) ToDomain() *user.User {
item := new(user.User)
structure.Copy(a, item)
return item
}
func toDomainList(ms []*Model) []*user.User {
list := make([]*user.User, len(ms))
for i, item := range ms {
list[i] = item.ToDomain()
}
return list
}
func domainToModel(u *user.User) *Model {
item := new(Model)
structure.Copy(u, item)
return item
}