Skip to content

Shopping cart system in Java11 + PostgreSQL implementing Event Sourcing (ES) + Command Query Responsibility Segregation (CQRS)

License

Notifications You must be signed in to change notification settings

cbeardsmore/shopping-cart-event-sourced

Repository files navigation

shopping-cart-event-sourced

codecov Gradle Build GitHub

A shopping cart system in Java 11 and PostgreSQL implementing Event Sourcing (ES) and Command Query Responsibility Segregation (CQRS). The system follows a Hex Arch pattern to create loosely coupled components, isolate the core domain logic and facilitate test automation.

Build and Run

Gradle

  • To build via gradle:

    gradle clean build

Docker

  • To build:

    docker-compose build

  • To run:

    docker-compose up --build

  • To test via Postman while running:

     npm install -g newman
     ./postman/test.sh

API

Command Endpoints

  • Create a new Cart:
POST /cart/create
RESPONSE:
{
  "aggregateId": "UUID"
}
  • Add a Product:
POST /cart/{cartId}
REQUEST: 
{
  "productId": "UUID",
  "name": "Samsung TV",
  "price": 49.99
}
  • Remove a Product:
DELETE /cart/{cartId}/product/{productId}
  • Checkout:
POST /cart/{cartId}/checkout
RESPONSE:
{
  "totalPrice": 199.97
}

Query Endpoints

  • Get total price of all checked out carts:
GET /carts/total
RESPONSE:
{
  "totalPrice": 199.97
}
  • Get total price of a specific cart:
GET /cart/{cartId}
RESPONSE:
{
  "totalPrice": 199.97
}
  • Get top 5 most popular products:
GET /product/popular
RESPONSE:
{
  "popularProducts": [
    {
      "productId": "UUID"
      "quantity": 430
    }
  ]
}

About

Shopping cart system in Java11 + PostgreSQL implementing Event Sourcing (ES) + Command Query Responsibility Segregation (CQRS)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages