Merge branch 'main-merge-base-a'
# Conflicts: # deploy/dev/docker-compose.yml # deploy/dev/envoy.yaml # desc/api/dispute.api # desc/api/review.api # desc/api/search.api
This commit is contained in:
@@ -28,7 +28,7 @@ func NewConfirmCloseOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||
}
|
||||
|
||||
func (l *ConfirmCloseOrderLogic) ConfirmCloseOrder(req *types.PathId) (resp *types.EmptyResp, err error) {
|
||||
if err = transitionOrderStatus(l.ctx, l.svcCtx, req.Id, "completed", false, true, true, false); err != nil {
|
||||
if err = transitionOrderStatus(l.ctx, l.svcCtx, req.Id, "pending_review", false, true, false, false); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package order
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -55,13 +57,39 @@ func toAPIOrder(in *orderservice.Orders) types.Order {
|
||||
return order
|
||||
}
|
||||
|
||||
// validTransitions defines the allowed order state transitions per the API spec.
|
||||
var validTransitions = map[string][]string{
|
||||
"pending_payment": {"pending_accept"},
|
||||
"pending_accept": {"in_progress", "cancelled"},
|
||||
"in_progress": {"pending_close", "disputed"},
|
||||
"pending_close": {"pending_review", "disputed"},
|
||||
"pending_review": {"completed"},
|
||||
"disputed": {"pending_review"},
|
||||
}
|
||||
|
||||
func transitionOrderStatus(ctx context.Context, svcCtx *svc.ServiceContext, orderID int64, toStatus string, setAcceptedAt bool, setClosedAt bool, setCompletedAt bool, setCancelledAt bool) error {
|
||||
current, err := svcCtx.OrderRpc.GetOrdersById(ctx, &orderservice.GetOrdersByIdReq{Id: orderID})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if current.GetOrders() == nil {
|
||||
return nil
|
||||
return errors.New("order not found")
|
||||
}
|
||||
|
||||
fromStatus := current.Orders.GetStatus()
|
||||
allowed, ok := validTransitions[fromStatus]
|
||||
if !ok {
|
||||
return fmt.Errorf("order status %q does not allow any transition", fromStatus)
|
||||
}
|
||||
found := false
|
||||
for _, s := range allowed {
|
||||
if s == toStatus {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return fmt.Errorf("transition from %q to %q is not allowed", fromStatus, toStatus)
|
||||
}
|
||||
|
||||
now := time.Now().Unix()
|
||||
@@ -87,7 +115,6 @@ func transitionOrderStatus(ctx context.Context, svcCtx *svc.ServiceContext, orde
|
||||
return err
|
||||
}
|
||||
|
||||
fromStatus := current.Orders.GetStatus()
|
||||
actorID, _ := contextj.UserIDFrom(ctx)
|
||||
actorRole := "system"
|
||||
if actorID > 0 {
|
||||
|
||||
@@ -5,6 +5,7 @@ package order
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"juwan-backend/app/order/rpc/orderservice"
|
||||
@@ -37,7 +38,7 @@ func (l *ReorderLogic) Reorder(req *types.PathId) (resp *types.CreateOrderResp,
|
||||
}
|
||||
oldOrder := oldOrderResp.GetOrders()
|
||||
if oldOrder == nil {
|
||||
return nil, nil
|
||||
return nil, errors.New("order not found")
|
||||
}
|
||||
|
||||
now := time.Now().Unix()
|
||||
|
||||
Reference in New Issue
Block a user