A Rails API application for managing restaurant menus and menu items. This application provides endpoints to import restaurant data, view restaurants, menus, and menu items.
- Restaurant Management: Create and view restaurants
- Menu Management: Handle multiple menus per restaurant
- Menu Item Management: Manage menu items with pricing
- Data Import: Import restaurant data from JSON files via API or rake tasks
- RESTful API: Clean API endpoints for all operations
- Ruby 3.4.5
- PostgreSQL
- Bundler
git clone <repository-url>
cd popmenu
bundle installThe application uses PostgreSQL. Make sure PostgreSQL is running and create the databases:
# Create and setup the database
rails db:create
rails db:migraterails serverThe API will be available at http://localhost:3000
GET /api/restaurants- List all restaurantsGET /api/restaurants/:id- Get a specific restaurant
GET /api/menus- List all menusGET /api/menus/:id- Get a specific menu
GET /api/menu_items- List all menu items
POST /api/imports- Import restaurant data from JSON
bundle exec rspecThis will run all RSpec tests including:
- Controller tests for API endpoints
- Service tests for import functionality
- Model tests for data validation
rails restaurants:import_sampleCreate a file called sample_data.json:
{
"restaurants": [
{
"name": "Poppo's Cafe",
"menus": [
{
"name": "lunch",
"menu_items": [
{"name": "Burger", "price": 9.00},
{"name": "Small Salad", "price": 5.00}
]
},
{
"name": "dinner",
"menu_items": [
{"name": "Burger", "price": 15.00},
{"name": "Large Salad", "price": 8.00}
]
}
]
}
]
}Then import it:
curl -X POST http://localhost:3000/api/imports \
-H "Content-Type: application/json" \
-d @sample_data.jsonAfter importing data, test the endpoints:
# List all restaurants
curl http://localhost:3000/api/restaurants
# Get a specific restaurant
curl http://localhost:3000/api/restaurants/1
# List all menus
curl http://localhost:3000/api/menus
# List all menu items
curl http://localhost:3000/api/menu_itemsStandard format (menu_items):
curl -X POST http://localhost:3000/api/imports \
-H "Content-Type: application/json" \
-d '{"restaurants": [{"name": "Test Restaurant", "menus": [{"name": "lunch", "menu_items": [{"name": "Burger", "price": 9.99}]}]}]}'Alternative format (dishes):
curl -X POST http://localhost:3000/api/imports \
-H "Content-Type: application/json" \
-d '{"restaurants": [{"name": "Test Restaurant 2", "menus": [{"name": "dinner", "dishes": [{"name": "Pasta", "price": 12.50}]}]}]}'curl -X POST http://localhost:3000/api/imports \
-F "file=@sample_data.json"Test various error scenarios:
# Invalid JSON
curl -X POST http://localhost:3000/api/imports \
-H "Content-Type: application/json" \
-d 'invalid json'
# Empty request
curl -X POST http://localhost:3000/api/imports \
-H "Content-Type: application/json" \
-d '{}'# Run all RSpec tests
bundle exec rspec
# Run specific test files
bundle exec rspec spec/controllers/api/imports_controller_spec.rb
bundle exec rspec spec/services/restaurant_import_service_spec.rb
# Run with verbose output
bundle exec rspec --format documentation
# Run specific test patterns
bundle exec rspec spec/models/
bundle exec rspec spec/controllers/# Run RuboCop for code style
bundle exec rubocop
# Run Brakeman for security analysis
bundle exec brakemanThe application includes Docker support for production deployment:
# Build the Docker image
docker build -t popmenu .
# Run with Docker
docker run -p 3000:3000 -e RAILS_MASTER_KEY=<your-master-key> popmenuThe application uses the following models:
- Restaurant: Stores restaurant information
- Menu: Stores menu information (belongs to restaurant)
- MenuItem: Stores menu item information
- MenuMenuItem: Join table for menu-item associations
See IMPORT_INSTRUCTIONS.md for detailed information about the JSON format and import options.
- Database connection errors: Ensure PostgreSQL is running and credentials in
config/database.ymlare correct - Bundle install issues: Make sure you're using Ruby 3.4.5
- Import errors: Check the JSON format matches the expected structure
Check the Rails logs for detailed error information:
tail -f log/development.log