Git Product home page Git Product logo

book's Introduction

Cookbook Application

Objective

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:

  1. Whether the dish is vegetarian
  2. The number of servings
  3. Specific ingredients (either include or exclude)
  4. Text search within the instructions

Example Search Requests

  • 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

Requirements

  1. It must be a REST application implemented using Java
  2. Your code should be production-ready
  3. REST API must be documented
  4. Data must be persisted in a database
  5. Unit tests must be present
  6. Integration tests must be present

Architectural Choices

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

Why These Choices?

  • 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.

Getting Started

Prerequisites

  • Java 17 or higher
  • Gradle 8.7 or higher

Installation

  1. Clone the repository

    git clone https://github.com/sergey-rubtsov/book.git
    cd book
    
  2. Build the project

    ./gradlew build
  3. 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

Running Tests

To run unit and integration tests, execute:

./gradlew test

API Documentation

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

Usage

Adding a Recipe

  • 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."
    }

Updating a Recipe

  • 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."
    }

Removing a Recipe

  • Endpoint: DELETE /api/recipes/{id}

Fetching Recipes

  • Endpoint: GET /api/recipes
  • Query Parameters:
    • vegetarian (optional): true or false
    • servings (optional): number of servings
    • include (optional): list of ingredients to include
    • exclude (optional): list of ingredients to exclude
    • instructions (optional): text search within instructions, case-sensitive
    • page (optional): number of page
    • size (optional): number of recipes per page

book's People

Contributors

sergey-rubtsov avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.