SA Phase 4 Code Challenge : Pizza Restaurants [COMPULSORY]

πŸ• Pizza Restaurant API Challenge

Overview

Your task is to build a RESTful API for a Pizza Restaurant using Flask. You will implement models, validations, and routes from scratch β€” no frontend is required. You’ll test your API using Postman and provide clear documentation in a README.md.

πŸ”ƒ GitHub Repository Setup Instructions

Before you start building, set up your GitHub repo to version and submit your work properly.

βœ… Step 1: Create a new GitHub repository

  1. Go to https://github.com Links to an external site.
  2. Click New repository
  3. Name your repo something like pizza-api-challenge
  4. Keep it public (as advised)
  5. Do not initialize with a README or.gitignore (you’ll do that locally)

🧱 Project Structure (MVC Preferred)

Follow the MVC (Model–View–Controller) pattern for structuring your application:
.
β”œβ”€β”€ server/
β”‚ β”œβ”€β”€ __init__.py
β”‚ β”œβ”€β”€ app.py # App setup
β”‚ β”œβ”€β”€ config.py # DB config, etc.
β”‚ β”œβ”€β”€ models/ # πŸ’Ύ Models (SQLAlchemy)
β”‚ β”‚ β”œβ”€β”€ __init__.py
β”‚ β”‚ └── restaurant.py
β”‚ β”‚ └── pizza.py
β”‚ β”‚ └── restaurant_pizza.py
β”‚ β”œβ”€β”€ controllers/ # 🎯 Route handlers (Controllers)
β”‚ β”‚ β”œβ”€β”€ __init__.py
β”‚ β”‚ └── restaurant_controller.py
β”‚ β”‚ └── pizza_controller.py
β”‚ β”‚ └── restaurant_pizza_controller.py
β”‚ β”œβ”€β”€ seed.py # Seed data
β”œβ”€β”€ migrations/
β”œβ”€β”€ challenge-1-pizzas.postman_collection.json
└── README.md

πŸ’‘ If you're new to MVC, just think of:

🧰 Setup Instructions

  1. **Create a virtual environment and install packages

    pipenv install flask flask_sqlalchemy flask_migrate
    pipenv shell
    **

  2. **Run DB setup commands

    export FLASK_APP=server/app.py
    flask db init
    flask db migrate -m "Initial migration"
    flask db upgrade

    **

  3. **Seed the database

    Write data in server/seed.py and run:
    python server/seed.py

    **

🧩 Models

Implement these models inside the models/ folder.

Restaurant

Relationships:

Pizza

Relationships:

RestaurantPizza (Join table)

Relationships:

βœ… Ensure cascading deletes when a Restaurant is deleted.

πŸ›  Required Routes (Define in Controllers)

Each controller should handle one resource.

GET /restaurants

Returns a list of all restaurants.


Returns details of a single restaurant and its pizzas.


Deletes a restaurant and all related RestaurantPizzas.


GET /pizzas

Returns a list of pizzas.

POST /restaurant_pizzas

Creates a new RestaurantPizza.

Request:

Success response:

Error response:

With 400 Bad Request


πŸ”Ž Testing

βœ… Using Postman

Import the Postman collection:

  1. Open Postman
  2. Click Import β†’ Upload challenge-1-pizzas.postman_collection.json
  3. Test each route

Your README.md should include:


βœ… Submission Checklist

Keep in mind that 101 students have already been assessed using this rubric. Changing it will affect their evaluations.

Phase 4 Flask CC Rubric

Criteria Ratings Pts
Models, Relationships, and Validations Edit criterion description 5 pts 5 All specified models, relationships, and validations are complete and correct. Validations are used when appropriate. Variable and method names are intention-revealing. 4 pts 4 All models, relationships, and validations are complete and correct, save minor mistakes in advanced deliverables. Advanced validations are complete and add informative error messages. 3 pts 3 Models, relationships, and validations mostly complete and correct per the deliverables. Advanced validations and methods may be incomplete. May have unused or unnecessary code, possibly including duplication. May have written validations instead of using appropriate built-in validations. May implement advanced query methods with iterators instead of using built-in methods. 2 pts 2 Models, relationships, and validations attempted but incomplete or have errors. Relationships may construct the wrong relationships. Validations may be missing or applied to the wrong models. Advanced query methods incomplete or have errors. 1 pts 1 Models, relationships, and validation not started or have errors that prevent the application from running. Missing validations, or validation syntax is incorrect. May have introduced models outside the specified domain. pts 5 pts --
Routes and REST Edit criterion description 5 pts 5 All routes deliverables work as described in the instructions. Routing follows REST naming conventions. 4 pts 4 Nearly all routing deliverables completed, possibly with minor errors in advanced deliverables. Routing follows REST conventions. 3 pts 3 Most routing logic working as specified. Some advanced deliverables may be incomplete. Routing follows REST convention. 2 pts 2 Some routing logic implemented, but incompletely or incorrectly. May have routes actions not included in the deliverables. 1 pts 1 Routes missing, naming does not follow REST. pts 5 pts --
Response Structure Edit criterion description 5 pts 5 Includes correct JSON response body with nested data where indicated. All routes return the appropriate HTTP status code for successful requests as well as unsuccessful requests. Uses a serializer to structure data. 4 pts 4 Includes correct JSON response body with nested data where indicated. All routes return the appropriate HTTP status code for successful requests as well as unsuccessful requests. 3 pts 3 Includes appropriate top-level JSON data in response as specified. May have missing nested data structures. Includes the correct HTTP status code for successful requests. May be missing response body or status code for unsuccessful requests (not found or invalid data). 1 pts 1 Missing response or returns JSON data other than what is specified in the deliverables. pts 5 pts --
Powered by Forestry.md