1
|
package controllers
|
1
|
package controllers
|
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
|
|
4
|
+ "github.com/astaxie/beego/context"
|
4
|
"github.com/linmadan/egglib-go/web/beego/utils"
|
5
|
"github.com/linmadan/egglib-go/web/beego/utils"
|
5
|
"github.com/tiptok/godevp/pkg/application/users/command"
|
6
|
"github.com/tiptok/godevp/pkg/application/users/command"
|
6
|
"github.com/tiptok/godevp/pkg/application/users/query"
|
7
|
"github.com/tiptok/godevp/pkg/application/users/query"
|
|
@@ -8,53 +9,58 @@ import ( |
|
@@ -8,53 +9,58 @@ import ( |
8
|
)
|
9
|
)
|
9
|
|
10
|
|
10
|
type UsersController struct {
|
11
|
type UsersController struct {
|
11
|
- utils.Controller
|
12
|
+ //utils.Controller
|
12
|
}
|
13
|
}
|
13
|
|
14
|
|
14
|
-func (controller *UsersController) CreateUsers() {
|
15
|
+func (controller *UsersController) CreateUsers(ctx *context.Context) {
|
|
|
16
|
+ contextController := utils.NewController(ctx)
|
15
|
usersService := service.NewUsersService(nil)
|
17
|
usersService := service.NewUsersService(nil)
|
16
|
createUsersCommand := &command.CreateUsersCommand{}
|
18
|
createUsersCommand := &command.CreateUsersCommand{}
|
17
|
- controller.Unmarshal(createUsersCommand)
|
19
|
+ contextController.Unmarshal(createUsersCommand)
|
18
|
data, err := usersService.CreateUsers(createUsersCommand)
|
20
|
data, err := usersService.CreateUsers(createUsersCommand)
|
19
|
- controller.Response(data, err)
|
21
|
+ contextController.Response(data, err)
|
20
|
}
|
22
|
}
|
21
|
|
23
|
|
22
|
-func (controller *UsersController) UpdateUsers() {
|
24
|
+func (controller *UsersController) UpdateUsers(ctx *context.Context) {
|
|
|
25
|
+ contextController := utils.NewController(ctx)
|
23
|
usersService := service.NewUsersService(nil)
|
26
|
usersService := service.NewUsersService(nil)
|
24
|
updateUsersCommand := &command.UpdateUsersCommand{}
|
27
|
updateUsersCommand := &command.UpdateUsersCommand{}
|
25
|
- controller.Unmarshal(updateUsersCommand)
|
|
|
26
|
- Id, _ := controller.GetInt64(":Id")
|
28
|
+ contextController.Unmarshal(updateUsersCommand)
|
|
|
29
|
+ Id, _ := contextController.GetInt64(":Id")
|
27
|
updateUsersCommand.UsersId = Id
|
30
|
updateUsersCommand.UsersId = Id
|
28
|
data, err := usersService.UpdateUsers(updateUsersCommand)
|
31
|
data, err := usersService.UpdateUsers(updateUsersCommand)
|
29
|
- controller.Response(data, err)
|
32
|
+ contextController.Response(data, err)
|
30
|
}
|
33
|
}
|
31
|
|
34
|
|
32
|
-func (controller *UsersController) GetUsers() {
|
|
|
33
|
- usersService := service.NewUsersService(map[string]interface{}{"context": controller.Ctx.Request.Context()})
|
35
|
+func (controller *UsersController) GetUsers(ctx *context.Context) {
|
|
|
36
|
+ contextController := utils.NewController(ctx)
|
|
|
37
|
+ usersService := service.NewUsersService(map[string]interface{}{"context": ctx.Request.Context()})
|
34
|
getUsersQuery := &query.GetUsersQuery{}
|
38
|
getUsersQuery := &query.GetUsersQuery{}
|
35
|
- Id, _ := controller.GetInt64(":Id")
|
39
|
+ Id, _ := contextController.GetInt64(":Id")
|
36
|
getUsersQuery.UsersId = Id
|
40
|
getUsersQuery.UsersId = Id
|
37
|
data, err := usersService.GetUsers(getUsersQuery)
|
41
|
data, err := usersService.GetUsers(getUsersQuery)
|
38
|
- controller.Response(data, err)
|
42
|
+ contextController.Response(data, err)
|
39
|
}
|
43
|
}
|
40
|
|
44
|
|
41
|
-func (controller *UsersController) RemoveUsers() {
|
45
|
+func (controller *UsersController) RemoveUsers(ctx *context.Context) {
|
|
|
46
|
+ contextController := utils.NewController(ctx)
|
42
|
usersService := service.NewUsersService(nil)
|
47
|
usersService := service.NewUsersService(nil)
|
43
|
removeUsersCommand := &command.RemoveUsersCommand{}
|
48
|
removeUsersCommand := &command.RemoveUsersCommand{}
|
44
|
- controller.Unmarshal(removeUsersCommand)
|
|
|
45
|
- Id, _ := controller.GetInt64(":Id")
|
49
|
+ contextController.Unmarshal(removeUsersCommand)
|
|
|
50
|
+ Id, _ := contextController.GetInt64(":Id")
|
46
|
removeUsersCommand.UsersId = Id
|
51
|
removeUsersCommand.UsersId = Id
|
47
|
data, err := usersService.RemoveUsers(removeUsersCommand)
|
52
|
data, err := usersService.RemoveUsers(removeUsersCommand)
|
48
|
- controller.Response(data, err)
|
53
|
+ contextController.Response(data, err)
|
49
|
}
|
54
|
}
|
50
|
|
55
|
|
51
|
-func (controller *UsersController) ListUsers() {
|
56
|
+func (controller *UsersController) ListUsers(ctx *context.Context) {
|
|
|
57
|
+ contextController := utils.NewController(ctx)
|
52
|
usersService := service.NewUsersService(nil)
|
58
|
usersService := service.NewUsersService(nil)
|
53
|
listUsersQuery := &query.ListUsersQuery{}
|
59
|
listUsersQuery := &query.ListUsersQuery{}
|
54
|
- offset, _ := controller.GetInt("offset")
|
60
|
+ offset, _ := contextController.GetInt("offset")
|
55
|
listUsersQuery.Offset = offset
|
61
|
listUsersQuery.Offset = offset
|
56
|
- limit, _ := controller.GetInt("limit")
|
62
|
+ limit, _ := contextController.GetInt("limit")
|
57
|
listUsersQuery.Limit = limit
|
63
|
listUsersQuery.Limit = limit
|
58
|
data, err := usersService.ListUsers(listUsersQuery)
|
64
|
data, err := usersService.ListUsers(listUsersQuery)
|
59
|
- controller.Response(data, err)
|
65
|
+ contextController.Response(data, err)
|
60
|
} |
66
|
} |