The name of the application is called the Casting Agency. The Casting Agency models a company that is responsible for creating movies and managing and assigning actors to those movies. As an Executive Producer within the company, I am motivated in creating a system to simplify and streamline the processes.
This app is hosted on heroku. The link to the app is here, click me!. The backend is up and running. The frontend is still under construction.
Refer to the credentials given below to login in order to access the JWT for each role mentioned below. Ensure that your browser history is cleared at least for the last 1 hour before login into each account.
The app uses Auth0 as a third party authentication service.
Three roles have been created to manage the system. Each role is restricted to perform certain CRUD operations on the system as assigned and permitted by Auth0 service.
The three roles are:
-
Casting assistant
- Permission to
get:movies-details
andget:actors-details
- Login info:
- Email:
[email protected]
- password:
Passwordeca1
- Email:
- Permission to
-
Casting Director
- All permissions a Casting Assistant has, as mentioned above.
- Permission to
post:actors
anddelete:actors
- Permission to
patch:actors
andpatch:movies
- Login info:
- Email:
[email protected]
- password:
${hidden}
- Email:
-
Executive Producer
- All permissions a Casting Director has, as mentioned above.
- Permission to
post:movies
anddelete:movies
- Login info:
- Email:
[email protected]
- password:
${hidden}
- Email:
Follow instructions to install the latest version of python for your platform in the python docs
It is recommended working within a virtual environment whenever using Python for projects. This keeps your dependencies for each project separate and organized. Instructions for setting up a virual enviornment for your platform can be found in the python docs
Once you have your virtual environment setup and running, install dependencies by navigating to the project directory and running:
pip3 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.
With Postgres running, restore a database using the casting.psql file provided. From the main project folder in the terminal run:
createdb castingagency
python3 manage.py db init
python3 manage.py db migrate
python3 manage.py db upgrade
Note: You may be required to delete the migrations folder before running the commands above.
Ensure that you are working using your created virtual environment.
In backend/app.py
remove the .
from line 7 and 8.
Line 7 & 8 should look like this:
from models import setup_db, Movie, Actor
from auth import AuthError, requires_auth
The .
is required on line 7 and 8 when Heroku launches the app from the wsgi.py
file found in the casting-agency-folder
. The .models
is equivalent to backend.models
. It designates the path to the module. The issue is why the app can't be launched locally when the command lines below are executed in the terminal, unless the changes, as mentioned above, are made to lines 7 & 8.
From within the casting-agency-api
directory, run the server by executing:
export FLASK_APP=wsgi
export FLASK_ENV=development
flask run
Setting the FLASK_ENV
variable to development
will detect the changes made to the file and restart the server automatically.
Setting the FLASK_APP
variable to wsgi
directs flask to use the backend
directory and the app.py
file to find the application.
The endpoints can be tested on Postman to check on the corresponding returned objects for each endpoint.
Refer to the Postman collection file in the casting-agency-api
folder. Remember to use the JWTs generated from the Auth0 login, refer to section Deployment and Authentication, in order to test the endpoints that required the necessary authentication and permission.
Alternatively, refer to the postman docs for this particular collection for the respective Curl
commands for each endpoint. Remember to include the headers={"Authorization": (ROLE's_JWT)}
at the end of each curl
command where authorization is required for the endpoint.
-
General:
- Fetches a dictionary of movies
- Request Arguments: The page_number. Default is set to page 1. The page number can be requested by adding
?page={page_number}
to the endpoint, e.g/movies?page=2
. - Returns: an object with keys
movies
andsuccess
. The keymovies
contains a list of id, title and release_date with their corresponding values.
-
Sample:
{
"movies": [
{
"id": 1,
"release_date": "Feb 14, 2020",
"title": "Sonic The Hedgehog"
},
{
"id": 2,
"release_date": "Feb 7, 2020",
"title": "The Call Of the Wild"
}
],
"success": true
}
-
General:
- Fetches a dictionary of movies with full details
- Request Arguments: The page_number. Default is set to page 1. The page number can be requested by adding
?page={page_number}
to the endpoint, e.g/movies-details?page=2
. - Returns: an object with keys
movies
andsuccess
. The keymovies
is another object that contains a list ofactors
, theid
,release_date
,title
of the movies. The list of actors provide the details of actors assigned to the movies.
-
Sample:
{
"movies": [
{
"actors": [
{
"age": 58,
"gender": "male",
"id": 1,
"movie": 1,
"name": "Jim Carrey"
},
{
"age": 46,
"gender": "male",
"id": 2,
"movie": 1,
"name": "James Marsden"
}
],
"id": 1,
"release_date": "Feb 14, 2020",
"title": "Sonic The Hedgehog"
},
{
"actors": [
{
"age": 77,
"gender": "male",
"id": 3,
"movie": 2,
"name": "Harrison Ford"
},
{
"age": 42,
"gender": "male",
"id": 4,
"movie": 2,
"name": "Omar Sy"
},
{
"age": 32,
"gender": "female",
"id": 5,
"movie": 2,
"name": "Karen Gillan"
}
],
"id": 2,
"release_date": "Feb 7, 2020",
"title": "The Call Of the Wild"
}
],
"success": true
}
-
General:
- Add a movie with the required details. Only a registered Executive Producer have the permissions to add an actor.
- Request Arguments: authentication token, an object containing the
title
andrelease_date
of the new movie. - Returns: an object with keys
added_movie
andsuccess
. The keyadded_movie
is another object that contains theid
,title
andrelease_date
with their corresponding values.
-
Sample:
{
"added_movie": [
{
"id": 5,
"release_date": "March 13, 2020",
"title": "Bloodshot"
}
],
"success": true
}
-
General:
- Delete details of a movie. Only a registered Executive Producer have the permissions to delete an a movie.
- Request Arguments:
movie.id
, authentication token - Returns: an object with keys
deleted_movie
andsuccess
. The keydeleted_movie
is another object that contains theid
,title
andrelease_date
with their corresponding values.
-
Sample:
{
"deleted_movie": [
{
"id": 5,
"release_date": "March 13, 2020",
"title": "Bloodshot"
}
],
"success": true
}
-
General:
- update details about an movie. Only a registered Executive Producer have the permissions to update details about an actor.
- Request Arguments: authentication token,
movie.id
, an object containing the keystitle
andrelease_date
with the respective updated values. - Returns: an object with keys
updated_movie
andsuccess
. The keyupdated_movie
is another object that contains theid
,title
andrelease_date
with their corresponding updated values.
-
Sample:
{
"success": true,
"updated_movie": [
[
{
"id": 1,
"release_date": "June 27, 2020",
"title": "Sonic The Hedgehog"
}
]
]
}
-
General:
- Fetches a dictionary of actors
- Request Arguments: The page_number. Default is set to page 1. The page number can be requested by adding
?page={page_number}
to the endpoint, e.g/actors?page=2
. - Returns: an object with keys
actors
andsuccess
. The keyactors
contains a list of name, age, and gender with their corresponding values.
-
Sample:
{
"actors": [
{
"age": 58,
"gender": "male",
"id": 1,
"name": "Jim Carrey"
},
{
"age": 46,
"gender": "male",
"id": 2,
"name": "James Marsden"
}
],
"success": true
}
-
General:
- Fetches a dictionary of actors
- Request Arguments: The page_number. Default is set to page 1. The page number can be requested by adding
?page={page_number}
to the endpoint, e.g/actors-details?page=2
. - Returns: an object with keys
actors
andsuccess
. The keyactors
contains a list ofid
,name
,age
,gender
andmovie
with their corresponding values.
-
Sample:
{
"actors": [
{
"age": 58,
"gender": "male",
"id": 1,
"movie": 1,
"name": "Jim Carrey"
},
{
"age": 46,
"gender": "male",
"id": 2,
"movie": 1,
"name": "James Marsden"
},
{
"age": 42,
"gender": "male",
"id": 4,
"movie": 2,
"name": "Omar Sy"
},
{
"age": 32,
"gender": "female",
"id": 5,
"movie": 2,
"name": "Karen Gillan"
},
{
"age": 37,
"gender": "female",
"id": 6,
"movie": 3,
"name": "Ali Wong"
},
{
"age": 38,
"gender": "female",
"id": 7,
"movie": 4,
"name": "Andrea Riseborough"
}
],
"success": true
}
-
General:
- Delete details of an actor. Only a registered casting director and an executive Producer have the permissions to delete an actor.
- Request Arguments:
actor.id
, authentication token - Returns: an object with keys
deleted_actor
andsuccess
. The keydeleted_actor
is another object that contains theid
,name
,age
andgender
with their corresponding values.
-
Sample:
{
"deleted_actor": {
"age": 77,
"gender": "male",
"id": 3,
"name": "Harrison Ford"
},
"success": true
}
-
General:
- Add an actor with the required details. Only a registered casting director and an executive Producer have the permissions to add an actor.
- Request Arguments: authentication token, an object containing the
name
,age
,gender
and/ormovie
of the new actor. - Returns: an object with keys
added_actor
andsuccess
. The keyadded_actor
is another object that contains theid
,name
,age
,gender
andmovie
with their corresponding values. The keymovie
, in this instance, is the assignedmovie_id
to this particular actor.
-
Sample:
{
"added_actor": [
{
"age": 60,
"gender": "Female",
"id": 9,
"movie": null,
"name": "Margot Robbie"
}
],
"success": true
}
-
General:
- update details about an actor. Only a registered casting director and an executive Producer have the permissions to update details about an actor.
- Request Arguments:
actor.id
, authentication token - Returns: an object with keys
updated_actor
andsuccess
. The keyupdated_actor
is another object that contains theid
,name
,age
,gender
andmovie
with their corresponding values. The keymovie
, in this instance, is the assignedmovie_id
to this particular actor.
-
Sample:
{
"success": true,
"updated_actor": [
[
{
"age": 25,
"gender": "Female",
"id": 9,
"movie": 2,
"name": "Margot Robbie"
}
]
]
}
In order to carry out the tests on the endpoints, navigate to the backend folder in your terminal and run the following commands:
source setup.sh
dropdb castingagency_test
createdb castingagency_test
psql castingagency_test < casting.psql
python3 test_flaskr.py
The contents of this repository are covered under the MIT License.