menu_controller.go 2.2 KB
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.ParentId, _ = controller.GetInt64("parentId", 0)
	listMenuQuery.MenuName = controller.GetString("menuName")
	listMenuQuery.StructType = controller.GetString("structType")
	data, err := menuService.ListMenu(listMenuQuery)
	controller.Response(data, err)
}