user_controller.go
2.5 KB
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
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/user/command"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/user/query"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/user/service"
)
type UserController struct {
beego.BaseController
}
func (controller *UserController) CreateUser() {
userService := service.NewUserService(nil)
createUserCommand := &command.CreateUserCommand{}
controller.Unmarshal(createUserCommand)
data, err := userService.CreateUser(createUserCommand)
controller.Response(data, err)
}
func (controller *UserController) UpdateUser() {
userService := service.NewUserService(nil)
updateUserCommand := &command.UpdateUserCommand{}
controller.Unmarshal(updateUserCommand)
userId, _ := controller.GetInt64(":userId")
updateUserCommand.UserId = userId
data, err := userService.UpdateUser(updateUserCommand)
controller.Response(data, err)
}
func (controller *UserController) GetUser() {
userService := service.NewUserService(nil)
getUserQuery := &query.GetUserQuery{}
userId, _ := controller.GetInt64(":userId")
getUserQuery.UserId = userId
data, err := userService.GetUser(getUserQuery)
controller.Response(data, err)
}
func (controller *UserController) RemoveUser() {
userService := service.NewUserService(nil)
removeUserCommand := &command.RemoveUserCommand{}
controller.Unmarshal(removeUserCommand)
userId, _ := controller.GetInt64(":userId")
removeUserCommand.UserId = userId
data, err := userService.RemoveUser(removeUserCommand)
controller.Response(data, err)
}
func (controller *UserController) ListUser() {
userService := service.NewUserService(nil)
listUserQuery := &query.ListUserQuery{}
offset, _ := controller.GetInt("offset")
listUserQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listUserQuery.Limit = limit
data, err := userService.ListUser(listUserQuery)
controller.Response(data, err)
}
func (controller *UserController) ConvertUserStatus() {
userService := service.NewUserService(nil)
convertUserStatusCommand := &command.ConvertUserStatusCommand{}
controller.Unmarshal(convertUserStatusCommand)
data, err := userService.ConvertUserStatus(convertUserStatusCommand)
controller.Response(data, err)
}
func (controller *UserController) SetPermission() {
userService := service.NewUserService(nil)
setPermissionCommand := &command.SetPermissionCommand{}
controller.Unmarshal(setPermissionCommand)
data, err := userService.SetPermission(setPermissionCommand)
controller.Response(data, err)
}