workshop_controller.go 3.4 KB
package controllers

import (
	"github.com/linmadan/egglib-go/web/beego"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/workshop/command"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/workshop/query"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/workshop/service"
)

type WorkshopController struct {
	beego.BaseController
}

func (controller *WorkshopController) CreateWorkshop() {
	workshopService := service.NewWorkshopService(nil)
	createWorkshopCommand := &command.CreateWorkshopCommand{}
	Must(controller.Unmarshal(createWorkshopCommand))
	data, err := workshopService.CreateWorkshop(ParseOperateInfo(controller.BaseController), createWorkshopCommand)
	controller.Response(data, err)
}

func (controller *WorkshopController) UpdateWorkshop() {
	workshopService := service.NewWorkshopService(nil)
	updateWorkshopCommand := &command.UpdateWorkshopCommand{}
	Must(controller.Unmarshal(updateWorkshopCommand))
	workshopId, _ := controller.GetInt(":workshopId")
	updateWorkshopCommand.WorkshopId = workshopId
	data, err := workshopService.UpdateWorkshop(updateWorkshopCommand)
	controller.Response(data, err)
}

func (controller *WorkshopController) GetWorkshop() {
	workshopService := service.NewWorkshopService(nil)
	getWorkshopQuery := &query.GetWorkshopQuery{}
	workshopId, _ := controller.GetInt(":workshopId")
	getWorkshopQuery.WorkshopId = workshopId
	data, err := workshopService.GetWorkshop(getWorkshopQuery)
	controller.Response(data, err)
}

func (controller *WorkshopController) RemoveWorkshop() {
	workshopService := service.NewWorkshopService(nil)
	removeWorkshopCommand := &command.RemoveWorkshopCommand{}
	controller.Unmarshal(removeWorkshopCommand)
	workshopId, _ := controller.GetInt(":workshopId")
	removeWorkshopCommand.WorkshopId = workshopId
	data, err := workshopService.RemoveWorkshop(removeWorkshopCommand)
	controller.Response(data, err)
}

func (controller *WorkshopController) ListWorkshop() {
	workshopService := service.NewWorkshopService(nil)
	listWorkshopQuery := &query.ListWorkshopQuery{}
	offset, _ := controller.GetInt("offset")
	listWorkshopQuery.Offset = offset
	limit, _ := controller.GetInt("limit")
	listWorkshopQuery.Limit = limit
	data, err := workshopService.ListWorkshop(listWorkshopQuery)
	controller.Response(data, err)
}

func (controller *WorkshopController) SearchWorkshop() {
	workshopService := service.NewWorkshopService(nil)
	listWorkshopQuery := &query.SearchWorkshopQuery{}
	Must(controller.Unmarshal(listWorkshopQuery))
	data, err := workshopService.SearchWorkshop(ParseOperateInfo(controller.BaseController), listWorkshopQuery)
	controller.Response(data, err)
}

func (controller *WorkshopController) SelectorWorkshop() {
	workshopService := service.NewWorkshopService(nil)
	listWorkshopQuery := &query.SearchWorkshopQuery{}
	Must(controller.Unmarshal(listWorkshopQuery))
	data, err := workshopService.SearchWorkshop(ParseOperateInfo(controller.BaseController), listWorkshopQuery)
	controller.Response(data, err)
}

func (controller *WorkshopController) SelectorWorkshopSection() {
	workshopService := service.NewWorkshopService(nil)
	getWorkshopQuery := &query.GetWorkshopQuery{}
	Must(controller.Unmarshal(getWorkshopQuery))
	data, err := workshopService.SelectorWorkshopSection(ParseOperateInfo(controller.BaseController), getWorkshopQuery)
	controller.Response(data, err)
}