workshop_controller.go 2.3 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{}
	controller.Unmarshal(createWorkshopCommand)
	data, err := workshopService.CreateWorkshop(createWorkshopCommand)
	controller.Response(data, err)
}

func (controller *WorkshopController) UpdateWorkshop() {
	workshopService := service.NewWorkshopService(nil)
	updateWorkshopCommand := &command.UpdateWorkshopCommand{}
	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)
}