su_money_controller.go 1.5 KB
package controllers

import (
	"encoding/json"

	"github.com/astaxie/beego"
	"github.com/linmadan/egglib-go/web/beego/utils"
	"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/command"
	"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/service"
)

type SuMoneyController struct {
	beego.Controller
}

func (controller *SuMoneyController) ExchangeSuMoney() {
	suMoneyService := service.NewSuMoneyService(nil)
	exchangeSuMoneyCommand := &command.ExchangeSuMoneyCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), exchangeSuMoneyCommand)
	data, err := suMoneyService.ExchangeSuMoney(exchangeSuMoneyCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

func (controller *SuMoneyController) SearchSuMoneyTransactionRecord() {
	suMoneyService := service.NewSuMoneyService(nil)
	searchSuMoneyTransactionRecordCommand := &command.SearchSuMoneyTransactionRecordCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), searchSuMoneyTransactionRecordCommand)
	data, err := suMoneyService.SearchSuMoneyTransactionRecord(searchSuMoneyTransactionRecordCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}