service.go
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
}