Casting agency api is a tool that provides endpoints to support you create an application to manage casting.
I developed this project to make use of the knowledge I acquired in Udacity nanogree and hence gain confidence in these skills.
The access token will be displayed on the URL bar after login.
- There are 3 roles 'Casting Assistant', 'Casting Director' and 'Executive Producer'.
- To get access token for 'Casting Assistant', login with account:
- username: [email protected]
- password: Abcd1234
- To get access token for 'Casting Director', login with account:
- username: [email protected]
- password: Abcd1234
- To get access token for 'Executive Producer', login with account:
- username: [email protected]
- password: Abcd1234
Auth0 is set up and running. The following configurations are in a setup.sh file which is exported by the app:
- The Auth0 Domain Name
- The JWT code signing secret
- The Auth0 Client ID The JWT token contains the permissions for the 'Executive Producer' roles.
The schema for the database and helper methods to simplify API behavior are in models.py:
- There are three tables created: Movie, Acotr and Casting
- The Movie table is used by the role 'Executive Producer' to add, update and create movies. 'Casting Director' and 'Casting Assistant' can retrieve movie list.
- The Actor table is used by the role 'Executive Producer' and 'Casting Director' to add, update and create actors. 'Casting Assistant' can retrieve actor list.
- The Casting table is used by the role 'Executive Producer', 'Casting Director' and 'Casting Assistant' to add, update and create castings and retrive all casting data
- The Casting table has 2 foreign keys 'actor_id' and 'movie_id' for both Actor and Movie table. Each table has an insert, update, delete, and format helper functions.
-
Run venv
python3.9 -m venv venv -
Setup environment
source venv/bin/activate source setup.sh -
Install dependencies
pip3 install -r requirements.txt -
Create a new database and import new data for testing
dropdb casting-agency # (optional) Drop if it exists createdb casting-agency psql -U postgres -d casting-agency < database.sql -
Run the app
flask run -p 3000 -
Login in local
Login locally The access token will be displayed on the URL bar after login.
-
Run unittest
python3 test_flask.py -
Run test
In Postman, import file casting-agency.postman_collection.json to run the test.
If the tokens expire, please login locally again to get the token for respectively roles.
-
Return a list of movies in database
-
Sample curl:
curl -H "Content-Type: application/json" -H "Authorization: Bearer {INSERT_TOKEN_HERE}" http://localhost:3000/movies -
Sample response
{ "movies": [ { "director": "Seymour Huikerby", "facebook_link": "http://google.com", "genres": "Adventure,Sci-Fi", "id": 1, "image_link": "http://google.com", "name": "Dune", "phone": "123412343", "producer": "Dach-Streich", "seeking_actor": true, "seeking_description": "Finding actors for Dune movie", "website": "http://dune.com" }, { "director": "Juliane Pexton", "facebook_link": "166.11.226.15", "genres": "Drama", "id": 2, "image_link": "27.215.169.113", "name": "A Magnificent Haunting", "phone": "241 789 3774", "producer": "Dooley Group", "seeking_actor": true, "seeking_description": "˙ɐnbᴉlɐ ɐuƃɐɯ ǝɹolop ʇǝ ǝɹoqɐl ʇn ʇunpᴉpᴉɔuᴉ ɹodɯǝʇ poɯsnᴉǝ op pǝs 'ʇᴉlǝ ƃuᴉɔsᴉdᴉpɐ ɹnʇǝʇɔǝsuoɔ 'ʇǝɯɐ ʇᴉs ɹolop ɯnsdᴉ ɯǝɹo˥", "website": "190.29.216.110" } ], "success": true, "total_movies": 2 } -
To get the tokens for this endpoints, we have to login with any role permission that is listed in RABC section. Click on Login and enter one of those credentials into Auth0.
-
Search movies in database by searchTerm
-
Sample curl:
curl -H "Content-Type: application/json" -H "Authorization: Bearer {INSERT_TOKEN_HERE}" http://localhost:3000/movies?searchTerm=Dune -
Sample response
{ "movies": [ { "director": "Seymour Huikerby", "facebook_link": "http://google.com", "genres": "Adventure,Sci-Fi", "id": 1, "image_link": "http://google.com", "name": "Dune", "phone": "123412343", "producer": "Dach-Streich", "seeking_actor": true, "seeking_description": "Finding actors for Dune movie", "website": "http://dune.com" } ], "success": true, "total_movies": 1 } -
To get the tokens for this endpoints, we have to login with any role permission that is listed in RABC section. Click on Login and enter one of those credentials into Auth0.
-
Get specific infor of a movie id
-
Sample curl:
curl -H "Content-Type: application/json" -H "Authorization: Bearer {INSERT_TOKEN_HERE}" http://localhost:3000/movies/1 -
Sample response
{ "movie": { "director": "Seymour Huikerby", "facebook_link": "http://google.com", "genres": "Adventure,Sci-Fi", "id": 1, "image_link": "http://google.com", "name": "Dune", "phone": "123412343", "producer": "Dach-Streich", "seeking_actor": true, "seeking_description": "Finding actors for Dune movie", "website": "http://dune.com" }, "success": true } -
To get the tokens for this endpoints, we have to login with any role permission that is listed in RABC section. Click on Login and enter one of those credentials into Auth0.
-
Update a movie id infomation
-
Sample curl:
curl -X PATCH -H "Content-Type: application/json" -H "Authorization: Bearer {INSERT_TOKEN_HERE}" http://localhost:3000/movies/1 \ -F director:Seymour Huikerby \ -F facebook_link:http://google.com \ -F genres:Adventure \ -F genres:Sci-Fi \ -F image_link:http://google.com \ -F name:Dune \ -F phone:123412343 \ -F producer:Dach-Streich \ -F seeking_actor:true \ -F seeking_description:Finding actors for Dune movie \ -F website:http://dune.com -
Sample response
{ "movie": { "director": "Seymour Huikerby", "facebook_link": "http://google.com", "genres": "Adventure,Sci-Fi", "id": 1, "image_link": "http://google.com", "name": "Dune", "phone": "123412343", "producer": "Dach-Streich", "seeking_actor": true, "seeking_description": "Finding actors for Dune movie", "website": "http://dune.com" }, "success": true } -
To get the tokens for this endpoints, we have to login with 'Executive Producer' role permission that is listed in RABC section. Click on Login and enter that credential into Auth0.
-
Create a new movie
-
Sample curl:
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer {INSERT_TOKEN_HERE}" http://localhost:3000/movies \ -F director:Seymour Huikerby \ -F facebook_link:http://google.com \ -F genres:Adventure \ -F genres:Sci-Fi \ -F image_link:http://google.com \ -F name:Dune \ -F phone:123412343 \ -F producer:Dach-Streich \ -F seeking_actor:true \ -F seeking_description:Finding actors for Dune movie \ -F website:http://dune.com -
Sample response
{ "movie": { "director": "Seymour Huikerby", "facebook_link": "http://google.com", "genres": "Adventure,Sci-Fi", "id": 17, "image_link": "http://google.com", "name": "Dune", "phone": "123412343", "producer": "Dach-Streich", "seeking_actor": true, "seeking_description": "Finding actors for Dune movie", "website": "http://dune.com" }, "success": true } -
To get the tokens for this endpoints, we have to login with 'Executive Producer' role permission that is listed in RABC section. Click on Login and enter that credential into Auth0.
-
Delete a movie by id
-
Sample curl:
curl -X DELETE -H "Content-Type: application/json" -H "Authorization: Bearer {INSERT_TOKEN_HERE}" http://localhost:3000/movies/10 -
Sample response
{ "id": "10", "success": true } -
To get the tokens for this endpoints, we have to login with 'Executive Producer' role permission that is listed in RABC section. Click on Login and enter that credential into Auth0.
-
Return a list of actors in database
-
Sample curl:
curl -H "Content-Type: application/json" -H "Authorization: Bearer {INSERT_TOKEN_HERE}" http://localhost:3000/actors -
Sample response:
{ "actors": [ { "age": 43, "city": "Norman", "genres": "Comedy,Drama", "id": 1, "image_link": "http://google.com", "name": "Arabela Lebbern", "phone": "4056375359", "seeking_description": "I want a movie", "seeking_movie": true, "sex": "Male", "state": "AL", "website": "http://google.com" }, { "age": 55, "city": "Spartanburg", "genres": "Drama", "id": 2, "image_link": "175.158.204.166", "name": "Amandi Grewcock", "phone": "8641139421", "seeking_description": "", "seeking_movie": true, "sex": "Female", "state": "South Carolina", "website": "65.11.237.63" } ], "success": true, "total_actors": 2 } -
To get the tokens for this endpoints, we have to login with any role permission that is listed in RABC section. Click on Login and enter one of those credentials into Auth0.
-
Return a list of movies that match the search term
-
Sample curl:
curl -H "Content-Type: application/json" -H "Authorization: Bearer {INSERT_TOKEN_HERE}" http://localhost:3000/actors?searchTerm=Jeff -
Sample response:
{ "actors": [ { "age": 27, "city": "New Castle", "genres": "Comedy|Crime|Romance", "id": 3, "image_link": "84.76.160.39", "name": "Jeff Petrushka", "phone": "7247585798", "seeking_description": "!@#$%^&*()", "seeking_movie": true, "sex": "Male", "state": "Pennsylvania", "website": "231.90.43.230" } ], "success": true, "total_actors": 1 } -
To get the tokens for this endpoints, we have to login with any role permission that is listed in RABC section. Click on Login and enter one of those credentials into Auth0.
-
Return actor info of an actor
-
Sample curl:
curl -H "Content-Type: application/json" -H "Authorization: Bearer {INSERT_TOKEN_HERE}" http://localhost:3000/actors/1 -
Sample response:
{ "actor": { "age": 43, "city": "Norman", "genres": "Comedy,Drama", "id": 1, "image_link": "http://google.com", "name": "Arabela Lebbern", "phone": "4056375359", "seeking_description": "I want a movie", "seeking_movie": true, "sex": "Male", "state": "AL", "website": "http://google.com" }, "success": true } -
To get the tokens for this endpoints, we have to login with any role permission that is listed in RABC section. Click on Login and enter one of those credentials into Auth0.
-
Update actor info by id
-
Sample curl:
curl -X PATCH -H "Content-Type: application/json" -H "Authorization: Bearer {INSERT_TOKEN_HERE}" http://localhost:3000/actors/1 \ -F age:43 \ -F city:Norman \ -F genres:Comedy \ -F genres:Drama \ -F image_link:http://google.com \ -F name:Arabela Lebbern \ -F phone:4056375359 \ -F seeking_description:I want a movie \ -F seeking_movie:true \ -F sex:Male \ -F state:AL \ -F website:http://google.com -
Sample response:
{ "actor": { "age": "43", "city": "Norman", "genres": "Comedy,Drama", "id": 1, "image_link": "http://google.com", "name": "Arabela Lebbern", "phone": "4056375359", "seeking_description": "I want a movie", "seeking_movie": true, "sex": "Male", "state": "AL", "website": "http://google.com" }, "success": true } -
To get the tokens for this endpoints, we have to login with 'Executive Producer' or 'Casting Director' role permission that is listed in RABC section. Click on Login and enter that credential into Auth0.
-
Create a new actor
-
Sample curl
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer {INSERT_TOKEN_HERE}" http://localhost:3000/actors \ -F age:43 \ -F city:Norman \ -F genres:Comedy \ -F genres:Drama \ -F image_link:http://google.com \ -F name:Arabela Lebbern \ -F phone:4056375359 \ -F seeking_description:I want a movie \ -F seeking_movie:true \ -F sex:Male \ -F state:AL \ -F website:http://google.com -
Sample response
{ "actor": { "age": null, "city": "Norman", "genres": "Comedy,Drama,Romance,War", "id": 11, "image_link": "http://google.com", "name": "Arabela Lebbern", "phone": "4056375359", "seeking_description": "I want a movie", "seeking_movie": true, "sex": null, "state": "AL", "website": "http://google.com" }, "success": true } -
To get the tokens for this endpoints, we have to login with 'Executive Producer' or 'Casting Director' role permission that is listed in RABC section. Click on Login and enter that credential into Auth0.
-
Delete an actor by id
-
Sample curl
curl -X DELETE -H "Content-Type: application/json" -H "Authorization: Bearer {INSERT_TOKEN_HERE}" http://localhost:3000/actors/11 -
Sample response
{ "id": "11", "success": true } -
To get the tokens for this endpoints, we have to login with 'Executive Producer' or 'Casting Director' role permission that is listed in RABC section. Click on Login and enter that credential into Auth0.
-
Return a list of castings in database
-
Sample curl
curl -H "Content-Type: application/json" -H "Authorization: Bearer {INSERT_TOKEN_HERE}" http://localhost:3000/castings -
Sample response
{ "castings": [ { "actor_id": 1, "id": 1, "movie_id": 1, "place": "23rd Lincon street", "start_time": "2014-12-11 23:30:34" }, { "actor_id": 1, "id": 2, "movie_id": 1, "place": "342street", "start_time": "2014-12-11 23:30:34" } ], "success": true, "total_castings": 2 } -
To get the tokens for this endpoints, we have to login with any role permission that is listed in RABC section. Click on Login and enter one of those credentials into Auth0.
-
Create a new casting
-
Sample curl
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer {INSERT_TOKEN_HERE}" http://localhost:3000/castings \ - F actor_id:1 \ - F movie_id:1 \ - F start_time:2014-12-11 23:30:34 \ - F place:342street -
Sample response
{ "casting": { "actor_id": "1", "id": 3, "movie_id": "1", "place": "342street", "start_time": "2014-12-11 23:30:34" }, "success": true } -
To get the tokens for this endpoints, we have to login with any role permission that is listed in RABC section. Click on Login and enter one of those credentials into Auth0.
-
Delete a casting by id
-
Sample curl
curl -X DELETE -H "Content-Type: application/json" -H "Authorization: Bearer {INSERT_TOKEN_HERE}" http://localhost:3000/castings/1 -
Sample response
{ "id": "3", "success": true } -
To get the tokens for this endpoints, we have to login with any role permission that is listed in RABC section. Click on Login and enter one of those credentials into Auth0.
All error return a json object with these keys: success, error and message
{
"success": False,
"error": 400,
"message": "Bad Request"
} {
"success": False,
"error": 404,
"message": "Not Found"
} {
"success": False,
"error": 405,
"message": "Method Not Allowed"
} {
"success": False,
"error": 422,
"message": "Unprocessable"
} {
"success": False,
"error": 500,
"message": "Internal Server Error"
}