Simple Ecommerce endpoints using GraphQL and PubSub.
- Receive orders from third parties origins.
- Visualize all orders.
-
Install Docker and Docker Compose.
-
Clone the repository and cd into it:
git clone https://github.com/SirVoRaK/ecommerce
cd ecommerce
- Build the docker images:
docker build -t ecommerce-publisher ecommerce-publisher
docker build -t ecommerce-consumer ecommerce-consumer
docker build -t ecommerce-frontend ecommerce-frontend
- (IMPORTANT) Create the data folder:
mkdir data
mkdir data/mongodb
mkdir data/pubsub
-
Run the containers:
- Keep attached:
docker compose up
- Run in background:
docker compose up -d
-
Stop the container:
docker compose down
POST http://localhost:8001/graphql
mutation {
publishPlacedOrderMessage(order: {
order: "MY-ORDER-NUMBER-1",
origin: "moon",
items: [
{
name: "Boot",
image: "image-path.png",
qty: 1,
cost: 50.25,
currency: "BRL"
},
{
name: "Hammer",
image: "image-path.png",
qty: 2,
cost: 10.5,
currency: "BRL"
},
{
name: "Fork",
image: "image-path.png",
qty: 12,
cost: 2.25,
currency: "BRL"
}
]
}) {
success,
message
}
}
{
"data": {
"publishPlacedOrderMessage": {
"success": true,
"message": "Order created successfully"
}
}
}
POST http://localhost:8002/graphql
query {
placedOrders {
id,
order,
origin,
total,
createdAt,
items {
name,
image,
qty,
cost,
currency
}
}
}
{
"data": {
"placedOrders": [
{
"id": "64cc0ba8dd694012b48b31ee",
"order": "MY-ORDER-NUMBER-1",
"origin": "moon",
"total": 98.25,
"createdAt": "2023-08-03T17:18:48.051946324",
"items": [
{
"name": "Boot",
"image": "image-path.png",
"qty": 1,
"cost": 50.25,
"currency": "BRL"
},
{
"name": "Hammer",
"image": "image-path.png",
"qty": 2,
"cost": 10.5,
"currency": "BRL"
},
{
"name": "Fork",
"image": "image-path.png",
"qty": 12,
"cost": 2.25,
"currency": "BRL"
}
]
}
]
}
}
POST http://localhost:8002/graphql
query {
placedOrder (id: "64cc0ba8dd694012b48b31ee") {
id,
order,
origin,
total,
createdAt,
items {
name,
image,
qty,
cost,
currency
}
}
}
{
"data": {
"placedOrder": {
"id": "64cc0ba8dd694012b48b31ee",
"order": "MY-ORDER-NUMBER-1",
"origin": "moon",
"total": 98.25,
"createdAt": "2023-08-03T17:18:48.051946324",
"items": [
{
"name": "Boot",
"image": "image-path.png",
"qty": 1,
"cost": 50.25,
"currency": "BRL"
},
{
"name": "Hammer",
"image": "image-path.png",
"qty": 2,
"cost": 10.5,
"currency": "BRL"
},
{
"name": "Fork",
"image": "image-path.png",
"qty": 12,
"cost": 2.25,
"currency": "BRL"
}
]
}
}
}
Accessing http://localhost:8000/orders
(or just http://localhost:8000)
in your browser you will see:
Accessing http://localhost:8000/orders/ID
(or by clicking on an order)
you will see:
Both microservices are tested using JUnit and Mockito:
Publisher:
Consumer:
The ecommerce-publisher project is responsible for receiving an order through a GraphQL endpoint (exposed to the third parties), parsing it to JSON and publishing it to a PubSub topic/queue.
After that the ecommerce-consumer listens to that topic, parses the JSON into an Order instance and persist it to a Mongo database.
The consumer is also responsible for exposing a GraphQL endpoint to read the orders from the database, by making this the third parties won't have access to all orders.
The front end is made with Angular. It makes a request to the consumer to get the orders and display it to the user, clicking on an order you'll see it's details.
- Adding order pagination.
- Adding logs and save them to ElasticSearch.
- Adding filters.