SA Phase 4 Code Challenge : Pizza Restaurants [COMPULSORY]
- Due Jun 17 by 11:59pm
- Points 15
- Submitting a website url
- Available after Jun 12 at 12am
π 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
- Go to https://github.com Links to an external site.
- Click New repository
- Name your repo something like
pizza-api-challenge - Keep it public (as advised)
- 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:
models/= data layercontrollers/= route logic layerapp.py= glue between the two
π§° Setup Instructions
-
**Create a virtual environment and install packages
pipenv install flask flask_sqlalchemy flask_migrate
pipenv shell
** -
**Run DB setup commands
export FLASK_APP=server/app.py
flask db init
flask db migrate -m "Initial migration"
flask db upgrade**
-
**Seed the database
Write data in
server/seed.pyand run:
python server/seed.py**
π§© Models
Implement these models inside the models/ folder.
Restaurant
id: primary keyname: stringaddress: string
Relationships:
- has many
RestaurantPizzas
Pizza
id: primary keyname: stringingredients: string
Relationships:
- has many
RestaurantPizzas
RestaurantPizza (Join table)
id: primary keyprice: integer (validation: must be between 1 and 30)restaurant_id: FKpizza_id: FK
Relationships:
- belongs to
RestaurantandPizza
β
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.
GET /restaurants/int:id
Returns details of a single restaurant and its pizzas.
- If not found β
{ "error": "Restaurant not found" }with404
DELETE /restaurants/int:id
Deletes a restaurant and all related RestaurantPizzas.
- If successful β
204 No Content - If not found β
{ "error": "Restaurant not found" }with404
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:
- Open Postman
- Click
Importβ Uploadchallenge-1-pizzas.postman_collection.json - Test each route
π§Ύ README.md Requirements
Your README.md should include:
- Setup steps (pipenv, Flask commands)
- DB migration & seeding instructions
- Route summary
- Example requests & responses for each route
- Validation rules
- Postman usage instructions
β Submission Checklist
- MVC folder structure
- Models with validations and relationships
- All routes implemented
- Postman tests passing
- Well-written
README.md
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 -- |