Skip to content

andreaiacono/recipes

Repository files navigation

Recipes API

A REST API for managing recipes and shopping carts, built with Micronaut and Kotlin.

API Endpoints

Recipes

  • GET /recipes - List all available recipes with ingredients

Carts

  • GET /carts/{id} - Get cart by ID with items and recipes
  • POST /carts/{id}/add_recipe - Add a recipe to cart (I would change it to /carts/{id}/recipes for consistency with the DELETE endpoint and because it's more RESTish)
  • DELETE /carts/{id}/recipes/{recipeId} - Remove a recipe from cart

Technology Stack

  • Micronaut 4.3.5 - Framework
  • Kotlin - Programming language
  • H2 - Database
  • Flyway - Database migrations
  • Micronaut Data JDBC - Data access layer
  • JUnit 5 - Testing
  • MockK - Mocking framework

Database Schema

The application uses the following tables:

  • products - Product information (name, price)
  • recipes - Recipe information (name, description, servings, prep time)
  • recipe_ingredients - Recipe-to-product relationships
  • carts - Shopping cart information
  • cart_items - Individual product items in carts
  • cart_recipes - Recipes added to carts

Running the Application

./gradlew run

The API will be available at http://localhost:8081

Running Tests

./gradlew test

Building the Application

./gradlew build

Sample Data

The application comes with sample data including:

Products:

  • Tomatoes, Mozzarella, Basil, Olive Oil
  • Pasta, Garlic, Chicken Breast, Onion, Bell Pepper, Rice

Recipes:

  • Margherita Pizza (Tomatoes, Mozzarella, Basil, Olive Oil)
  • Chicken Stir Fry (Chicken Breast, Onion, Bell Pepper, Rice)
  • Pasta Aglio e Olio (Pasta, Garlic, Olive Oil)

Sample Carts:

  • 3 empty carts (IDs: 1, 2, 3)

API Usage Examples

Get all recipes

curl http://localhost:8081/recipes

Get cart by ID

curl http://localhost:8081/carts/1

Add recipe to cart

curl -X POST http://localhost:8081/carts/1/add_recipe \
  -H "Content-Type: application/json" \
  -d '{"recipe_id": 1, "quantity": 1}'

Remove recipe from cart

curl -X DELETE http://localhost:8081/carts/1/recipes/1

Project Structure

src/
├── main/
│   ├── kotlin/me/andreaiacono/
│   │   ├── controller/          # REST controllers
│   │   ├── dto/                 # Data transfer objects
│   │   ├── model/               # Domain models
│   │   ├── repository/          # Data repositories
│   │   ├── service/             # Business logic
│   │   └── Application.kt       # Main application class
│   └── resources/
│       ├── application.yml      # Application configuration
│       └── db/migration/        # Database migrations
└── test/
    ├── kotlin/me/andreaiacono/
    │   ├── controller/          # Controller tests
    │   └── service/             # Service tests
    └── resources/
        └── application-test.yml # Test configuration

Development Notes

I used Claude Code for creating the project and then I re-arranged quite some things here and there for improving it.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages