credit_account_controller.go 3.3 KB
package controllers

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

type CreditAccountController struct {
	beego.BaseController
}

func (controller *CreditAccountController) CreateCreditAccount() {
	creditAccountService := service.NewCreditAccountService(nil)
	createCreditAccountCommand := &command.CreateCreditAccountCommand{}
	controller.Unmarshal(createCreditAccountCommand)
	data, err := creditAccountService.CreateCreditAccount(createCreditAccountCommand)
	controller.Response(data, err)
}

func (controller *CreditAccountController) UpdateCreditAccount() {
	creditAccountService := service.NewCreditAccountService(nil)
	updateCreditAccountCommand := &command.UpdateCreditAccountCommand{}
	controller.Unmarshal(updateCreditAccountCommand)
	creditAccountId, _ := controller.GetInt64(":creditAccountId")
	updateCreditAccountCommand.CreditAccountId = creditAccountId
	data, err := creditAccountService.UpdateCreditAccount(updateCreditAccountCommand)
	controller.Response(data, err)
}

func (controller *CreditAccountController) GetCreditAccount() {
	creditAccountService := service.NewCreditAccountService(nil)
	getCreditAccountQuery := &query.GetCreditAccountQuery{}
	creditAccountId, _ := controller.GetInt64(":creditAccountId")
	getCreditAccountQuery.CreditAccountId = creditAccountId
	data, err := creditAccountService.GetCreditAccount(getCreditAccountQuery)
	controller.Response(data, err)
}

func (controller *CreditAccountController) RemoveCreditAccount() {
	creditAccountService := service.NewCreditAccountService(nil)
	removeCreditAccountCommand := &command.RemoveCreditAccountCommand{}
	controller.Unmarshal(removeCreditAccountCommand)
	creditAccountId, _ := controller.GetInt64(":creditAccountId")
	removeCreditAccountCommand.CreditAccountId = creditAccountId
	data, err := creditAccountService.RemoveCreditAccount(removeCreditAccountCommand)
	controller.Response(data, err)
}

func (controller *CreditAccountController) SearchCreditAccount() {
	creditAccountService := service.NewCreditAccountService(nil)
	searchCreditAccountQuery := &query.SearchCreditAccountQuery{}
	data, err := creditAccountService.SearchCreditAccount(searchCreditAccountQuery)
	controller.Response(data, err)
}

func (controller *CreditAccountController) PayCreditAccount() {
	creditAccountService := service.NewCreditAccountService(nil)
	payCreditAccountCommand := &command.PayCreditAccountCommand{}
	controller.Unmarshal(payCreditAccountCommand)
	data, err := creditAccountService.PayCreditAccount(payCreditAccountCommand)
	controller.Response(data, err)
}

func (controller *CreditAccountController) ListCreditAccount() {
	creditAccountService := service.NewCreditAccountService(nil)
	listCreditAccountQuery := &query.ListCreditAccountQuery{}
	offset, _ := controller.GetInt("offset")
	listCreditAccountQuery.Offset = offset
	limit, _ := controller.GetInt("limit")
	listCreditAccountQuery.Limit = limit
	data, err := creditAccountService.ListCreditAccount(listCreditAccountQuery)
	controller.Response(data, err)
}