This project is a web application for a casting agency, whose goal is to find suitable actors to cast in different movies. It models relationships in SQLAlchemy ORM, implements RESTful APIs and enforces Role Based Access Control (RBAC) on the APIs using Auth0. This application is the capstone project of my Full Stack Web Developer Nanodegree Program.
The App is hosted on heroku.
URL: https://web-app-casting-agency.herokuapp.com
Once you have your virtual environment setup and running, install dependencies by naviging to the /backend
directory and running:
pip install -r requirements.txt
This will install all of the required packages we selected within the requirements.txt
file.
-
Flask is a lightweight backend microservices framework. Flask is required to handle requests and responses.
-
SQLAlchemy is the Python SQL toolkit and ORM we'll use handle the lightweight sqlite database. You'll primarily work in app.py and can reference models.py.
-
Flask-CORS is the extension we'll use to handle cross origin requests from our frontend server.
- Create a local Postgres database.
- Create environment variable DATABASE_URL and set it to the database's URL.
Example:
export DATABASE_URL=postgresql://$USER@localhost:5432/<your_db_name>
- To run the server locally, execute:
source setup.sh
export FLASK_ENV=development
flask run
GET '/actors'
GET '/movies'
POST '/actors'
POST '/movies'
PATCH '/actors/int:id'
PATCH '/movies/int:id'
DELETE '/actors/int:id'
DELETE '/movies/int:id'
All APIs are secured by RBAC, and are available depending on the user's role.
There are three roles: Casting Assistant, Casting Director and Casting Producer. Each role has access to the followings APIs.
GET '/actors'
GET '/movies'
GET '/actors'
GET '/movies'
POST '/actors'
PATCH '/actors/int:id'
PATCH '/movies/int:id'
DELETE '/actors/int:id'
GET '/actors'
GET '/movies'
POST '/actors'
POST '/movies'
PATCH '/actors/int:id'
PATCH '/movies/int:id'
DELETE '/actors/int:id'
DELETE '/movies/int:id'
!castingassistant5786%
!castingdirector4132%
!castingproducer6879%
- Fetches a list of all actors in the database
- Request Arguments: None
- Returns: A list of actor objects, where each object has the following properties: id, name, age, gender and list of movie titles the actor acted in.
Example Response: GET '/actors'
[
{
"age": 45,
"gender": "Male",
"id": 1,
"movies": [
"Titanic",
"Catch Me If You Can"
],
"name": "Leonardo DiCaprio"
},
{
"age": 44,
"gender": "Female",
"id": 2,
"movies": [
"Titanic"
],
"name": "Kate Winslet"
},
{
"age": 64,
"gender": "Male",
"id": 3,
"movies": [
"Forrest Gump",
"Catch Me If You Can"
],
"name": "Tom Hanks"
},
{
"age": 54,
"gender": "Female",
"id": 4,
"movies": [
"Forrest Gump"
],
"name": "Robin Wright"
},
{
"age": 77,
"gender": "Male",
"id": 5,
"movies": [
"Catch Me If You Can"
],
"name": "Christopher Walken"
}
]
- Fetches a list of all movies in the database
- Request Arguments: None
- Returns: A list of movie objects, where each object has the following properties: id, title, release_date and list of names of actors who acted in in the movie.
Example Respone: GET '/movies'
[
{
"actors": [
"Tom Hanks",
"Robin Wright"
],
"id": 1,
"release_date": "Wed, 06 Jul 1994 00:00:00 GMT",
"title": "Forrest Gump"
},
{
"actors": [
"Leonardo DiCaprio",
"Kate Winslet"
],
"id": 2,
"release_date": "Fri, 19 Dec 1997 00:00:00 GMT",
"title": "Titanic"
},
{
"actors": [
"Leonardo DiCaprio",
"Tom Hanks",
"Christopher Walken"
],
"id": 3,
"release_date": "Wed, 25 Dec 2002 00:00:00 GMT",
"title": "Catch Me If You Can"
}
]
- Creates and inserts a new actor record into the database
- Request Body: actor information { "name": <actor_name>, "age": <actor_age>, "gender": <actor_gender>}
- Returns: A JSON containing the actor inserted
Example Request: POST '/actors'
{
"age": 77,
"gender": "Male",
"name": "Robert De Niro"
}
Response
{
"actor": {
"age": 77,
"gender": "Male",
"id": 9,
"name": "Robert De Niro"
},
"success": true
}
- Creates and inserts a new movie record into the database
- Request Body: movie information
{ "title": <movie_title>, "release_date": <<movie_release_date>}
The release date has to a string in the following format: "YYYY-MM-DD", example: “2021-12-31” - Returns: A JSON containing the movie inserted
Example Request: POST '/movies'
{
"release_date": "1976-02-08",
"title": "Taxi Driver"
}
Response
{
"movie": {
"id": 6,
"release_date": "Sun, 08 Feb 1976 00:00:00 GMT",
"title": "Taxi Driver"
},
"success": true
}
- Updates an existing actor record in the database.
- Request Body: new actor information conatining one or more of the following keys { "name": <actor_name>, "age": <actor_age>, "gender": <actor_gender>}
- Returns: A JSON containing the actor updated
Example Request: PATCH '/actors/1'
{
"age":46
}
Response
{
"actor": {
"age": 46,
"gender": "Male",
"id": 1,
"name": "Leonardo DiCaprio"
},
"success": true
}
- Updates an existing movie record in the database.
- Request Body: new movie information conatining one or more of the following keys
{ "title": <movie_title>, "release_date": <<movie_release_date>}
The release date has to a string in the following format: "YYYY-MM-DD", example: “2021-12-31” - Returns: A JSON containing the movie updated
Example Request: PATCH '/movies/1'
{
"release_date":"1997-12-25"
}
Response:
{
"movie": {
"id": 1,
"release_date": "Thu, 25 Dec 1997 00:00:00 GMT",
"title": "Forrest Gump"
},
"success": true
}
- Deletes the actor with given id from the database
- Returns: the id of the actor succefully deleted
Example Request: DELETE '/actors/1' Response:
{
"delete": 1,
"success": true
}
- Deletes the movie with given id from the database
- Returns: the id of the movie succefully deleted
Example Request: DELETE '/movies/1' Response:
{
"delete": 1,
"success": true
}
Instructions to run tests:
- Create a local database for testing.
- Import data from test_db.db
For Example, if your test database is named casting_agency_test_db:
psql casting_agency_test_db < test_db.db
- Set “LOCAL_TEST_DB_URL“ to the db's url in your python virtual env. Example:
export LOCAL_TEST_DB_URL=postgresql://$USER@localhost:5432/<test_database_name>
- Import Environment Variables
source setup.sh
- To run the tests
python tests.py