su_money_controller.go 2.9 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/query"
	"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/service"
)

type SuMoneyController struct {
	beego.Controller
}

func (controller *SuMoneyController) GetSuMoneyTransactionRecord() {
	suMoneyService := service.NewSuMoneyService(nil)
	getSuMoneyTransactionRecordQuery := &query.GetSuMoneyTransactionRecordQuery{}
	suMoneyTransactionRecordId, _ := controller.GetInt64(":suMoneyTransactionRecordId")
	getSuMoneyTransactionRecordQuery.SuMoneyTransactionRecordId = suMoneyTransactionRecordId
	data, err := suMoneyService.GetSuMoneyTransactionRecord(getSuMoneyTransactionRecordQuery)
	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) 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()
}

func (controller *SuMoneyController) SuMoneyTransactionRecordStatistics() {
	suMoneyService := service.NewSuMoneyService(nil)
	suMoneyTransactionRecordStatisticsCommand := &command.SuMoneyTransactionRecordStatisticsCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), suMoneyTransactionRecordStatisticsCommand)
	data, err := suMoneyService.SuMoneyTransactionRecordStatistics(suMoneyTransactionRecordStatisticsCommand)
	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()
}