It is the year 2030 and IMDB crashed, it is up to you to create a database for people to see which actor was in which movie. You are movie lovers only hope, may the force be with you.
In this repo:
- There is a Flask application with some features built out.
You can check your API by:
- Using Postman, Thunder Client or a different request engine to make requests
To download the dependencies for the frontend and backend, run:
pipenv install && pipenv shell
You can run your Flask API on localhost:5555
by
running:
python server/app.py
Your job is to build out the Flask API to add the functionality described in the deliverables below.
It is your job to build out Movie, Actor, and Credit models so that Actors can be in Movies. In a given credit, one Actor will be in one Movie. Over their careers, Actors will be in many Movies and Movies will be have many Actors.
You will implement an API for the following data model:
The file server/models.py
defines the model classes without relationships or fields.
Create the fields based off the above schema.
Now you can implement the relationships as shown in the ER Diagram:
- A
Actor
has manyMovie
throughCredit
s - An
Movie
has manyActor
s throughCredit
s - A
Credit
belongs to aMovie
and belongs to aActor
Update server/models.py
to establish the model relationships. Since a
Credit
belongs to a Actor
and a Movie
, configure the model to
cascade deletes.
After creating the relationships, we intialize our DB, create our migration, upgrade our database with our migration:
cd server/
export FLASK_APP=app.py
flask db init
flask db migrate
flask db upgrade
Set serialization rules to limit the recursion depth.
Seed the database:
python seed.py
If you aren't able to get the provided seed file working, you are welcome to generate your own seed data to test the application.
Add validations to the Actor
model:
- must have a
name
, and anage
that is great than 10
Add validations to the Credit
model:
- must have a
role
, aactor_id
and amovie_id
role
must be either: ["Performer", "Director", "Producor", "Playwright", "Lighting Design", "Sound Design", "Set Design"].
Add validations to the Movie
model:
- must have a
rating
between 1 and 10. genre
must be one of the following: [ "Action", "Comedy", "Drama", "Horror", "Romance", "Thriller", "Science Fiction", "Fantasy", "Mystery", "Adventure", "Crime", "Family", "Animation", "Documentary", "War" ]
Set up the following routes. Make sure to return JSON data in the format specified along with the appropriate HTTP verb.
Recall you can specify fields to include or exclude when serializing a model instance to a dictionary using to_dict() (don't forget the comma if specifying a single field).
NOTE: If you choose to implement a Flask-RESTful app, you need to add code to
instantiate the Api
class in server/app.py.
Return JSON data, without any additional nested data related to each actor.
If the Actor
exists, return JSON data. Make sure to include a list of Movies for the actor.
If the Actor
does not exist, return the following JSON data, along with
the appropriate HTTP status code:
{
"error": "Actor not found"
}
This route should create a new Actor
. It should accept an object with the
following properties in the body of the request:
{
"name": "Shawn Horizon",
"age": 52
}
If the Actor
is created successfully, send back a response with the new Actor
.
If the Actor
is not created successfully due to validation errors,
return the following JSON data, along with the appropriate HTTP status code:
{
"errors": ["validation errors"]
}
This route should update an existing Actor
. It should accept an object
with one or more of the following properties in the body of the request:
{
"name": "Bevan Horizon",
"age": 12
}
If the Actor
is updated successfully, send back a response with the updated Actor
and a 202 accepted
status code.
If the Actor
is not updated successfully, return the following JSON
data, along with the appropriate HTTP status code:
{
"errors": ["validation errors"]
}
OR, given an invalid ID, the appropriate HTTP status code, and the following JSON:
{
"error": "Actor not found"
}
If the Actor
exists, it should be removed from the database, along with
any Credit
s that are associated with it. If you did not set up your models to
cascade deletes, you need to delete associated Credit
s before the Actor
can be deleted.
After deleting the Actor
, return an empty response body, along with the
appropriate HTTP status code.
If the Actor
does not exist, return the following JSON data, along with
the appropriate HTTP status code:
{
"error": "Actor not found"
}
Return JSON data without any additional nested data related to each movie.
This route should create a new Movie
. It should accept an object with the following properties in the body of the request:
{
"image": "https://flxt.tmsimg.com/assets/p1036_p_v12_an.jpg",
"title": "Blazing Saddles",
"genre": "Action",
"rating": 7,
"description": "In this satirical take on Westerns, crafty railroad worker Bart (Cleavon Little) becomes the first black sheriff of Rock Ridge, a frontier town about to be destroyed in order to make way for a new railroad. Initially, the people of Rock Ridge harbor a racial bias toward their new leader. However, they warm to him after realizing that Bart and his perpetually drunk gunfighter friend (Gene Wilder) are the only defense against a wave of thugs sent to rid the town of its population."
}
If the Movie
is created successfully, send back a response about the new movie.
If the Movie
is not created successfully, return the following JSON data, along with the appropriate HTTP status code:
{
"errors": ["validation errors"]
}
Return JSON data without any additional nested data related to each credit.
If the Credit
exists, Make sure to include the actor and movie associated.
If the Credit
does not exist, return the following JSON data, along with
the appropriate HTTP status code:
{
"error": "Credit not found"
}
This route should create a new Credit
. It should accept an object with the
following properties in the body of the request:
{
"actor_id": 2,
"movie_id": 1,
"role": "Performer"
}
If the Credit
is created successfully, send back a response with the new Credit
.
If the Credit
is not created successfully due to validation errors,
return the following JSON data, along with the appropriate HTTP status code:
{
"errors": ["validation errors"]
}
This route should update an existing Credit
. It should accept an object
with one or more of the following properties in the body of the request:
{
"role": "Director",
}
If the Actor
is updated successfully, send back a response with the updated Actor
and a 202 accepted
status code.
If the Credit
is not updated successfully, return the following JSON
data, along with the appropriate HTTP status code:
{
"errors": ["validation errors"]
}
OR, given an invalid ID, the appropriate HTTP status code, and the following JSON:
{
"error": "Credit not found"
}
If the Credit
exists, it should be removed from the database.
After deleting the Credit
, return an empty response body, along with the
appropriate HTTP status code.
If the Credit
does not exist, return the following JSON data, along with
the appropriate HTTP status code:
{
"error": "Credit not found"
}