credit_account_controller.go 5.1 KB
package controllers

import (
	"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 {
	BaseController
}

func (controller *CreditAccountController) CreateCreditAccount() {
	creditAccountService := service.NewCreditAccountService(nil)
	createCreditAccountCommand := &command.CreateCreditAccountCommand{}
	_ = controller.Unmarshal(createCreditAccountCommand)
	header := controller.GetRequestHeader(controller.Ctx)
	createCreditAccountCommand.CompanyId = header.CompanyId
	createCreditAccountCommand.OrgId = header.OrgId
	createCreditAccountCommand.UserId = header.UserId
	createCreditAccountCommand.UserBaseId = header.UserBaseId
	data, err := creditAccountService.CreateCreditAccount(createCreditAccountCommand)
	controller.Response(data, err)
}

func (controller *CreditAccountController) UpdateCreditAccount() {
	creditAccountService := service.NewCreditAccountService(nil)
	updateCreditAccountCommand := &command.UpdateCreditAccountCommand{}
	_ = controller.Unmarshal(updateCreditAccountCommand)
	header := controller.GetRequestHeader(controller.Ctx)
	updateCreditAccountCommand.CompanyId = header.CompanyId
	updateCreditAccountCommand.OrgId = header.OrgId
	updateCreditAccountCommand.UserId = header.UserId
	updateCreditAccountCommand.UserBaseId = header.UserBaseId
	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{}
	header := controller.GetRequestHeader(controller.Ctx)
	getCreditAccountQuery.CompanyId = header.CompanyId
	getCreditAccountQuery.OrgId = header.OrgId
	getCreditAccountQuery.UserId = header.UserId
	getCreditAccountQuery.UserBaseId = header.UserBaseId
	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)
	header := controller.GetRequestHeader(controller.Ctx)
	removeCreditAccountCommand.CompanyId = header.CompanyId
	removeCreditAccountCommand.OrgId = header.OrgId
	removeCreditAccountCommand.UserId = header.UserId
	removeCreditAccountCommand.UserBaseId = header.UserBaseId
	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{}
	header := controller.GetRequestHeader(controller.Ctx)
	searchCreditAccountQuery.CompanyId = header.CompanyId
	searchCreditAccountQuery.OrgId = header.OrgId
	searchCreditAccountQuery.UserId = header.UserId
	searchCreditAccountQuery.UserBaseId = header.UserBaseId
	data, err := creditAccountService.SearchCreditAccount(searchCreditAccountQuery)
	controller.Response(data, err)
}

func (controller *CreditAccountController) PayCreditAccount() {
	creditAccountService := service.NewCreditAccountService(nil)
	payCreditAccountCommand := &command.PayCreditAccountCommand{}
	_ = controller.Unmarshal(payCreditAccountCommand)
	header := controller.GetRequestHeader(controller.Ctx)
	payCreditAccountCommand.CompanyId = header.CompanyId
	payCreditAccountCommand.OrgId = header.OrgId
	payCreditAccountCommand.UserId = header.UserId
	payCreditAccountCommand.UserBaseId = header.UserBaseId
	data, err := creditAccountService.PayCreditAccount(payCreditAccountCommand)
	controller.Response(data, err)
}

func (controller *CreditAccountController) ListCreditAccount() {
	creditAccountService := service.NewCreditAccountService(nil)
	listCreditAccountQuery := &query.ListCreditAccountQuery{}
	header := controller.GetRequestHeader(controller.Ctx)
	listCreditAccountQuery.CompanyId = header.CompanyId
	listCreditAccountQuery.OrgId = header.OrgId
	listCreditAccountQuery.UserId = header.UserId
	listCreditAccountQuery.UserBaseId = header.UserBaseId
	pageSize, _ := controller.GetInt64("pageSize")
	listCreditAccountQuery.PageSize = pageSize
	pageNumber, _ := controller.GetInt64("pageNumber")
	listCreditAccountQuery.PageNumber = pageNumber
	data, err := creditAccountService.ListCreditAccount(listCreditAccountQuery)
	controller.Response(data, err)
}