The service is presented using a variant of the MVC architecture applying different tools that allow easy testing of the challenge. For this we use an in-memory H2 database and documentation using Swagger. We opted for the use of Java 17 as a test implementation.
We used java version 17 using the following dependencies:
- Spring Boot 3.0.4
- Apache Maven 3.8.7
- H2 Database
- MyBatis
- Lombok
- Swagger
- Clone the repository
- Build the project with mvn command:
mvn clean install
- Run the project with mvn command:
mvn spring-boot:run
- You can test the endpoints using the swagger interface go to the following url: http://localhost:8080/swagger-ui/index.html#/
- Run the tests with mvn command:
mvn test
Cart is an online shopping cart concept commonly used in ecommerce services, in which we store our list of desired products, therefore we use the following endpoints to manipulate the cart.
GET
/cart
(Get all carts)
Get all active carts in list
None
{
"carts": [
{
"id": "3c11c6f4-b7cf-4feb-88ab-50f9b196f679",
"totalPrice": 34.3,
"productListIds": [
1
],
"creationUser": "bpalaciosm",
"modificationUser": "bpalaciosm",
"creationDate": "2023-05-03T07:08:25.909531",
"modificationDate": "2023-05-03T07:08:25.909531"
}
]
}
curl -X 'GET' \
'http://localhost:8080/cart' \
-H 'accept: application/hal+json'
POST
/cart
(Create new shopping cart)
Create a new cart with a list of products. These products must already exist in the database.
None
{
"productListIds": [
1
],
"creationUser": "onebox"
}
{
"id": "308e0332-7c16-4ed8-9570-e8ed9517dc49"
}
curl -X 'POST' \
'http://localhost:8080/cart' \
-H 'accept: application/hal+json' \
-H 'Content-Type: application/json' \
-d '{
"productListIds": [
1
],
"creationUser": "onebox"
}'
GET
/cart/{id}
(Get cart information)
Get cart information by generated id
- id :
String
[Example:3c11c6f4-b7cf-4feb-88ab-50f9b196f679
]
{
"id": "3c11c6f4-b7cf-4feb-88ab-50f9b196f679",
"totalPrice": 34.3,
"productListIds": [
1
],
"creationUser": "bpalaciosm",
"modificationUser": "bpalaciosm",
"creationDate": "2023-05-03T07:08:25.909531",
"modificationDate": "2023-05-03T07:08:25.909531"
}
curl -X 'GET' \
'http://localhost:8080/cart/3c11c6f4-b7cf-4feb-88ab-50f9b196f679' \
-H 'accept: application/hal+json'
PUT
/cart/{id}
(Put or Drop products from cart)
Enpoint in charge of removing or putting products in the cart and updating to the latest modification. For this we use the flag addToCart that will indicate if it is placing or removing products. During this process the cart will be updated with the total price.
- id :
String
[Example:3c11c6f4-b7cf-4feb-88ab-50f9b196f679
]
{
"productListIds": [
1
],
"addToCart": false,
"modificationUser": "user"
}
{}
{
"productListIds": [
1
],
"addToCart": true,
"modificationUser": "user"
}
{}
curl -X 'PUT' \
'http://localhost:8080/cart/3c11c6f4-b7cf-4feb-88ab-50f9b196f679' \
-H 'accept: application/hal+json' \
-H 'Content-Type: application/json' \
-d '{
"productListIds": [
1
],
"addToCart": false,
"modificationUser": "user"
}'
DELETE
/cart/{id}
(Get cart information)
Delete cart by id
- id :
String
[Example:3c11c6f4-b7cf-4feb-88ab-50f9b196f679
]
{}
curl -X 'DELETE' \
'http://localhost:8080/cart/3c11c6f4-b7cf-4feb-88ab-50f9b196f679' \
-H 'accept: application/hal+json'
Every cart has products for purchase, these products are listed and well labeled according to the catalog that has our platform.
GET
/product
(Get all products)
Get all list of products in database
None
{
"products": [
{
"id": 1,
"description": "Product 1",
"price": 1
}
]
}
curl -X 'GET' \
'http://localhost:8080/product' \
-H 'accept: application/hal+json'
POST
/product/{id}
(Create new product)
Create new product in database
None
{
"description": "Product 2",
"price": 10.3
}
{
"id": 2
}
curl -X 'POST' \
'http://localhost:8080/product' \
-H 'accept: application/hal+json' \
-H 'Content-Type: application/json' \
-d '{
"description": "Product 2",
"price": 10.3
}'
GET
/product/{id}
(Get product information)
View specific product
- id :
String
[Example:3c11c6f4-b7cf-4feb-88ab-50f9b196f679
]
{
"id": 1,
"description": "Product 1",
"price": 1
}
curl -X 'GET' \
'http://localhost:8080/product/1' \
-H 'accept: application/hal+json'
OpenAPIv3 was used to launch our documentation.
A task is set every 10 minutes to check that no car has expired, otherwise it deletes it. This can be found in the JobConfiguration.java
file.
Nine tests were performed and were satisfactory.