REST API that supports the customer reviews section of a product page in an e-commerce application.
Polyglot persistence was used and Review information is stored in both MySQL and MongoDB in different shapes. API supports all operations that a modern e-commerce application’s product page requires. Three entities are persisted:
- product
- review
- comment
Each product can have many reviews added by the customers. Each review can have many comments.
The project shows:
- connection between an application and database
- use of Flyway with SQL scripts to create entity tables
- Spring Data JPA repositories and data modeling
- Spring Data Mongo repositories
- tests of both type of repositories
- clone the repository
- start mysql and mongodb
- api can be used using tools like Postman
Create a new Product (POST request)
/products/
Body:
{
"name": "product",
"description": "desc",
"price": 10.50
}
Get a product by id (GET request)
/products/{id}
Get a product by name (GET request)
/products/name/{name}
Get all existing products (GET request)
/products/
Get a review for a product by product id (GET request)
/reviews/products/{product_id}
Add a new review for a product (POST request)
/reviews/products/{product_id}
Body:
{
"rating": 5,
"review_title": "Title",
"review_text": "Long text"
}
Get comments for a review (GET request)
/comments/reviews/{review_id}
Add a new comment for a review (POST request)
/comments/reviews/{review_id}
Body:
{
"comment_text": "the best comment ever"
}
- The project uses its own JSON representation for REST instead of serializing the entities directly.
- The project uses aggregations to calculate average rating for the product.