menu_controller.go
2.1 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
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/mmm-go-pp/terms/pkg/application/menu/command"
"gitlab.fjmaimaimai.com/mmm-go-pp/terms/pkg/application/menu/query"
"gitlab.fjmaimaimai.com/mmm-go-pp/terms/pkg/application/menu/service"
)
type MenuController struct {
beego.BaseController
}
func (controller *MenuController) CreateMenu() {
menuService := service.NewMenuService(nil)
createMenuCommand := &command.CreateMenuCommand{}
controller.Unmarshal(createMenuCommand)
data, err := menuService.CreateMenu(createMenuCommand)
controller.Response(data, err)
}
func (controller *MenuController) UpdateMenu() {
menuService := service.NewMenuService(nil)
updateMenuCommand := &command.UpdateMenuCommand{}
controller.Unmarshal(updateMenuCommand)
Id, _ := controller.GetInt64(":menuId")
updateMenuCommand.MenuId = Id
data, err := menuService.UpdateMenu(updateMenuCommand)
controller.Response(data, err)
}
func (controller *MenuController) GetMenu() {
menuService := service.NewMenuService(nil)
getMenuQuery := &query.GetMenuQuery{}
Id, _ := controller.GetInt64(":menuId")
getMenuQuery.MenuId = Id
data, err := menuService.GetMenu(getMenuQuery)
controller.Response(data, err)
}
func (controller *MenuController) RemoveMenu() {
menuService := service.NewMenuService(nil)
removeMenuCommand := &command.RemoveMenuCommand{}
controller.Unmarshal(removeMenuCommand)
Id, _ := controller.GetInt64(":menuId")
removeMenuCommand.MenuId = Id
data, err := menuService.RemoveMenu(removeMenuCommand)
controller.Response(data, err)
}
func (controller *MenuController) ListMenu() {
menuService := service.NewMenuService(nil)
listMenuQuery := &query.ListMenuQuery{}
offset, _ := controller.GetInt("offset")
listMenuQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listMenuQuery.Limit = limit
listMenuQuery.MenuCategory = controller.GetString("menuCategory")
listMenuQuery.MenuParentId, _ = controller.GetInt64("parentId", 0)
listMenuQuery.MenuName = controller.GetString("menuName")
data, err := menuService.ListMenu(listMenuQuery)
controller.Response(data, err)
}