This standalone Java application allows users to manage their favorite recipes. Users can add, update, remove, and fetch recipes. Additionally, users can filter available recipes based on the following criteria:
- Whether the dish is vegetarian
- The number of servings
- Specific ingredients (either include or exclude)
- Text search within the instructions
- All vegetarian recipes
- Recipes that can serve 4 persons and have "potatoes" as an ingredient
- Recipes without "salmon" as an ingredient that have "oven" in the instructions
- It must be a REST application implemented using Java
- Your code should be production-ready
- REST API must be documented
- Data must be persisted in a database
- Unit tests must be present
- Integration tests must be present
This application is built using the following technologies and frameworks:
- Spring Boot: For building the RESTful web services
- Hibernate: For ORM (Object-Relational Mapping) and database interactions
- H2 Database: For in-memory database during development and testing
- PostgreSQL: For production
- JUnit: For unit testing
- Mockito: For mocking in unit tests
- Spring Cloud Contract: For integration testing
- Spring Boot: Simplifies the development of RESTful services and provides production-ready features out of the box.
- Hibernate: Provides a powerful and flexible ORM framework.
- H2 Database: Lightweight and fast in-memory database, ideal for development and testing.
- PostgreSQL: Robust and reliable with advanced features for complex queries and indexing.
- JUnit & Mockito: Well-known frameworks for writing and running unit tests efficiently.
- Spring Cloud Contract: Generates and executes tests from contracts.
- Spring Test: Integrates well with Spring Boot for comprehensive integration testing.
- Java 17 or higher
- Gradle 8.7 or higher
-
Clone the repository
git clone https://github.com/sergey-rubtsov/book.git cd book
-
Build the project
./gradlew build
-
Run the application With test local H2 DB
./gradlew bootRun --args='--spring.profiles.active=local'
Using docker with Postgres DB
docker-compose -f docker-compose.yaml -p book up -d postgres docker-compose -f docker-compose.yaml -p book up -d book
To run unit and integration tests, execute:
./gradlew test
The REST API is documented using OpenAPI. Once the application is running, you can access the API documentation at:
http://localhost:8080/swagger-ui/index.html
- Endpoint:
POST /api/recipes
- Request Body:
{ "title": "Veggie Delight", "servings": 4, "ingredients": [ {"name": "carrots", "category": "VEGETARIAN"}, {"name": "potatoes", "category": "VEGETARIAN"}, {"name": "peas", "category": "VEGETARIAN"} ], "instructions": "Boil the vegetables and mix them well." }
- Endpoint:
PUT /api/recipes/{id}
- Request Body (by title):
{ "title": "Veggie Delight Updated", "servings": 4, "ingredients": [ {"name": "carrots", "category": "VEGETARIAN"}, {"name": "potatoes", "category": "VEGETARIAN"}, {"name": "peas", "category": "VEGETARIAN"}, {"name": "corn", "category": "VEGETARIAN"} ], "instructions": "Boil the vegetables, add corn and mix them well." }
- Request Body (by id):
{ "id": 1, "title": "Veggie Delight Updated", "servings": 4, "ingredients": [ {"name": "carrots", "category": "VEGETARIAN"}, {"name": "potatoes", "category": "VEGETARIAN"}, {"name": "peas", "category": "VEGETARIAN"}, {"name": "corn", "category": "VEGETARIAN"} ], "instructions": "Boil the vegetables, add corn and mix them well." }
- Endpoint:
DELETE /api/recipes/{id}
- Endpoint:
GET /api/recipes
- Query Parameters:
vegetarian
(optional):true
orfalse
servings
(optional): number of servingsinclude
(optional): list of ingredients to includeexclude
(optional): list of ingredients to excludeinstructions
(optional): text search within instructions, case-sensitivepage
(optional): number of pagesize
(optional): number of recipes per page