作者 yangfu

add order domain service

... ... @@ -2,8 +2,10 @@ 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"
)
... ... @@ -14,6 +16,24 @@ type CancelOrderService struct {
}
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
}
... ...
... ... @@ -2,8 +2,10 @@ 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"
)
... ... @@ -14,6 +16,24 @@ type ReceivingGoodsService struct {
}
func (service *ReceivingGoodsService) Receiving(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.Receive(); 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
}
... ...
... ... @@ -2,8 +2,10 @@ 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"
)
... ... @@ -14,7 +16,25 @@ type ReturnGoodsService struct {
}
func (service *ReturnGoodsService) Return(orderId int64) (*domain.Order, error) {
panic("implement me")
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.Return(); 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 NewReturnGoodsService(transactionContext *pgTransaction.TransactionContext) (*ReturnGoodsService, error) {
... ...
... ... @@ -2,8 +2,10 @@ 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"
)
... ... @@ -14,6 +16,24 @@ type ShippingGoodsService struct {
}
func (service *ShippingGoodsService) Shipping(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.Shipping(); 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
}
... ...