The project is written in Java and uses the Spring Boot framework. It includes two microservices as required by the assignment. Both services can be run simultaneously using Docker Compose. Additionally, a MySQL 8 server is utilized, which was set up and managed through AWS cloud services.
Run the project with Docker-Compose:
Install Docker + Docker Compose inside WSL2 (Ubuntu):
- Install prerequisites:
- sudo apt update
- sudo apt install ca-certificates curl gnupg lsb-release -y
- Add Docker GPG key:
- sudo mkdir -p /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
- Add Docker repository:
- echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
- Install Docker + Docker Compose plugin:
- sudo apt update
- sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y
- Start Docker and allow current user:
- sudo service docker start
- sudo usermod -aG docker $USER
- newgrp docker
Install Java 17+ and Maven:
- Install Java 21 (includes Java 17 support):
- sudo apt install openjdk-21-jdk -y
- Install Maven:
- sudo apt install maven -y
Prepare the Project:
- Clone the project:
- git clone https://github.com/orlevran/Project_iCash.git
- cd Project_iCash
Build Both Microservices:
- First Microservice:
- cd ~/Project_iCash/cash_register_service
- mvn clean package
- Second Microservice:
- cd ~/Project_iCash/supermarket_service
- mvn clean package
Run with Docker Compose:
- From the root project folder:
- docker compose down (Not for the first time)
- docker compose up --build
Test in Postman (Or Insomnia) the following requests: (Note- Some requests are expected to receive a response with an error message)
curl --location 'http://localhost:8080/purchases/make'
--header 'Content-Type: application/json'
--data '{
"supermarketId": "SMKT001",
"items": ["milk", "eggs", "cereal"],
"userId": "123e4567-e89b-12d3-a456-426614174000"
}'
curl --location 'http://localhost:8080/purchases/make'
--header 'Content-Type: application/json'
--data '{
"supermarketId": "SMKT002",
"items": ["bread", "milk"],
"userId": null
}'
curl --location 'http://localhost:8080/purchases/make'
--header 'Content-Type: application/json'
--data '{
"items": ["milk", "eggs"],
"userId": "123e4567-e89b-12d3-a456-426614174000"
}'
curl --location 'http://localhost:8080/purchases/make'
--header 'Content-Type: application/json'
--data '{
"supermarketId": "UNKNOWN123",
"items": ["milk"],
"userId": null
}'
curl --location 'http://localhost:8080/purchases/make'
--header 'Content-Type: application/json'
--data '{
"supermarketId": "SMKT003",
"items": ["milk", "invalid_item"],
"userId": null
}'
curl --location 'http://localhost:8080/purchases/make'
--header 'Content-Type: application/json'
--data '{}'
curl --location 'http://localhost:8080/purchases/make'
--header 'Content-Type: application/json'
--data '{
"supermarketId": "SMKT001",
"items": ["milk", "eggs", "bread", "cheese", "butter", "water", "juice", "yogurt", "apples", "bananas", "extra_item"],
"userId": null
}'
curl --location 'http://localhost:8081/supermarket/ping'
--data ''
curl --location 'http://localhost:8081/supermarket/total-users'
--data ''
curl --location 'http://localhost:8081/supermarket/loyal-users'
--data ''
curl --location 'http://localhost:8081/supermarket/top-three-products'
--data ''