forked from ebhomengo/niki
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package service
|
|
|
|
import (
|
|
entity "git.gocasts.ir/ebhomengo/niki/domain/order/entity"
|
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
|
types "git.gocasts.ir/ebhomengo/niki/types"
|
|
)
|
|
|
|
type Service struct {
|
|
repo Repo
|
|
}
|
|
|
|
type Repo interface {
|
|
CreateOrder(order entity.Order, orderItems []entity.OrderItem) (types.ID, error)
|
|
UpdateOrderProcessStatus(orderID types.ID, status string) (bool, error)
|
|
GetShipping() ([]entity.Shipping, error)
|
|
}
|
|
|
|
func New(orderRepo Repo) Service {
|
|
return Service{repo: orderRepo}
|
|
}
|
|
|
|
func (s *Service) CreateOrder(order entity.Order, orderItems []entity.OrderItem) (types.ID, error) {
|
|
const Op = "domain.order.service.order.CreateOrder"
|
|
orderID, err := s.repo.CreateOrder(order, orderItems)
|
|
|
|
if err != nil {
|
|
return 0, richerror.New(Op).WithErr(err)
|
|
}
|
|
|
|
return orderID, nil
|
|
}
|
|
|
|
func (s *Service) UpdateOrderProcessStatus(orderID types.ID, status string) (bool, error) {
|
|
|
|
const Op = "domain.order.service.order.UpdateOrderProcessStatus"
|
|
_, err := s.repo.UpdateOrderProcessStatus(orderID, status)
|
|
if err != nil {
|
|
return false, richerror.New(Op).WithErr(err)
|
|
}
|
|
|
|
return true, nil
|
|
}
|