arch-atlas

Order Service

core/services/order_service.dart

data

Overview

Four endpoints: getOrders (customer list), getOrder (single, role-aware), getSellerOrders (vendor list with field selection), cancelSellerOrder (vendor POST cancel).

User Flow

  1. getOrders → GET /store/orders with authScope:'customer'.
  2. getOrder routes path by isSeller flag and attaches the seller field-selection query.
  3. getSellerOrders → GET /vendor/orders?fields=… + optional status filter.
  4. cancelSellerOrder → POST /vendor/orders/{id}/cancel.
  5. All list responses parse orders one at a time and skip-on-error to avoid one bad row killing the whole list.

Cases & Edge Cases

  • Per-order parse failures are debugPrinted and the row is dropped — they never crash the controller.
  • Reversed list ordering is applied here (newest first) — controllers and screens rely on this invariant.
  • Seller endpoints rely on the DioHelper path heuristic (/vendor/* → seller token) to attach the right Authorization header.

Code References

  • lib/src/core/services/order_service.dart:12 // getOrders
  • lib/src/core/services/order_service.dart:44 // getOrder
  • lib/src/core/services/order_service.dart:76 // getSellerOrders
  • lib/src/core/services/order_service.dart:117 // cancelSellerOrder

API Calls

  • GET/store/ordersno status

    Customer order list (newest-first).

    Response
    { orders: Order[] }
    lib/src/features/shared/orders/views/orders_screen.dart

    auth: customer. Service reverses to newest-first client-side.

  • GET/store/orders/:orderIdno status

    Customer order detail.

    Response
    { order: Order }
    lib/src/features/shared/orders/views/order_detail_screen.dart

    auth: customer.

  • GET/vendor/orders?fields=*customer,+payment_status,*split_order_payment&status=:statusno status

    Seller order list with embedded customer + split-payment info.

    Response
    { orders: Order[] /* with customer + splitOrderPayment */, count, offset, limit }
    lib/src/features/shared/orders/views/orders_screen.dart // role=freelancer

    auth: seller.

  • GET/vendor/orders/:orderId?fields=*customer,+payment_status,*split_order_paymentno status

    Seller order detail with customer + split-payment.

    Response
    { order: Order }
    lib/src/features/shared/orders/views/order_detail_screen.dart

    auth: seller.

  • POST/vendor/orders/:orderId/cancelno status

    Seller-initiated order cancellation and refund.

    Response
    { order: { status: 'canceled', split_order_payment: { status: 'refunded', refunded_amount: number }, payment_status: 'refunded' } }
    lib/src/features/shared/orders/views/order_detail_screen.dart // Cancel button

    auth: seller.

Notes

Each call carries a RequestTrace with feature='orders/customer' or 'orders/seller' — useful when grep-debugging real network traces.