pg_cancel_order_service.go
1.5 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
48
package domainService
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/repository"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
)
type CancelOrderService struct {
coreDomain.BaseEventPublisher
transactionContext *pgTransaction.TransactionContext
}
func (service *CancelOrderService) Cancel(orderId int64) (*domain.Order, error) {
var orderRepository domain.OrderRepository
if value, err := repository.NewOrderRepository(service.transactionContext); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
orderRepository = value
}
order, err := orderRepository.FindOne(map[string]interface{}{"orderId": orderId})
if err != nil {
return nil, err
}
if err := order.Cancel(); err != nil {
return nil, err
}
if order, err := orderRepository.Save(order); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
return order, nil
}
return nil, nil
}
func NewCancelOrderService(transactionContext *pgTransaction.TransactionContext) (*CancelOrderService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &CancelOrderService{
transactionContext: transactionContext,
}, nil
}
}