service.go 1.6 KB
package service

import (
	"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
	"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerCategory/query"
	"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
	"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)

type PartnerCategoryService struct {
}

func NewPartnerCategoryService(option map[string]interface{}) *PartnerCategoryService {
	newService := new(PartnerCategoryService)
	return newService
}

func (srv PartnerCategoryService) ListPartnerCategory(q query.ListPartnerCategoryCommand) (int, []domain.PartnerCategory, error) {
	//实际业务
	var err error
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
		return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
	}
	if err := transactionContext.StartTransaction(); err != nil {
		return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
	}
	defer func() {
		transactionContext.RollbackTransaction()
	}()
	var (
		categoryRepository domain.PartnerCategoryRepository
		categorys          []domain.PartnerCategory
		cnt                int
	)
	if categoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{
		"transactionContext": transactionContext,
	}); err != nil {
		return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
	}
	cnt, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{})
	if err != nil {
		return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
	}
	err = transactionContext.CommitTransaction()
	return cnt, categorys, nil
}