正在显示
33 个修改的文件
包含
1991 行增加
和
0 行删除
pkg/application/user/command/batch_add.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + | ||
9 | + "github.com/beego/beego/v2/core/validation" | ||
10 | +) | ||
11 | + | ||
12 | +type BatchAddCommand struct { | ||
13 | + // 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加) | ||
14 | + UserType int `cname:"用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加)" json:"userType" valid:"Required"` | ||
15 | + // 用户列表 | ||
16 | + User []*domain.User `cname:"用户列表" json:"user,omitempty"` | ||
17 | + // 密码 | ||
18 | + Password string `cname:"密码" json:"password" valid:"Required"` | ||
19 | +} | ||
20 | + | ||
21 | +func (batchAddCommand *BatchAddCommand) Valid(validation *validation.Validation) { | ||
22 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
23 | +} | ||
24 | + | ||
25 | +func (batchAddCommand *BatchAddCommand) ValidateCommand() error { | ||
26 | + valid := validation.Validation{} | ||
27 | + b, err := valid.Valid(batchAddCommand) | ||
28 | + if err != nil { | ||
29 | + return err | ||
30 | + } | ||
31 | + if !b { | ||
32 | + elem := reflect.TypeOf(batchAddCommand).Elem() | ||
33 | + for _, validErr := range valid.Errors { | ||
34 | + field, isExist := elem.FieldByName(validErr.Field) | ||
35 | + if isExist { | ||
36 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
37 | + } else { | ||
38 | + return fmt.Errorf(validErr.Message) | ||
39 | + } | ||
40 | + } | ||
41 | + } | ||
42 | + return nil | ||
43 | +} |
pkg/application/user/command/batch_enable.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type BatchEnableCommand struct { | ||
12 | + UserIds []int64 `cname:"" json:"userIds" valid:"Required"` | ||
13 | + // 启用状态(启用:1 禁用:2 注销:3) | ||
14 | + EnableStatus int `cname:"启用状态(启用:1 禁用:2 注销:3)" json:"enableStatus" valid:"Required"` | ||
15 | +} | ||
16 | + | ||
17 | +func (batchEnableCommand *BatchEnableCommand) Valid(validation *validation.Validation) { | ||
18 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
19 | +} | ||
20 | + | ||
21 | +func (batchEnableCommand *BatchEnableCommand) ValidateCommand() error { | ||
22 | + valid := validation.Validation{} | ||
23 | + b, err := valid.Valid(batchEnableCommand) | ||
24 | + if err != nil { | ||
25 | + return err | ||
26 | + } | ||
27 | + if !b { | ||
28 | + elem := reflect.TypeOf(batchEnableCommand).Elem() | ||
29 | + for _, validErr := range valid.Errors { | ||
30 | + field, isExist := elem.FieldByName(validErr.Field) | ||
31 | + if isExist { | ||
32 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
33 | + } else { | ||
34 | + return fmt.Errorf(validErr.Message) | ||
35 | + } | ||
36 | + } | ||
37 | + } | ||
38 | + return nil | ||
39 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type BatchResetPasswordCommand struct { | ||
12 | + UserIds []int64 `cname:"" json:"userIds" valid:"Required"` | ||
13 | + // 密码 | ||
14 | + Password string `cname:"密码" json:"password" valid:"Required"` | ||
15 | +} | ||
16 | + | ||
17 | +func (batchResetPasswordCommand *BatchResetPasswordCommand) Valid(validation *validation.Validation) { | ||
18 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
19 | +} | ||
20 | + | ||
21 | +func (batchResetPasswordCommand *BatchResetPasswordCommand) ValidateCommand() error { | ||
22 | + valid := validation.Validation{} | ||
23 | + b, err := valid.Valid(batchResetPasswordCommand) | ||
24 | + if err != nil { | ||
25 | + return err | ||
26 | + } | ||
27 | + if !b { | ||
28 | + elem := reflect.TypeOf(batchResetPasswordCommand).Elem() | ||
29 | + for _, validErr := range valid.Errors { | ||
30 | + field, isExist := elem.FieldByName(validErr.Field) | ||
31 | + if isExist { | ||
32 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
33 | + } else { | ||
34 | + return fmt.Errorf(validErr.Message) | ||
35 | + } | ||
36 | + } | ||
37 | + } | ||
38 | + return nil | ||
39 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + "time" | ||
8 | + | ||
9 | + "github.com/beego/beego/v2/core/validation" | ||
10 | +) | ||
11 | + | ||
12 | +type CreateCooperatorCommand struct { | ||
13 | + // 共创公司 | ||
14 | + CooperationCompany string `cname:"共创公司" json:"cooperationCompany" valid:"Required"` | ||
15 | + // 共创到期时间 | ||
16 | + CooperationDeadline time.Time `cname:"共创到期时间" json:"cooperationDeadline" valid:"Required"` | ||
17 | + // 邮箱 | ||
18 | + Email string `cname:"邮箱" json:"email" valid:"Required"` | ||
19 | + // 启用状态(启用:1 禁用:2 注销:3) | ||
20 | + EnableStatus int `cname:"启用状态(启用:1 禁用:2 注销:3)" json:"enableStatus" valid:"Required"` | ||
21 | + // 用户编号 企业内标识 | ||
22 | + UserCode string `cname:"用户编号 企业内标识" json:"userCode" valid:"Required"` | ||
23 | + // 用户Id 用户唯一标识 | ||
24 | + UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"` | ||
25 | + // 用户姓名 | ||
26 | + UserName string `cname:"用户姓名" json:"userName" valid:"Required"` | ||
27 | + // 头像 | ||
28 | + Avatar string `cname:"头像" json:"avatar" valid:"Required"` | ||
29 | + // 组织ID | ||
30 | + OrgId int64 `cname:"组织ID" json:"orgId,string" valid:"Required"` | ||
31 | +} | ||
32 | + | ||
33 | +func (createCooperatorCommand *CreateCooperatorCommand) Valid(validation *validation.Validation) { | ||
34 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
35 | +} | ||
36 | + | ||
37 | +func (createCooperatorCommand *CreateCooperatorCommand) ValidateCommand() error { | ||
38 | + valid := validation.Validation{} | ||
39 | + b, err := valid.Valid(createCooperatorCommand) | ||
40 | + if err != nil { | ||
41 | + return err | ||
42 | + } | ||
43 | + if !b { | ||
44 | + elem := reflect.TypeOf(createCooperatorCommand).Elem() | ||
45 | + for _, validErr := range valid.Errors { | ||
46 | + field, isExist := elem.FieldByName(validErr.Field) | ||
47 | + if isExist { | ||
48 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
49 | + } else { | ||
50 | + return fmt.Errorf(validErr.Message) | ||
51 | + } | ||
52 | + } | ||
53 | + } | ||
54 | + return nil | ||
55 | +} |
pkg/application/user/command/create_user.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/beego/beego/v2/core/validation" | ||
11 | +) | ||
12 | + | ||
13 | +type CreateUserCommand struct { | ||
14 | + // 企业id | ||
15 | + CompanyId int64 `cname:"企业id" json:"companyId,string" valid:"Required"` | ||
16 | + // 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加) | ||
17 | + UserType int `cname:"用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加)" json:"userType" valid:"Required"` | ||
18 | + // 用户编号 企业内标识 | ||
19 | + UserCode string `cname:"用户编号 企业内标识" json:"userCode" valid:"Required"` | ||
20 | + // 组织机构 | ||
21 | + OrganizationId int64 `cname:"组织机构" json:"organizationId,string,omitempty"` | ||
22 | + // 所属部门 | ||
23 | + DepartmentId int64 `cname:"所属部门" json:"departmentId,string,omitempty"` | ||
24 | + // 用户关联的组织 | ||
25 | + UserOrg []*domain.Org `cname:"用户关联的组织" json:"userOrg,omitempty"` | ||
26 | + // 用户关联的角色 | ||
27 | + UserRole []*domain.Role `cname:"用户关联的角色" json:"userRole,omitempty"` | ||
28 | + // 共创公司 | ||
29 | + CooperationCompany string `cname:"共创公司" json:"cooperationCompany,omitempty"` | ||
30 | + // 共创到期时间 (yyyy-MM-dd) | ||
31 | + CooperationDeadline time.Time `cname:"共创到期时间 (yyyy-MM-dd)" json:"cooperationDeadline,omitempty"` | ||
32 | + // 启用状态(启用:1 禁用:2) | ||
33 | + EnableStatus int `cname:"启用状态(启用:1 禁用:2)" json:"enableStatus,omitempty"` | ||
34 | + // 密码 | ||
35 | + Password string `cname:"密码" json:"password" valid:"Required"` | ||
36 | + // 用户姓名 | ||
37 | + UserName string `cname:"用户姓名" json:"userName" valid:"Required"` | ||
38 | + // 手机号码 | ||
39 | + Phone string `cname:"手机号码" json:"phone" valid:"Required"` | ||
40 | + // 头像 | ||
41 | + Avatar string `cname:"头像" json:"avatar" valid:"Required"` | ||
42 | + // 邮箱 | ||
43 | + Email string `cname:"邮箱" json:"email" valid:"Required"` | ||
44 | +} | ||
45 | + | ||
46 | +func (createUserCommand *CreateUserCommand) Valid(validation *validation.Validation) { | ||
47 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
48 | +} | ||
49 | + | ||
50 | +func (createUserCommand *CreateUserCommand) ValidateCommand() error { | ||
51 | + valid := validation.Validation{} | ||
52 | + b, err := valid.Valid(createUserCommand) | ||
53 | + if err != nil { | ||
54 | + return err | ||
55 | + } | ||
56 | + if !b { | ||
57 | + elem := reflect.TypeOf(createUserCommand).Elem() | ||
58 | + for _, validErr := range valid.Errors { | ||
59 | + field, isExist := elem.FieldByName(validErr.Field) | ||
60 | + if isExist { | ||
61 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
62 | + } else { | ||
63 | + return fmt.Errorf(validErr.Message) | ||
64 | + } | ||
65 | + } | ||
66 | + } | ||
67 | + return nil | ||
68 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type DeleteFavoriteMenusCommand struct { | ||
12 | + // 编码 | ||
13 | + Code int `cname:"编码" json:"code" valid:"Required"` | ||
14 | + // 用户Id 用户唯一标识 | ||
15 | + UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"` | ||
16 | +} | ||
17 | + | ||
18 | +func (deleteFavoriteMenusCommand *DeleteFavoriteMenusCommand) Valid(validation *validation.Validation) { | ||
19 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
20 | +} | ||
21 | + | ||
22 | +func (deleteFavoriteMenusCommand *DeleteFavoriteMenusCommand) ValidateCommand() error { | ||
23 | + valid := validation.Validation{} | ||
24 | + b, err := valid.Valid(deleteFavoriteMenusCommand) | ||
25 | + if err != nil { | ||
26 | + return err | ||
27 | + } | ||
28 | + if !b { | ||
29 | + elem := reflect.TypeOf(deleteFavoriteMenusCommand).Elem() | ||
30 | + for _, validErr := range valid.Errors { | ||
31 | + field, isExist := elem.FieldByName(validErr.Field) | ||
32 | + if isExist { | ||
33 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
34 | + } else { | ||
35 | + return fmt.Errorf(validErr.Message) | ||
36 | + } | ||
37 | + } | ||
38 | + } | ||
39 | + return nil | ||
40 | +} |
pkg/application/user/command/remove_user.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type RemoveUserCommand struct { | ||
12 | + // 用户Id 用户唯一标识 | ||
13 | + UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (removeUserCommand *RemoveUserCommand) Valid(validation *validation.Validation) { | ||
17 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (removeUserCommand *RemoveUserCommand) ValidateCommand() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(removeUserCommand) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + elem := reflect.TypeOf(removeUserCommand).Elem() | ||
28 | + for _, validErr := range valid.Errors { | ||
29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
30 | + if isExist { | ||
31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
32 | + } else { | ||
33 | + return fmt.Errorf(validErr.Message) | ||
34 | + } | ||
35 | + } | ||
36 | + } | ||
37 | + return nil | ||
38 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + "time" | ||
8 | + | ||
9 | + "github.com/beego/beego/v2/core/validation" | ||
10 | +) | ||
11 | + | ||
12 | +type UpdateCooperatorCommand struct { | ||
13 | + // 共创公司 | ||
14 | + CooperationCompany string `cname:"共创公司" json:"cooperationCompany" valid:"Required"` | ||
15 | + // 共创到期时间 | ||
16 | + CooperationDeadline time.Time `cname:"共创到期时间" json:"cooperationDeadline" valid:"Required"` | ||
17 | + // 邮箱 | ||
18 | + Email string `cname:"邮箱" json:"email" valid:"Required"` | ||
19 | + // 启用状态(启用:1 禁用:2 注销:3) | ||
20 | + EnableStatus int `cname:"启用状态(启用:1 禁用:2 注销:3)" json:"enableStatus" valid:"Required"` | ||
21 | + // 用户编号 企业内标识 | ||
22 | + UserCode string `cname:"用户编号 企业内标识" json:"userCode" valid:"Required"` | ||
23 | + // 用户Id 用户唯一标识 | ||
24 | + UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"` | ||
25 | + // 用户姓名 | ||
26 | + UserName string `cname:"用户姓名" json:"userName" valid:"Required"` | ||
27 | + // 头像 | ||
28 | + Avatar string `cname:"头像" json:"avatar" valid:"Required"` | ||
29 | + // 组织ID | ||
30 | + OrgId int64 `cname:"组织ID" json:"orgId,string" valid:"Required"` | ||
31 | +} | ||
32 | + | ||
33 | +func (updateCooperatorCommand *UpdateCooperatorCommand) Valid(validation *validation.Validation) { | ||
34 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
35 | +} | ||
36 | + | ||
37 | +func (updateCooperatorCommand *UpdateCooperatorCommand) ValidateCommand() error { | ||
38 | + valid := validation.Validation{} | ||
39 | + b, err := valid.Valid(updateCooperatorCommand) | ||
40 | + if err != nil { | ||
41 | + return err | ||
42 | + } | ||
43 | + if !b { | ||
44 | + elem := reflect.TypeOf(updateCooperatorCommand).Elem() | ||
45 | + for _, validErr := range valid.Errors { | ||
46 | + field, isExist := elem.FieldByName(validErr.Field) | ||
47 | + if isExist { | ||
48 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
49 | + } else { | ||
50 | + return fmt.Errorf(validErr.Message) | ||
51 | + } | ||
52 | + } | ||
53 | + } | ||
54 | + return nil | ||
55 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type UpdateFavoriteMenusCommand struct { | ||
12 | + // 菜单编码列表 | ||
13 | + FavoriteMenus []string `cname:"菜单编码列表" json:"favoriteMenus,omitempty"` | ||
14 | + // 用户Id 用户唯一标识 | ||
15 | + UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"` | ||
16 | +} | ||
17 | + | ||
18 | +func (updateFavoriteMenusCommand *UpdateFavoriteMenusCommand) Valid(validation *validation.Validation) { | ||
19 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
20 | +} | ||
21 | + | ||
22 | +func (updateFavoriteMenusCommand *UpdateFavoriteMenusCommand) ValidateCommand() error { | ||
23 | + valid := validation.Validation{} | ||
24 | + b, err := valid.Valid(updateFavoriteMenusCommand) | ||
25 | + if err != nil { | ||
26 | + return err | ||
27 | + } | ||
28 | + if !b { | ||
29 | + elem := reflect.TypeOf(updateFavoriteMenusCommand).Elem() | ||
30 | + for _, validErr := range valid.Errors { | ||
31 | + field, isExist := elem.FieldByName(validErr.Field) | ||
32 | + if isExist { | ||
33 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
34 | + } else { | ||
35 | + return fmt.Errorf(validErr.Message) | ||
36 | + } | ||
37 | + } | ||
38 | + } | ||
39 | + return nil | ||
40 | +} |
pkg/application/user/command/update_user.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/beego/beego/v2/core/validation" | ||
11 | +) | ||
12 | + | ||
13 | +type UpdateUserCommand struct { | ||
14 | + // 用户Id 用户唯一标识 | ||
15 | + UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"` | ||
16 | + // 组织机构 | ||
17 | + OrganizationId int64 `cname:"组织机构" json:"organizationId,string,omitempty"` | ||
18 | + // 所属部门 | ||
19 | + DepartmentId int64 `cname:"所属部门" json:"departmentId,string,omitempty"` | ||
20 | + // 用户关联的组织 | ||
21 | + UserOrg []*domain.Org `cname:"用户关联的组织" json:"userOrg,omitempty"` | ||
22 | + // 用户关联的角色 | ||
23 | + UserRole []*domain.Role `cname:"用户关联的角色" json:"userRole,omitempty"` | ||
24 | + // 共创公司 | ||
25 | + CooperationCompany string `cname:"共创公司" json:"cooperationCompany,omitempty"` | ||
26 | + // 共创到期时间 (yyyy-MM-dd) | ||
27 | + CooperationDeadline time.Time `cname:"共创到期时间 (yyyy-MM-dd)" json:"cooperationDeadline,omitempty"` | ||
28 | + // 启用状态(启用:1 禁用:2) | ||
29 | + EnableStatus int `cname:"启用状态(启用:1 禁用:2)" json:"enableStatus,omitempty"` | ||
30 | + // 用户姓名 | ||
31 | + UserName string `cname:"用户姓名" json:"userName" valid:"Required"` | ||
32 | + // 手机号码 | ||
33 | + Phone string `cname:"手机号码" json:"phone" valid:"Required"` | ||
34 | + // 头像 | ||
35 | + Avatar string `cname:"头像" json:"avatar" valid:"Required"` | ||
36 | + // 邮箱 | ||
37 | + Email string `cname:"邮箱" json:"email" valid:"Required"` | ||
38 | +} | ||
39 | + | ||
40 | +func (updateUserCommand *UpdateUserCommand) Valid(validation *validation.Validation) { | ||
41 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
42 | +} | ||
43 | + | ||
44 | +func (updateUserCommand *UpdateUserCommand) ValidateCommand() error { | ||
45 | + valid := validation.Validation{} | ||
46 | + b, err := valid.Valid(updateUserCommand) | ||
47 | + if err != nil { | ||
48 | + return err | ||
49 | + } | ||
50 | + if !b { | ||
51 | + elem := reflect.TypeOf(updateUserCommand).Elem() | ||
52 | + for _, validErr := range valid.Errors { | ||
53 | + field, isExist := elem.FieldByName(validErr.Field) | ||
54 | + if isExist { | ||
55 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
56 | + } else { | ||
57 | + return fmt.Errorf(validErr.Message) | ||
58 | + } | ||
59 | + } | ||
60 | + } | ||
61 | + return nil | ||
62 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type UpdateUsersBaseCommand struct { | ||
12 | + // 用户Id 用户唯一标识 | ||
13 | + UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"` | ||
14 | + // 用户姓名 | ||
15 | + UserName string `cname:"用户姓名" json:"userName" valid:"Required"` | ||
16 | + // 头像 | ||
17 | + Avatar string `cname:"头像" json:"avatar" valid:"Required"` | ||
18 | + // 手机号码 | ||
19 | + Phone string `cname:"手机号码" json:"phone" valid:"Required"` | ||
20 | + // 邮箱 | ||
21 | + Email string `cname:"邮箱" json:"email" valid:"Required"` | ||
22 | +} | ||
23 | + | ||
24 | +func (updateUsersBaseCommand *UpdateUsersBaseCommand) Valid(validation *validation.Validation) { | ||
25 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
26 | +} | ||
27 | + | ||
28 | +func (updateUsersBaseCommand *UpdateUsersBaseCommand) ValidateCommand() error { | ||
29 | + valid := validation.Validation{} | ||
30 | + b, err := valid.Valid(updateUsersBaseCommand) | ||
31 | + if err != nil { | ||
32 | + return err | ||
33 | + } | ||
34 | + if !b { | ||
35 | + elem := reflect.TypeOf(updateUsersBaseCommand).Elem() | ||
36 | + for _, validErr := range valid.Errors { | ||
37 | + field, isExist := elem.FieldByName(validErr.Field) | ||
38 | + if isExist { | ||
39 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
40 | + } else { | ||
41 | + return fmt.Errorf(validErr.Message) | ||
42 | + } | ||
43 | + } | ||
44 | + } | ||
45 | + return nil | ||
46 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type GetFavoriteMenusQuery struct { | ||
12 | + // 用户Id 用户唯一标识 | ||
13 | + UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (getFavoriteMenusQuery *GetFavoriteMenusQuery) Valid(validation *validation.Validation) { | ||
17 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (getFavoriteMenusQuery *GetFavoriteMenusQuery) ValidateQuery() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(getFavoriteMenusQuery) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + elem := reflect.TypeOf(getFavoriteMenusQuery).Elem() | ||
28 | + for _, validErr := range valid.Errors { | ||
29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
30 | + if isExist { | ||
31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
32 | + } else { | ||
33 | + return fmt.Errorf(validErr.Message) | ||
34 | + } | ||
35 | + } | ||
36 | + } | ||
37 | + return nil | ||
38 | +} |
pkg/application/user/query/get_user.go
0 → 100644
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type GetUserQuery struct { | ||
12 | + // 用户Id 用户唯一标识 | ||
13 | + UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (getUserQuery *GetUserQuery) Valid(validation *validation.Validation) { | ||
17 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (getUserQuery *GetUserQuery) ValidateQuery() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(getUserQuery) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + elem := reflect.TypeOf(getUserQuery).Elem() | ||
28 | + for _, validErr := range valid.Errors { | ||
29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
30 | + if isExist { | ||
31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
32 | + } else { | ||
33 | + return fmt.Errorf(validErr.Message) | ||
34 | + } | ||
35 | + } | ||
36 | + } | ||
37 | + return nil | ||
38 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type GetUserAccessMenusQuery struct { | ||
12 | + // 用户Id 用户唯一标识 | ||
13 | + UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"` | ||
14 | + // 菜单类别 web app | ||
15 | + MenuCategory string `cname:"菜单类别 web app" json:"menuCategory,omitempty"` | ||
16 | +} | ||
17 | + | ||
18 | +func (getUserAccessMenusQuery *GetUserAccessMenusQuery) Valid(validation *validation.Validation) { | ||
19 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
20 | +} | ||
21 | + | ||
22 | +func (getUserAccessMenusQuery *GetUserAccessMenusQuery) ValidateQuery() error { | ||
23 | + valid := validation.Validation{} | ||
24 | + b, err := valid.Valid(getUserAccessMenusQuery) | ||
25 | + if err != nil { | ||
26 | + return err | ||
27 | + } | ||
28 | + if !b { | ||
29 | + elem := reflect.TypeOf(getUserAccessMenusQuery).Elem() | ||
30 | + for _, validErr := range valid.Errors { | ||
31 | + field, isExist := elem.FieldByName(validErr.Field) | ||
32 | + if isExist { | ||
33 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
34 | + } else { | ||
35 | + return fmt.Errorf(validErr.Message) | ||
36 | + } | ||
37 | + } | ||
38 | + } | ||
39 | + return nil | ||
40 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type GetUserProfileQuery struct { | ||
12 | + // 用户Id 用户唯一标识 | ||
13 | + UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string,omitempty"` | ||
14 | + // 手机号码 | ||
15 | + Phone string `cname:"手机号码" json:"phone,omitempty"` | ||
16 | + // 企业id | ||
17 | + CompanyId int64 `cname:"企业id" json:"companyId,string,omitempty"` | ||
18 | + // 用户编号 企业内标识 | ||
19 | + UserCode string `cname:"用户编号 企业内标识" json:"userCode,omitempty"` | ||
20 | +} | ||
21 | + | ||
22 | +func (getUserProfileQuery *GetUserProfileQuery) Valid(validation *validation.Validation) { | ||
23 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
24 | +} | ||
25 | + | ||
26 | +func (getUserProfileQuery *GetUserProfileQuery) ValidateQuery() error { | ||
27 | + valid := validation.Validation{} | ||
28 | + b, err := valid.Valid(getUserProfileQuery) | ||
29 | + if err != nil { | ||
30 | + return err | ||
31 | + } | ||
32 | + if !b { | ||
33 | + elem := reflect.TypeOf(getUserProfileQuery).Elem() | ||
34 | + for _, validErr := range valid.Errors { | ||
35 | + field, isExist := elem.FieldByName(validErr.Field) | ||
36 | + if isExist { | ||
37 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
38 | + } else { | ||
39 | + return fmt.Errorf(validErr.Message) | ||
40 | + } | ||
41 | + } | ||
42 | + } | ||
43 | + return nil | ||
44 | +} |
pkg/application/user/query/list_user.go
0 → 100644
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type ListUserQuery struct { | ||
12 | + // 查询偏离量 | ||
13 | + Offset int `cname:"查询偏离量" json:"offset" valid:"Required"` | ||
14 | + // 查询限制 | ||
15 | + Limit int `cname:"查询限制" json:"limit" valid:"Required"` | ||
16 | + // 企业id | ||
17 | + CompanyId int64 `cname:"企业id" json:"companyId,string,omitempty"` | ||
18 | + // 组织ID | ||
19 | + OrganizationId int64 `cname:"组织ID" json:"organizationId,string,omitempty"` | ||
20 | + // 部门编号 | ||
21 | + DepartmentId int64 `cname:"部门编号" json:"departmentId,string,omitempty"` | ||
22 | + // 用户姓名 | ||
23 | + UserName string `cname:"用户姓名" json:"userName,omitempty"` | ||
24 | + // 部门名称 | ||
25 | + DepName string `cname:"部门名称" json:"depName,omitempty"` | ||
26 | + // 手机号码 | ||
27 | + Phone string `cname:"手机号码" json:"phone,omitempty"` | ||
28 | +} | ||
29 | + | ||
30 | +func (listUserQuery *ListUserQuery) Valid(validation *validation.Validation) { | ||
31 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
32 | +} | ||
33 | + | ||
34 | +func (listUserQuery *ListUserQuery) ValidateQuery() error { | ||
35 | + valid := validation.Validation{} | ||
36 | + b, err := valid.Valid(listUserQuery) | ||
37 | + if err != nil { | ||
38 | + return err | ||
39 | + } | ||
40 | + if !b { | ||
41 | + elem := reflect.TypeOf(listUserQuery).Elem() | ||
42 | + for _, validErr := range valid.Errors { | ||
43 | + field, isExist := elem.FieldByName(validErr.Field) | ||
44 | + if isExist { | ||
45 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
46 | + } else { | ||
47 | + return fmt.Errorf(validErr.Message) | ||
48 | + } | ||
49 | + } | ||
50 | + } | ||
51 | + return nil | ||
52 | +} |
pkg/application/user/service/user.go
0 → 100644
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/linmadan/egglib-go/core/application" | ||
6 | + "github.com/linmadan/egglib-go/utils/tool_funs" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/factory" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/command" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/query" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
11 | +) | ||
12 | + | ||
13 | +// 用户 | ||
14 | +type UserService struct { | ||
15 | +} | ||
16 | + | ||
17 | +// 批量添加 | ||
18 | +func (userService *UserService) BatchAdd(batchAddCommand *command.BatchAddCommand) (interface{}, error) { | ||
19 | + if err := batchAddCommand.ValidateCommand(); err != nil { | ||
20 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
21 | + } | ||
22 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
23 | + if err != nil { | ||
24 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
25 | + } | ||
26 | + if err := transactionContext.StartTransaction(); err != nil { | ||
27 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
28 | + } | ||
29 | + defer func() { | ||
30 | + transactionContext.RollbackTransaction() | ||
31 | + }() | ||
32 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
33 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
34 | + } | ||
35 | + return nil, nil | ||
36 | +} | ||
37 | + | ||
38 | +// 批量修改启用状态 | ||
39 | +func (userService *UserService) BatchEnable(batchEnableCommand *command.BatchEnableCommand) (interface{}, error) { | ||
40 | + if err := batchEnableCommand.ValidateCommand(); err != nil { | ||
41 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
42 | + } | ||
43 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
44 | + if err != nil { | ||
45 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
46 | + } | ||
47 | + if err := transactionContext.StartTransaction(); err != nil { | ||
48 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
49 | + } | ||
50 | + defer func() { | ||
51 | + transactionContext.RollbackTransaction() | ||
52 | + }() | ||
53 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
54 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
55 | + } | ||
56 | + return nil, nil | ||
57 | +} | ||
58 | + | ||
59 | +// 批量重置密码 | ||
60 | +func (userService *UserService) BatchResetPassword(batchResetPasswordCommand *command.BatchResetPasswordCommand) (interface{}, error) { | ||
61 | + if err := batchResetPasswordCommand.ValidateCommand(); err != nil { | ||
62 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
63 | + } | ||
64 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
65 | + if err != nil { | ||
66 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
67 | + } | ||
68 | + if err := transactionContext.StartTransaction(); err != nil { | ||
69 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
70 | + } | ||
71 | + defer func() { | ||
72 | + transactionContext.RollbackTransaction() | ||
73 | + }() | ||
74 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
75 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
76 | + } | ||
77 | + return nil, nil | ||
78 | +} | ||
79 | + | ||
80 | +// 创建共创用户 | ||
81 | +func (userService *UserService) CreateCooperator(createCooperatorCommand *command.CreateCooperatorCommand) (interface{}, error) { | ||
82 | + if err := createCooperatorCommand.ValidateCommand(); err != nil { | ||
83 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
84 | + } | ||
85 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
86 | + if err != nil { | ||
87 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
88 | + } | ||
89 | + if err := transactionContext.StartTransaction(); err != nil { | ||
90 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
91 | + } | ||
92 | + defer func() { | ||
93 | + transactionContext.RollbackTransaction() | ||
94 | + }() | ||
95 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
96 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
97 | + } | ||
98 | + return nil, nil | ||
99 | +} | ||
100 | + | ||
101 | +// 创建 | ||
102 | +func (userService *UserService) CreateUser(createUserCommand *command.CreateUserCommand) (interface{}, error) { | ||
103 | + if err := createUserCommand.ValidateCommand(); err != nil { | ||
104 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
105 | + } | ||
106 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
107 | + if err != nil { | ||
108 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
109 | + } | ||
110 | + if err := transactionContext.StartTransaction(); err != nil { | ||
111 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
112 | + } | ||
113 | + defer func() { | ||
114 | + transactionContext.RollbackTransaction() | ||
115 | + }() | ||
116 | + newUser := &domain.User{ | ||
117 | + CompanyId: createUserCommand.CompanyId, | ||
118 | + UserType: createUserCommand.UserType, | ||
119 | + UserCode: createUserCommand.UserCode, | ||
120 | + OrganizationId: createUserCommand.OrganizationId, | ||
121 | + DepartmentId: createUserCommand.DepartmentId, | ||
122 | + UserOrg: createUserCommand.UserOrg, | ||
123 | + UserRole: createUserCommand.UserRole, | ||
124 | + //CooperationInfo: createUserCommand.CooperationInfo, | ||
125 | + EnableStatus: createUserCommand.EnableStatus, | ||
126 | + //Password: createUserCommand.Password, | ||
127 | + //UserName: createUserCommand.UserName, | ||
128 | + //Phone: createUserCommand.Phone, | ||
129 | + //Avatar: createUserCommand.Avatar, | ||
130 | + //Email: createUserCommand.Email, | ||
131 | + } | ||
132 | + var userRepository domain.UserRepository | ||
133 | + if value, err := factory.CreateUserRepository(map[string]interface{}{ | ||
134 | + "transactionContext": transactionContext, | ||
135 | + }); err != nil { | ||
136 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
137 | + } else { | ||
138 | + userRepository = value | ||
139 | + } | ||
140 | + if user, err := userRepository.Save(newUser); err != nil { | ||
141 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
142 | + } else { | ||
143 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
144 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
145 | + } | ||
146 | + return user, nil | ||
147 | + } | ||
148 | +} | ||
149 | + | ||
150 | +// 移除我收藏的菜单 | ||
151 | +func (userService *UserService) DeleteFavoriteMenus(deleteFavoriteMenusCommand *command.DeleteFavoriteMenusCommand) (interface{}, error) { | ||
152 | + if err := deleteFavoriteMenusCommand.ValidateCommand(); err != nil { | ||
153 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
154 | + } | ||
155 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
156 | + if err != nil { | ||
157 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
158 | + } | ||
159 | + if err := transactionContext.StartTransaction(); err != nil { | ||
160 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
161 | + } | ||
162 | + defer func() { | ||
163 | + transactionContext.RollbackTransaction() | ||
164 | + }() | ||
165 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
166 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
167 | + } | ||
168 | + return nil, nil | ||
169 | +} | ||
170 | + | ||
171 | +// 获取我收藏的菜单 | ||
172 | +func (userService *UserService) GetFavoriteMenus(getFavoriteMenusQuery *query.GetFavoriteMenusQuery) (interface{}, error) { | ||
173 | + if err := getFavoriteMenusQuery.ValidateQuery(); err != nil { | ||
174 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
175 | + } | ||
176 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
177 | + if err != nil { | ||
178 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
179 | + } | ||
180 | + if err := transactionContext.StartTransaction(); err != nil { | ||
181 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
182 | + } | ||
183 | + defer func() { | ||
184 | + transactionContext.RollbackTransaction() | ||
185 | + }() | ||
186 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
187 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
188 | + } | ||
189 | + return nil, nil | ||
190 | +} | ||
191 | + | ||
192 | +// 返回 | ||
193 | +func (userService *UserService) GetUser(getUserQuery *query.GetUserQuery) (interface{}, error) { | ||
194 | + if err := getUserQuery.ValidateQuery(); err != nil { | ||
195 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
196 | + } | ||
197 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
198 | + if err != nil { | ||
199 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
200 | + } | ||
201 | + if err := transactionContext.StartTransaction(); err != nil { | ||
202 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
203 | + } | ||
204 | + defer func() { | ||
205 | + transactionContext.RollbackTransaction() | ||
206 | + }() | ||
207 | + var userRepository domain.UserRepository | ||
208 | + if value, err := factory.CreateUserRepository(map[string]interface{}{ | ||
209 | + "transactionContext": transactionContext, | ||
210 | + }); err != nil { | ||
211 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
212 | + } else { | ||
213 | + userRepository = value | ||
214 | + } | ||
215 | + user, err := userRepository.FindOne(map[string]interface{}{"userId": getUserQuery.UserId}) | ||
216 | + if err != nil { | ||
217 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
218 | + } | ||
219 | + if user == nil { | ||
220 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getUserQuery.UserId))) | ||
221 | + } else { | ||
222 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
223 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
224 | + } | ||
225 | + return user, nil | ||
226 | + } | ||
227 | +} | ||
228 | + | ||
229 | +// 返回用户有权限的菜单 | ||
230 | +func (userService *UserService) GetUserAccessMenus(getUserAccessMenusQuery *query.GetUserAccessMenusQuery) (interface{}, error) { | ||
231 | + if err := getUserAccessMenusQuery.ValidateQuery(); err != nil { | ||
232 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
233 | + } | ||
234 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
235 | + if err != nil { | ||
236 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
237 | + } | ||
238 | + if err := transactionContext.StartTransaction(); err != nil { | ||
239 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
240 | + } | ||
241 | + defer func() { | ||
242 | + transactionContext.RollbackTransaction() | ||
243 | + }() | ||
244 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
245 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
246 | + } | ||
247 | + return nil, nil | ||
248 | +} | ||
249 | + | ||
250 | +// 获取用户概要数据 | ||
251 | +func (userService *UserService) GetUserProfile(getUserProfileQuery *query.GetUserProfileQuery) (interface{}, error) { | ||
252 | + if err := getUserProfileQuery.ValidateQuery(); err != nil { | ||
253 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
254 | + } | ||
255 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
256 | + if err != nil { | ||
257 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
258 | + } | ||
259 | + if err := transactionContext.StartTransaction(); err != nil { | ||
260 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
261 | + } | ||
262 | + defer func() { | ||
263 | + transactionContext.RollbackTransaction() | ||
264 | + }() | ||
265 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
266 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
267 | + } | ||
268 | + return nil, nil | ||
269 | +} | ||
270 | + | ||
271 | +// 返回列表 | ||
272 | +func (userService *UserService) ListUser(listUserQuery *query.ListUserQuery) (interface{}, error) { | ||
273 | + if err := listUserQuery.ValidateQuery(); err != nil { | ||
274 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
275 | + } | ||
276 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
277 | + if err != nil { | ||
278 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
279 | + } | ||
280 | + if err := transactionContext.StartTransaction(); err != nil { | ||
281 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
282 | + } | ||
283 | + defer func() { | ||
284 | + transactionContext.RollbackTransaction() | ||
285 | + }() | ||
286 | + var userRepository domain.UserRepository | ||
287 | + if value, err := factory.CreateUserRepository(map[string]interface{}{ | ||
288 | + "transactionContext": transactionContext, | ||
289 | + }); err != nil { | ||
290 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
291 | + } else { | ||
292 | + userRepository = value | ||
293 | + } | ||
294 | + if count, users, err := userRepository.Find(tool_funs.SimpleStructToMap(listUserQuery)); err != nil { | ||
295 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
296 | + } else { | ||
297 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
298 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
299 | + } | ||
300 | + return map[string]interface{}{ | ||
301 | + "count": count, | ||
302 | + "users": users, | ||
303 | + }, nil | ||
304 | + } | ||
305 | +} | ||
306 | + | ||
307 | +// 移除 | ||
308 | +func (userService *UserService) RemoveUser(removeUserCommand *command.RemoveUserCommand) (interface{}, error) { | ||
309 | + if err := removeUserCommand.ValidateCommand(); err != nil { | ||
310 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
311 | + } | ||
312 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
313 | + if err != nil { | ||
314 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
315 | + } | ||
316 | + if err := transactionContext.StartTransaction(); err != nil { | ||
317 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
318 | + } | ||
319 | + defer func() { | ||
320 | + transactionContext.RollbackTransaction() | ||
321 | + }() | ||
322 | + var userRepository domain.UserRepository | ||
323 | + if value, err := factory.CreateUserRepository(map[string]interface{}{ | ||
324 | + "transactionContext": transactionContext, | ||
325 | + }); err != nil { | ||
326 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
327 | + } else { | ||
328 | + userRepository = value | ||
329 | + } | ||
330 | + user, err := userRepository.FindOne(map[string]interface{}{"userId": removeUserCommand.UserId}) | ||
331 | + if err != nil { | ||
332 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
333 | + } | ||
334 | + if user == nil { | ||
335 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeUserCommand.UserId))) | ||
336 | + } | ||
337 | + if user, err := userRepository.Remove(user); err != nil { | ||
338 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
339 | + } else { | ||
340 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
341 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
342 | + } | ||
343 | + return user, nil | ||
344 | + } | ||
345 | +} | ||
346 | + | ||
347 | +// 更新共创用户 | ||
348 | +func (userService *UserService) UpdateCooperator(updateCooperatorCommand *command.UpdateCooperatorCommand) (interface{}, error) { | ||
349 | + if err := updateCooperatorCommand.ValidateCommand(); err != nil { | ||
350 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
351 | + } | ||
352 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
353 | + if err != nil { | ||
354 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
355 | + } | ||
356 | + if err := transactionContext.StartTransaction(); err != nil { | ||
357 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
358 | + } | ||
359 | + defer func() { | ||
360 | + transactionContext.RollbackTransaction() | ||
361 | + }() | ||
362 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
363 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
364 | + } | ||
365 | + return nil, nil | ||
366 | +} | ||
367 | + | ||
368 | +// 更新我喜欢菜单列表 | ||
369 | +func (userService *UserService) UpdateFavoriteMenus(updateFavoriteMenusCommand *command.UpdateFavoriteMenusCommand) (interface{}, error) { | ||
370 | + if err := updateFavoriteMenusCommand.ValidateCommand(); err != nil { | ||
371 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
372 | + } | ||
373 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
374 | + if err != nil { | ||
375 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
376 | + } | ||
377 | + if err := transactionContext.StartTransaction(); err != nil { | ||
378 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
379 | + } | ||
380 | + defer func() { | ||
381 | + transactionContext.RollbackTransaction() | ||
382 | + }() | ||
383 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
384 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
385 | + } | ||
386 | + return nil, nil | ||
387 | +} | ||
388 | + | ||
389 | +// 更新 | ||
390 | +func (userService *UserService) UpdateUser(updateUserCommand *command.UpdateUserCommand) (interface{}, error) { | ||
391 | + if err := updateUserCommand.ValidateCommand(); err != nil { | ||
392 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
393 | + } | ||
394 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
395 | + if err != nil { | ||
396 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
397 | + } | ||
398 | + if err := transactionContext.StartTransaction(); err != nil { | ||
399 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
400 | + } | ||
401 | + defer func() { | ||
402 | + transactionContext.RollbackTransaction() | ||
403 | + }() | ||
404 | + var userRepository domain.UserRepository | ||
405 | + if value, err := factory.CreateUserRepository(map[string]interface{}{ | ||
406 | + "transactionContext": transactionContext, | ||
407 | + }); err != nil { | ||
408 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
409 | + } else { | ||
410 | + userRepository = value | ||
411 | + } | ||
412 | + user, err := userRepository.FindOne(map[string]interface{}{"userId": updateUserCommand.UserId}) | ||
413 | + if err != nil { | ||
414 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
415 | + } | ||
416 | + if user == nil { | ||
417 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateUserCommand.UserId))) | ||
418 | + } | ||
419 | + if err := user.Update(tool_funs.SimpleStructToMap(updateUserCommand)); err != nil { | ||
420 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
421 | + } | ||
422 | + if user, err := userRepository.Save(user); err != nil { | ||
423 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
424 | + } else { | ||
425 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
426 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
427 | + } | ||
428 | + return user, nil | ||
429 | + } | ||
430 | +} | ||
431 | + | ||
432 | +// 更新用户基础信息数据 | ||
433 | +func (userService *UserService) UpdateUsersBase(updateUsersBaseCommand *command.UpdateUsersBaseCommand) (interface{}, error) { | ||
434 | + if err := updateUsersBaseCommand.ValidateCommand(); err != nil { | ||
435 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
436 | + } | ||
437 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
438 | + if err != nil { | ||
439 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
440 | + } | ||
441 | + if err := transactionContext.StartTransaction(); err != nil { | ||
442 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
443 | + } | ||
444 | + defer func() { | ||
445 | + transactionContext.RollbackTransaction() | ||
446 | + }() | ||
447 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
448 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
449 | + } | ||
450 | + return nil, nil | ||
451 | +} | ||
452 | + | ||
453 | +func NewUserService(options map[string]interface{}) *UserService { | ||
454 | + newUserService := &UserService{} | ||
455 | + return newUserService | ||
456 | +} |
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/web/beego" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/command" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/query" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/service" | ||
8 | +) | ||
9 | + | ||
10 | +type UserController struct { | ||
11 | + beego.BaseController | ||
12 | +} | ||
13 | + | ||
14 | +func (controller *UserController) CreateUser() { | ||
15 | + userService := service.NewUserService(nil) | ||
16 | + createUserCommand := &command.CreateUserCommand{} | ||
17 | + controller.Unmarshal(createUserCommand) | ||
18 | + data, err := userService.CreateUser(createUserCommand) | ||
19 | + controller.Response(data, err) | ||
20 | +} | ||
21 | + | ||
22 | +func (controller *UserController) UpdateUser() { | ||
23 | + userService := service.NewUserService(nil) | ||
24 | + updateUserCommand := &command.UpdateUserCommand{} | ||
25 | + controller.Unmarshal(updateUserCommand) | ||
26 | + userId, _ := controller.GetInt64(":userId") | ||
27 | + updateUserCommand.UserId = userId | ||
28 | + data, err := userService.UpdateUser(updateUserCommand) | ||
29 | + controller.Response(data, err) | ||
30 | +} | ||
31 | + | ||
32 | +func (controller *UserController) GetUser() { | ||
33 | + userService := service.NewUserService(nil) | ||
34 | + getUserQuery := &query.GetUserQuery{} | ||
35 | + userId, _ := controller.GetInt64(":userId") | ||
36 | + getUserQuery.UserId = userId | ||
37 | + data, err := userService.GetUser(getUserQuery) | ||
38 | + controller.Response(data, err) | ||
39 | +} | ||
40 | + | ||
41 | +func (controller *UserController) RemoveUser() { | ||
42 | + userService := service.NewUserService(nil) | ||
43 | + removeUserCommand := &command.RemoveUserCommand{} | ||
44 | + controller.Unmarshal(removeUserCommand) | ||
45 | + userId, _ := controller.GetInt64(":userId") | ||
46 | + removeUserCommand.UserId = userId | ||
47 | + data, err := userService.RemoveUser(removeUserCommand) | ||
48 | + controller.Response(data, err) | ||
49 | +} | ||
50 | + | ||
51 | +func (controller *UserController) ListUser() { | ||
52 | + userService := service.NewUserService(nil) | ||
53 | + listUserQuery := &query.ListUserQuery{} | ||
54 | + data, err := userService.ListUser(listUserQuery) | ||
55 | + controller.Response(data, err) | ||
56 | +} | ||
57 | + | ||
58 | +func (controller *UserController) GetUserAccessMenus() { | ||
59 | + userService := service.NewUserService(nil) | ||
60 | + getUserAccessMenusQuery := &query.GetUserAccessMenusQuery{} | ||
61 | + userId, _ := controller.GetInt64(":userId") | ||
62 | + getUserAccessMenusQuery.UserId = userId | ||
63 | + menuCategory := controller.GetString("menuCategory") | ||
64 | + getUserAccessMenusQuery.MenuCategory = menuCategory | ||
65 | + data, err := userService.GetUserAccessMenus(getUserAccessMenusQuery) | ||
66 | + controller.Response(data, err) | ||
67 | +} | ||
68 | + | ||
69 | +func (controller *UserController) GetUserProfile() { | ||
70 | + userService := service.NewUserService(nil) | ||
71 | + getUserProfileQuery := &query.GetUserProfileQuery{} | ||
72 | + userId, _ := controller.GetInt64(":userId") | ||
73 | + getUserProfileQuery.UserId = userId | ||
74 | + data, err := userService.GetUserProfile(getUserProfileQuery) | ||
75 | + controller.Response(data, err) | ||
76 | +} | ||
77 | + | ||
78 | +func (controller *UserController) BatchAdd() { | ||
79 | + userService := service.NewUserService(nil) | ||
80 | + batchAddCommand := &command.BatchAddCommand{} | ||
81 | + controller.Unmarshal(batchAddCommand) | ||
82 | + data, err := userService.BatchAdd(batchAddCommand) | ||
83 | + controller.Response(data, err) | ||
84 | +} | ||
85 | + | ||
86 | +func (controller *UserController) BatchEnable() { | ||
87 | + userService := service.NewUserService(nil) | ||
88 | + batchEnableCommand := &command.BatchEnableCommand{} | ||
89 | + controller.Unmarshal(batchEnableCommand) | ||
90 | + data, err := userService.BatchEnable(batchEnableCommand) | ||
91 | + controller.Response(data, err) | ||
92 | +} | ||
93 | + | ||
94 | +func (controller *UserController) BatchResetPassword() { | ||
95 | + userService := service.NewUserService(nil) | ||
96 | + batchResetPasswordCommand := &command.BatchResetPasswordCommand{} | ||
97 | + controller.Unmarshal(batchResetPasswordCommand) | ||
98 | + data, err := userService.BatchResetPassword(batchResetPasswordCommand) | ||
99 | + controller.Response(data, err) | ||
100 | +} | ||
101 | + | ||
102 | +func (controller *UserController) UpdateUsersBase() { | ||
103 | + userService := service.NewUserService(nil) | ||
104 | + updateUsersBaseCommand := &command.UpdateUsersBaseCommand{} | ||
105 | + controller.Unmarshal(updateUsersBaseCommand) | ||
106 | + userId, _ := controller.GetInt64(":userId") | ||
107 | + updateUsersBaseCommand.UserId = userId | ||
108 | + data, err := userService.UpdateUsersBase(updateUsersBaseCommand) | ||
109 | + controller.Response(data, err) | ||
110 | +} | ||
111 | + | ||
112 | +func (controller *UserController) CreateCooperator() { | ||
113 | + userService := service.NewUserService(nil) | ||
114 | + createCooperatorCommand := &command.CreateCooperatorCommand{} | ||
115 | + controller.Unmarshal(createCooperatorCommand) | ||
116 | + data, err := userService.CreateCooperator(createCooperatorCommand) | ||
117 | + controller.Response(data, err) | ||
118 | +} | ||
119 | + | ||
120 | +func (controller *UserController) UpdateCooperator() { | ||
121 | + userService := service.NewUserService(nil) | ||
122 | + updateCooperatorCommand := &command.UpdateCooperatorCommand{} | ||
123 | + controller.Unmarshal(updateCooperatorCommand) | ||
124 | + userId, _ := controller.GetInt64(":userId") | ||
125 | + updateCooperatorCommand.UserId = userId | ||
126 | + data, err := userService.UpdateCooperator(updateCooperatorCommand) | ||
127 | + controller.Response(data, err) | ||
128 | +} |
pkg/port/beego/routers/user_router.go
0 → 100644
1 | +package routers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/port/beego/controllers" | ||
6 | +) | ||
7 | + | ||
8 | +func init() { | ||
9 | + web.Router("/user/", &controllers.UserController{}, "Post:CreateUser") | ||
10 | + web.Router("/user/:userId", &controllers.UserController{}, "Put:UpdateUser") | ||
11 | + web.Router("/user/:userId", &controllers.UserController{}, "Get:GetUser") | ||
12 | + web.Router("/user/:userId", &controllers.UserController{}, "Delete:RemoveUser") | ||
13 | + web.Router("/user/search", &controllers.UserController{}, "Post:ListUser") | ||
14 | + web.Router("/user/:userId/access-menus", &controllers.UserController{}, "Get:GetUserAccessMenus") | ||
15 | + web.Router("/user/:userId/profile", &controllers.UserController{}, "Get:GetUserProfile") | ||
16 | + web.Router("/user/batch-add", &controllers.UserController{}, "Post:BatchAdd") | ||
17 | + web.Router("/user/batch-enable", &controllers.UserController{}, "Post:BatchEnable") | ||
18 | + web.Router("/user/batch-reset-password", &controllers.UserController{}, "Post:BatchResetPassword") | ||
19 | + web.Router("/user/:userId/base-info", &controllers.UserController{}, "Put:UpdateUsersBase") | ||
20 | + web.Router("/user/cooperator", &controllers.UserController{}, "Post:CreateCooperator") | ||
21 | + web.Router("/user/cooperator/:userId", &controllers.UserController{}, "Put:UpdateCooperator") | ||
22 | +} |
1 | +package user | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("批量添加", func() { | ||
14 | + var userId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&userId), | ||
18 | + "INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id", | ||
19 | + "testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("批量添加", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "userType": "int", | ||
28 | + "user": "array", | ||
29 | + "password": "string", | ||
30 | + } | ||
31 | + httpExpect.POST("/user/batch-add"). | ||
32 | + WithJSON(body). | ||
33 | + Expect(). | ||
34 | + Status(http.StatusOK). | ||
35 | + JSON(). | ||
36 | + Object(). | ||
37 | + ContainsKey("code").ValueEqual("code", 0). | ||
38 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
39 | + ContainsKey("data").Value("data").Object() | ||
40 | + }) | ||
41 | + }) | ||
42 | + }) | ||
43 | + AfterEach(func() { | ||
44 | + _, err := pG.DB.Exec("DELETE FROM users WHERE true") | ||
45 | + Expect(err).NotTo(HaveOccurred()) | ||
46 | + }) | ||
47 | +}) |
1 | +package user | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("批量修改启用状态", func() { | ||
14 | + var userId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&userId), | ||
18 | + "INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id", | ||
19 | + "testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("批量修改启用状态", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "userIds": "array", | ||
28 | + "enableStatus": "int", | ||
29 | + } | ||
30 | + httpExpect.POST("/user/batch-enable"). | ||
31 | + WithJSON(body). | ||
32 | + Expect(). | ||
33 | + Status(http.StatusOK). | ||
34 | + JSON(). | ||
35 | + Object(). | ||
36 | + ContainsKey("code").ValueEqual("code", 0). | ||
37 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
38 | + ContainsKey("data").Value("data").Object() | ||
39 | + }) | ||
40 | + }) | ||
41 | + }) | ||
42 | + AfterEach(func() { | ||
43 | + _, err := pG.DB.Exec("DELETE FROM users WHERE true") | ||
44 | + Expect(err).NotTo(HaveOccurred()) | ||
45 | + }) | ||
46 | +}) |
1 | +package user | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("批量重置密码", func() { | ||
14 | + var userId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&userId), | ||
18 | + "INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id", | ||
19 | + "testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("批量重置密码", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "userIds": "array", | ||
28 | + "password": "string", | ||
29 | + } | ||
30 | + httpExpect.POST("/user/batch-reset-password"). | ||
31 | + WithJSON(body). | ||
32 | + Expect(). | ||
33 | + Status(http.StatusOK). | ||
34 | + JSON(). | ||
35 | + Object(). | ||
36 | + ContainsKey("code").ValueEqual("code", 0). | ||
37 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
38 | + ContainsKey("data").Value("data").Object() | ||
39 | + }) | ||
40 | + }) | ||
41 | + }) | ||
42 | + AfterEach(func() { | ||
43 | + _, err := pG.DB.Exec("DELETE FROM users WHERE true") | ||
44 | + Expect(err).NotTo(HaveOccurred()) | ||
45 | + }) | ||
46 | +}) |
1 | +package user | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("创建共创用户", func() { | ||
14 | + var userId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&userId), | ||
18 | + "INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id", | ||
19 | + "testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("创建共创用户", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "cooperationCompany": "string", | ||
28 | + "cooperationDeadline": "datetime", | ||
29 | + "email": "string", | ||
30 | + "enableStatus": "int", | ||
31 | + "userCode": "string", | ||
32 | + "userId": "int64", | ||
33 | + "userName": "string", | ||
34 | + "avatar": "string", | ||
35 | + "orgId": "int64", | ||
36 | + } | ||
37 | + httpExpect.POST("/user/cooperator"). | ||
38 | + WithJSON(body). | ||
39 | + Expect(). | ||
40 | + Status(http.StatusOK). | ||
41 | + JSON(). | ||
42 | + Object(). | ||
43 | + ContainsKey("code").ValueEqual("code", 0). | ||
44 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
45 | + ContainsKey("data").Value("data").Object() | ||
46 | + }) | ||
47 | + }) | ||
48 | + }) | ||
49 | + AfterEach(func() { | ||
50 | + _, err := pG.DB.Exec("DELETE FROM users WHERE true") | ||
51 | + Expect(err).NotTo(HaveOccurred()) | ||
52 | + }) | ||
53 | +}) |
1 | +package user | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + . "github.com/onsi/ginkgo" | ||
8 | + . "github.com/onsi/gomega" | ||
9 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
10 | +) | ||
11 | + | ||
12 | +var _ = Describe("创建", func() { | ||
13 | + Describe("提交数据创建", func() { | ||
14 | + Context("提交正确的新用户数据", func() { | ||
15 | + It("返回用户数据", func() { | ||
16 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
17 | + body := map[string]interface{}{ | ||
18 | + "companyId": "int64", | ||
19 | + "userType": "int", | ||
20 | + "userCode": "string", | ||
21 | + "organizationId": "int64", | ||
22 | + "departmentId": "int64", | ||
23 | + "userOrg": "array", | ||
24 | + "userRole": "array", | ||
25 | + "cooperationCompany": "string", | ||
26 | + "cooperationDeadline": "datetime", | ||
27 | + "enableStatus": "int", | ||
28 | + "password": "string", | ||
29 | + "userName": "string", | ||
30 | + "phone": "string", | ||
31 | + "avatar": "string", | ||
32 | + "email": "string", | ||
33 | + } | ||
34 | + httpExpect.POST("/user/"). | ||
35 | + WithJSON(body). | ||
36 | + Expect(). | ||
37 | + Status(http.StatusOK). | ||
38 | + JSON(). | ||
39 | + Object(). | ||
40 | + ContainsKey("code").ValueEqual("code", 0). | ||
41 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
42 | + ContainsKey("data").Value("data").Object(). | ||
43 | + ContainsKey("userId").ValueNotEqual("userId", BeZero()) | ||
44 | + }) | ||
45 | + }) | ||
46 | + }) | ||
47 | + AfterEach(func() { | ||
48 | + _, err := pG.DB.Exec("DELETE FROM users WHERE true") | ||
49 | + Expect(err).NotTo(HaveOccurred()) | ||
50 | + }) | ||
51 | +}) |
1 | +package user | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("返回用户有权限的菜单", func() { | ||
14 | + var userId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&userId), | ||
18 | + "INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id", | ||
19 | + "testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("返回用户有权限的菜单", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.GET("/user/{userId}/access-menus"). | ||
27 | + WithQuery("menuCategory", "string"). | ||
28 | + Expect(). | ||
29 | + Status(http.StatusOK). | ||
30 | + JSON(). | ||
31 | + Object(). | ||
32 | + ContainsKey("code").ValueEqual("code", 0). | ||
33 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
34 | + ContainsKey("data").Value("data").Object() | ||
35 | + }) | ||
36 | + }) | ||
37 | + }) | ||
38 | + AfterEach(func() { | ||
39 | + _, err := pG.DB.Exec("DELETE FROM users WHERE true") | ||
40 | + Expect(err).NotTo(HaveOccurred()) | ||
41 | + }) | ||
42 | +}) |
1 | +package user | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("获取用户概要数据", func() { | ||
14 | + var userId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&userId), | ||
18 | + "INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id", | ||
19 | + "testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("获取用户概要数据", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.GET("/user/{userId}/profile"). | ||
27 | + Expect(). | ||
28 | + Status(http.StatusOK). | ||
29 | + JSON(). | ||
30 | + Object(). | ||
31 | + ContainsKey("code").ValueEqual("code", 0). | ||
32 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
33 | + ContainsKey("data").Value("data").Object() | ||
34 | + }) | ||
35 | + }) | ||
36 | + }) | ||
37 | + AfterEach(func() { | ||
38 | + _, err := pG.DB.Exec("DELETE FROM users WHERE true") | ||
39 | + Expect(err).NotTo(HaveOccurred()) | ||
40 | + }) | ||
41 | +}) |
test/integration/beego/user/get_user_test.go
0 → 100644
1 | +package user | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("返回", func() { | ||
14 | + var userId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&userId), | ||
18 | + "INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id", | ||
19 | + "testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("根据userId参数返回用户", func() { | ||
23 | + Context("传入有效的userId", func() { | ||
24 | + It("返回用户数据", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.GET("/user/{userId}"). | ||
27 | + Expect(). | ||
28 | + Status(http.StatusOK). | ||
29 | + JSON(). | ||
30 | + Object(). | ||
31 | + ContainsKey("code").ValueEqual("code", 0). | ||
32 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
33 | + ContainsKey("data").Value("data").Object() | ||
34 | + }) | ||
35 | + }) | ||
36 | + }) | ||
37 | + AfterEach(func() { | ||
38 | + _, err := pG.DB.Exec("DELETE FROM users WHERE true") | ||
39 | + Expect(err).NotTo(HaveOccurred()) | ||
40 | + }) | ||
41 | +}) |
1 | +package user | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("返回列表", func() { | ||
14 | + var userId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&userId), | ||
18 | + "INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id", | ||
19 | + "testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("根据参数返回用户列表", func() { | ||
23 | + Context("传入有效的参数", func() { | ||
24 | + It("返回用户数据列表", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "offset": "int", | ||
28 | + "limit": "int", | ||
29 | + "companyId": "int64", | ||
30 | + "organizationId": "int64", | ||
31 | + "departmentId": "int64", | ||
32 | + "userName": "string", | ||
33 | + "depName": "string", | ||
34 | + "phone": "string", | ||
35 | + } | ||
36 | + httpExpect.POST("/user/search"). | ||
37 | + WithJSON(body). | ||
38 | + Expect(). | ||
39 | + Status(http.StatusOK). | ||
40 | + JSON(). | ||
41 | + Object(). | ||
42 | + ContainsKey("code").ValueEqual("code", 0). | ||
43 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
44 | + ContainsKey("data").Value("data").Object(). | ||
45 | + ContainsKey("count").ValueEqual("count", 1). | ||
46 | + ContainsKey("users").Value("users").Array() | ||
47 | + }) | ||
48 | + }) | ||
49 | + }) | ||
50 | + AfterEach(func() { | ||
51 | + _, err := pG.DB.Exec("DELETE FROM users WHERE true") | ||
52 | + Expect(err).NotTo(HaveOccurred()) | ||
53 | + }) | ||
54 | +}) |
1 | +package user | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("移除", func() { | ||
14 | + var userId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&userId), | ||
18 | + "INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id", | ||
19 | + "testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("根据参数移除", func() { | ||
23 | + Context("传入有效的userId", func() { | ||
24 | + It("返回被移除用户的数据", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.DELETE("/user/{userId}"). | ||
27 | + Expect(). | ||
28 | + Status(http.StatusOK). | ||
29 | + JSON(). | ||
30 | + Object(). | ||
31 | + ContainsKey("code").ValueEqual("code", 0). | ||
32 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
33 | + ContainsKey("data").Value("data").Object() | ||
34 | + }) | ||
35 | + }) | ||
36 | + }) | ||
37 | + AfterEach(func() { | ||
38 | + _, err := pG.DB.Exec("DELETE FROM users WHERE true") | ||
39 | + Expect(err).NotTo(HaveOccurred()) | ||
40 | + }) | ||
41 | +}) |
1 | +package user | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("更新共创用户", func() { | ||
14 | + var userId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&userId), | ||
18 | + "INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id", | ||
19 | + "testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("更新共创用户", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "cooperationCompany": "string", | ||
28 | + "cooperationDeadline": "datetime", | ||
29 | + "email": "string", | ||
30 | + "enableStatus": "int", | ||
31 | + "userCode": "string", | ||
32 | + "userName": "string", | ||
33 | + "avatar": "string", | ||
34 | + "orgId": "int64", | ||
35 | + } | ||
36 | + httpExpect.PUT("/user/cooperator/{userId}"). | ||
37 | + WithJSON(body). | ||
38 | + Expect(). | ||
39 | + Status(http.StatusOK). | ||
40 | + JSON(). | ||
41 | + Object(). | ||
42 | + ContainsKey("code").ValueEqual("code", 0). | ||
43 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
44 | + ContainsKey("data").Value("data").Object() | ||
45 | + }) | ||
46 | + }) | ||
47 | + }) | ||
48 | + AfterEach(func() { | ||
49 | + _, err := pG.DB.Exec("DELETE FROM users WHERE true") | ||
50 | + Expect(err).NotTo(HaveOccurred()) | ||
51 | + }) | ||
52 | +}) |
1 | +package user | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("更新", func() { | ||
14 | + var userId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&userId), | ||
18 | + "INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id", | ||
19 | + "testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("提交数据更新", func() { | ||
23 | + Context("提交正确的用户数据", func() { | ||
24 | + It("返回更新后的用户数据", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "organizationId": "int64", | ||
28 | + "departmentId": "int64", | ||
29 | + "userOrg": "array", | ||
30 | + "userRole": "array", | ||
31 | + "cooperationCompany": "string", | ||
32 | + "cooperationDeadline": "datetime", | ||
33 | + "enableStatus": "int", | ||
34 | + "userName": "string", | ||
35 | + "phone": "string", | ||
36 | + "avatar": "string", | ||
37 | + "email": "string", | ||
38 | + } | ||
39 | + httpExpect.PUT("/user/{userId}"). | ||
40 | + WithJSON(body). | ||
41 | + Expect(). | ||
42 | + Status(http.StatusOK). | ||
43 | + JSON(). | ||
44 | + Object(). | ||
45 | + ContainsKey("code").ValueEqual("code", 0). | ||
46 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
47 | + ContainsKey("data").Value("data").Object(). | ||
48 | + ContainsKey("userId").ValueEqual("userId", userId) | ||
49 | + }) | ||
50 | + }) | ||
51 | + }) | ||
52 | + AfterEach(func() { | ||
53 | + _, err := pG.DB.Exec("DELETE FROM users WHERE true") | ||
54 | + Expect(err).NotTo(HaveOccurred()) | ||
55 | + }) | ||
56 | +}) |
1 | +package user | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("更新用户基础信息数据", func() { | ||
14 | + var userId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&userId), | ||
18 | + "INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id", | ||
19 | + "testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("更新用户基础信息数据", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "userName": "string", | ||
28 | + "avatar": "string", | ||
29 | + "phone": "string", | ||
30 | + "email": "string", | ||
31 | + } | ||
32 | + httpExpect.PUT("/user/{userId}/base-info"). | ||
33 | + WithJSON(body). | ||
34 | + Expect(). | ||
35 | + Status(http.StatusOK). | ||
36 | + JSON(). | ||
37 | + Object(). | ||
38 | + ContainsKey("code").ValueEqual("code", 0). | ||
39 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
40 | + ContainsKey("data").Value("data").Object() | ||
41 | + }) | ||
42 | + }) | ||
43 | + }) | ||
44 | + AfterEach(func() { | ||
45 | + _, err := pG.DB.Exec("DELETE FROM users WHERE true") | ||
46 | + Expect(err).NotTo(HaveOccurred()) | ||
47 | + }) | ||
48 | +}) |
1 | +package user | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + "net/http/httptest" | ||
6 | + "testing" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/server/web" | ||
9 | + . "github.com/onsi/ginkgo" | ||
10 | + . "github.com/onsi/gomega" | ||
11 | + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
12 | + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/port/beego" | ||
13 | +) | ||
14 | + | ||
15 | +func TestUser(t *testing.T) { | ||
16 | + RegisterFailHandler(Fail) | ||
17 | + RunSpecs(t, "Beego Port User Correlations Test Case Suite") | ||
18 | +} | ||
19 | + | ||
20 | +var handler http.Handler | ||
21 | +var server *httptest.Server | ||
22 | + | ||
23 | +var _ = BeforeSuite(func() { | ||
24 | + handler = web.BeeApp.Handlers | ||
25 | + server = httptest.NewServer(handler) | ||
26 | +}) | ||
27 | + | ||
28 | +var _ = AfterSuite(func() { | ||
29 | + server.Close() | ||
30 | +}) |
-
请 注册 或 登录 后发表评论