menu_controller.go 3.5 KB
package backgroud_client

import (
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/menu/command"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/menu/query"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/menu/service"
)

type MenuController struct {
	baseController
}

func (controller *MenuController) CreateMenu() {
	menuService := service.NewMenuService(nil)
	createMenuCommand := &command.CreateMenuCommand{}
	controller.Unmarshal(createMenuCommand)
	createMenuCommand.Operator = controller.GetOperator()
	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
	updateMenuCommand.Operator = controller.GetOperator()
	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
	getMenuQuery.Operator = controller.GetOperator()
	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
	removeMenuCommand.Operator = controller.GetOperator()
	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")
	listMenuQuery.Operator = controller.GetOperator()
	data, err := menuService.ListMenu(listMenuQuery)
	controller.Response(data, err)
}

func (controller *MenuController) SearchMenu() {
	menuService := service.NewMenuService(nil)
	listMenuQuery := &query.ListMenuQuery{}
	controller.Unmarshal(listMenuQuery)
	listMenuQuery.Offset = 0
	listMenuQuery.Limit = 0
	listMenuQuery.Operator = controller.GetOperator()
	data, err := menuService.ListMenu(listMenuQuery)
	controller.Response(data, err)
}

func (controller *MenuController) BatchDeleteMenu() {
	menuService := service.NewMenuService(nil)
	batchDeleteMenuCommand := &command.BatchDeleteMenuCommand{}
	controller.Unmarshal(batchDeleteMenuCommand)
	batchDeleteMenuCommand.Operator = controller.GetOperator()
	data, err := menuService.BatchDeleteMenu(batchDeleteMenuCommand)
	controller.Response(data, err)
}

func (controller *MenuController) BatchEnableMenu() {
	menuService := service.NewMenuService(nil)
	batchEnableMenu := &command.BatchEnableMenuCommand{}
	controller.Unmarshal(batchEnableMenu)
	batchEnableMenu.Operator = controller.GetOperator()
	data, err := menuService.BatchEnableMenu(batchEnableMenu)
	controller.Response(data, err)
}