Skip to main content

Order Service

Purpose

order-service stores orders and builds confirmed orders from successful payment events.

Responsibilities

  • Return order history and order details
  • Allow customer cancellation in allowed statuses
  • Allow admin status updates
  • Consume payment-success
  • Publish order-created

Dependencies

  • Port: 8084
  • Database: bookstore_order_db
  • HTTP dependencies: book-service, user-service
  • Kafka dependency: consumes and produces

REST APIs

MethodPathAuthDescription
PUT/api/orders/{orderId}/status?status=AdminUpdate order status
POST/api/orders/{orderId}/cancelYesCancel own order
GET/api/ordersAdminList all orders
GET/api/orders/meYesList current user's orders
GET/api/orders/userId?id=YesGet orders by user ID
GET/api/orders/payment/{paymentId}YesGet order by payment ID
GET/api/orders/{id}YesGet order by order ID

Kafka

Consumer

  • Topic: payment-success
  • Group: order-group

Producer

  • Topic: order-created

Outbound event

OrderCreatedEvent fields:

  • orderId
  • userId
  • email
  • totalAmount
  • items[]
  • firstName
  • phoneNumber
  • status

Database tables

orders

  • id
  • user_id
  • payment_id
  • total_amount
  • status
  • created_at
  • updated_at

order_items

  • id
  • book_id
  • book_title
  • quantity
  • price
  • order_id

Entity relationships

Internal flow

Status transitions

See the Orders API page for the full status state diagram.

Notes

  • createOrder(OrderRequest) exists in the service layer and publishes order-created, but the controller shown in the current repository does not expose a POST /api/orders endpoint.
  • Access checks inside the service use the authenticated principal UUID and an admin-role check.
  • Cancelable statuses are CREATED, PENDING, PAYMENT_PENDING, and CONFIRMED.