order_controller.go 3.2 KB
package controllers

import (
	"github.com/linmadan/egglib-go/web/beego"
	"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/order/command"
	"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/order/query"
	"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/order/service"
)

type OrderController struct {
	beego.BaseController
}

func (controller *OrderController) CreateOrder() {
	orderService := service.NewOrderService(nil)
	createOrderCommand := &command.CreateOrderCommand{}
	_ = controller.Unmarshal(createOrderCommand)
	data, err := orderService.CreateOrder(createOrderCommand)
	controller.Response(data, err)
}

func (controller *OrderController) UpdateOrder() {
	orderService := service.NewOrderService(nil)
	updateOrderCommand := &command.UpdateOrderCommand{}
	_ = controller.Unmarshal(updateOrderCommand)
	orderId, _ := controller.GetInt64(":orderId")
	updateOrderCommand.OrderId = orderId
	data, err := orderService.UpdateOrder(updateOrderCommand)
	controller.Response(data, err)
}

func (controller *OrderController) GetOrder() {
	orderService := service.NewOrderService(nil)
	getOrderQuery := &query.GetOrderQuery{}
	orderId, _ := controller.GetInt64(":orderId")
	getOrderQuery.OrderId = orderId
	data, err := orderService.GetOrder(getOrderQuery)
	controller.Response(data, err)
}

func (controller *OrderController) RemoveOrder() {
	orderService := service.NewOrderService(nil)
	removeOrderCommand := &command.RemoveOrderCommand{}
	_ = controller.Unmarshal(removeOrderCommand)
	orderId, _ := controller.GetInt64(":orderId")
	removeOrderCommand.OrderId = orderId
	data, err := orderService.RemoveOrder(removeOrderCommand)
	controller.Response(data, err)
}

func (controller *OrderController) ListOrder() {
	orderService := service.NewOrderService(nil)
	listOrderQuery := &query.ListOrderQuery{}
	offset, _ := controller.GetInt("offset")
	listOrderQuery.Offset = offset
	limit, _ := controller.GetInt("limit")
	listOrderQuery.Limit = limit
	data, err := orderService.ListOrder(listOrderQuery)
	controller.Response(data, err)
}

func (controller *OrderController) Shipping() {
	orderService := service.NewOrderService(nil)
	shippingCmd := &command.ShippingGoodsCommand{}
	_ = controller.Unmarshal(shippingCmd)
	orderId, _ := controller.GetInt(":orderId")
	shippingCmd.OrderId = orderId
	data, err := orderService.ShippingGoods(shippingCmd)
	controller.Response(data, err)
}

func (controller *OrderController) ReceiveGoods() {
	orderService := service.NewOrderService(nil)
	createOrderCommand := &command.ReceiveGoodsCommand{}
	_ = controller.Unmarshal(createOrderCommand)
	data, err := orderService.ReceiveGoods(createOrderCommand)
	controller.Response(data, err)
}

func (controller *OrderController) CancelOrder() {
	orderService := service.NewOrderService(nil)
	createOrderCommand := &command.CancelOrderCommand{}
	_ = controller.Unmarshal(createOrderCommand)
	data, err := orderService.CancelOrder(createOrderCommand)
	controller.Response(data, err)
}

func (controller *OrderController) ReturnGoods() {
	orderService := service.NewOrderService(nil)
	createOrderCommand := &command.ReturnGoodsCommand{}
	_ = controller.Unmarshal(createOrderCommand)
	data, err := orderService.ReturnGoods(createOrderCommand)
	controller.Response(data, err)
}