Skip to content

Flask App for creating movies and managing and assigning actors to those movies.

License

Notifications You must be signed in to change notification settings

allebd/casting-agency

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Casting Agency

Introduction

Flask App for creating movies and managing and assigning actors to those movies.

Table of Contents

Heroku Deployment

Application was deployed to Heroku. Use public URL https://casting-agency-allebd.herokuapp.com with API endpoints.

Technologies Used

Below are the key dependencies

  • 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.

Getting started

Clone

  • Clone this project to your local machine https://github.com/allebd/casting-agency.git
   git clone https://github.com/allebd/casting-agency.git

Installing Dependencies

Python 3.7

Follow instructions to install the latest version of python for your platform in the python docs

Virtual Environment

We recommend 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 virtual environment for your platform can be found in the python docs

PIP Dependencies

Once you have your virtual environment setup and running, install dependencies by running:

pip install -r requirements.txt

Database Setup

With Postgres running, restore a database using the casting.psql file provided. From the terminal run:

psql casting < casting.psql

Running the server

First ensure you are working using your created virtual environment.

To run the server, execute:

./setup.sh
flask run

Access Tokens

EXECUTIVE_PRODUCER = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Ik9EVTNNRVkxTlRnME1rWTFPRE00TlVORU9EbEJRakUwTVRoRk1qZzBOa1ZGUkRrelJFVXdRZyJ9.eyJpc3MiOiJodHRwczovL2Nhc3RpbmctYWxsZWJkLmF1dGgwLmNvbS8iLCJzdWIiOiJnb29nbGUtb2F1dGgyfDEwNzE1ODkwOTY3NDQzMDQwMjE2MyIsImF1ZCI6WyJjYXN0aW5nIiwiaHR0cHM6Ly9jYXN0aW5n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m1pc3Npb25zIjpbImdldDphY3RvcnMiLCJnZXQ6bW92aWVzIl19.c4aNdXBq_kVTXVBmKoFyQ8DwXNxBMjwUQHWyEYg8C9cE3MkA99o_Tme9V2taTXE06Tp2w5QA_l3bKQGH-3RMus4OYZRD_YQI8FtTPXmrC03fMvIzI6sdrVla8v48VAhWwQMxk5wMFtEZBL2RtByEhVK_PUAxZL3FGQOWjRcMx3HieuXFlAxhUpmbGZ2LIlMDN8y_H34rmKuli63fOG4brNSUkIqi_axM-TrCxSZY9xExhEHKiRiUrhRBcX4CC4vxKhqSkn4tt7HuCUqJ4HvvHx792AAu_E-Ru8__EekItsXeJgdgsM9nR0QJEjAN-RSGvBDD3ayCZJqL77-ZnpaYjQ'

Endpoints

NOTE:

  • Users should be logged in and must have the required permission to access endpoints
  • User permission include EXECUTIVE PRODUCER, CASTING DIRECTOR and CASTING ASSISTANT
  • The access tokens above can be used for the respective permitted endpoint
METHOD DESCRIPTION ENDPOINTS ACCESS PERMISSION PERMITTED USER
GET Get all movies /movies get:movies ALL USERS
GET Get a movie by id /movies/:movie_id get:movies ALL USERS
POST Create a movie /movies post:movies PRODUCER ONLY
PATCH Update a movie /movies/:movie_id patch:movies PRODUCER & DIRECTOR ONLY
DELETE Delete a movie /movies/:movie_id delete:movies PRODUCER ONLY
GET Get all actors /actors get:actors ALL USERS
GET Get an actor by id /actors/:actor_id get:actors ALL USERS
POST Create an actor /actors post:actors PRODUCER & DIRECTOR ONLY
PATCH Update an actor /actors/:actor_id patch:actors PRODUCER & DIRECTOR ONLY
DELETE Delete an actor /actors/:actor_id delete:actors PRODUCER & DIRECTOR ONLY
GET '/movies'
- Fetches a list of all movies the database
- Request Arguments: None
- Returns: An object with a keys: success, movies and total_movies
{
  "movies": [
    {
      "id": 1,
      "release_date": "Sat, 02 Feb 2019 00:00:00 GMT",
      "title": "Gemini Man"
    },
    {
      "id": 2,
      "release_date": "Mon, 03 Mar 2014 00:00:00 GMT",
      "title": "Home Alone"
    }
  ],
  "success": true,
  "total_movies": 2
}

***********************************************************************************************************************

GET '/movies/{movie_id}'
- Fetches a movie the database
- Request Arguments: movie_id
- Returns: An object with a keys: success, movie
{
  "movie": [
    {
      "id": 1,
      "release_date": "Sat, 02 Feb 2019 00:00:00 GMT",
      "title": "Home Alone"
    }
  ],
  "success": true
}

***********************************************************************************************************************

POST '/movies'
- Creates a movie in the database
- Request Arguments:
    {
        "title": <str>,
        "release_date": <str>,
    }
- Returns: A dictionary containing a success message if the operation was successful
{
  "message": "movie successfully added",
  "success": true,
  "movies": [
    {
      "id": 1,
      "release_date": "Sat, 02 Feb 2019 00:00:00 GMT",
      "title": "Gemini Man"
    },
    {
      "id": 2,
      "release_date": "Mon, 03 Mar 2014 00:00:00 GMT",
      "title": "Home Alone"
    }
  ]
}

***********************************************************************************************************************

PATCH '/movies/{movie_id}'
- Edits a movie from the database
- Request Arguments: movie_id
- Returns: A dictionary containing a success message if the operation was successful

{
  "movie": [
    {
      "id": 1,
      "release_date": "Sat, 02 Feb 2019 00:00:00 GMT",
      "title": "Home Alone"
    }
  ],
  "success": true,
  "message": 'movie successfully updated'
}

***********************************************************************************************************************

DELETE '/movies/{movie_id}'
- Deletes a movie from the database
- Request Arguments: movie_id
- Returns: A dictionary containing a success message if the operation was successful

{
  "deleted": 2,
  "movies": [
    {
      "id": 1,
      "release_date": "Sat, 02 Feb 2019 00:00:00 GMT",
      "title": "Gemini Man"
    },
    {
      "id": 2,
      "release_date": "Mon, 03 Mar 2014 00:00:00 GMT",
      "title": "Home Alone"
    }
  ],
  "success": true,
  "total_movies": 2
}

***********************************************************************************************************************

GET '/actors'
- Fetches a dictionary of actors in which the keys are the ids and the value is the corresponding string of the actor
- Request Arguments: None
- Returns: An object with a single key, actors, that contains a object of key:value pairs.
{
  "actors": [
    {
      "age": 43,
      "gender": "male",
      "id": 1,
      "name": "Ryan Reynolds"
    },
    {
      "age": 34,
      "gender": "male",
      "id": 2,
      "name": "Dave Franco"
    },
  ],
  "success": true,
  "total_actors": 2
}

***********************************************************************************************************************

GET '/actors/{actor_id}'
- Fetches a dictionary of actors in which the keys are the ids and the value is the corresponding string of the actor
- Request Arguments: actor_id
- Returns: An object with a single key, actors, that contains a object of key:value pairs.
{
  "actor": [
    {
      "age": 43,
      "gender": "male",
      "id": 1,
      "name": "Ryan Reynolds"
    }
  ],
  "success": true
}

***********************************************************************************************************************

POST '/actors'
- Creates a new actor in the database
- Request Arguments:
        {
            "name": <str>,
            "gender": <str>,
            "age": <int>
        }
- Returns: A dictionary containing a success message if the operation was successful
{
  "message": "movie successfully added",
  "success": true,
  "actors": [
    {
      "age": 43,
      "gender": "male",
      "id": 1,
      "name": "Ryan Reynolds"
    },
    {
      "age": 34,
      "gender": "male",
      "id": 2,
      "name": "Dave Franco"
    },
  ]
}

***********************************************************************************************************************

PATCH '/actors/{actor_id}'
- Edits an actor  from the database
- Request Arguments: actor_id
- Returns: A dictionary containing a success message if the operation was successful

{
  "actor": [
    {
      "age": 34,
      "gender": "male",
      "id": 2,
      "name": "Dave Franco"
    }
  ],
  "success": true,
  "message": 'actor successfully updated'
}

***********************************************************************************************************************

DELETE '/actors/{actor_id}'
- Deletes an actor from the database
- Request Arguments: actor_id
- Returns: A dictionary containing a success message if the operation was successful

{
  "deleted": 2,
  "actors": [
    {
      "age": 43,
      "gender": "male",
      "id": 1,
      "name": "Ryan Reynolds"
    },
    {
      "age": 34,
      "gender": "male",
      "id": 2,
      "name": "Dave Franco"
    },
  ],
  "success": true,
  "total_actors": 2
}

Running Unit Test

To run tests, execute:

dropdb casting_test && createdb casting_test
./setup_test.sh

Acknowledgements

Author

Bella Oyedele

About

Flask App for creating movies and managing and assigning actors to those movies.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published