apitos / FSND-Capstone

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Casting Agency

Project Description

This is the capstone project for Full - Stack Udacity Nanodegree. Casting Agency models a company that is responsible for creating movies and managing and assigning actors to those movies. There are three different roles in the company Casting Assistant, Casting Director, and Executive Producer. Each of them has a different set of permissions to view, add, update and delete movies and actors in the databse.

The work are done in the back - end. I wrote Restful APIs, built a database using SQLAlchemey, secured the application using Auth0, tested the application using unit tests and via Postman, and finally deploy the application to Heroku.

Motivation

This is my Capstone(Casting Agency) project for the Udacity FSND.

Project Result

Heroku: https://capstone-castingag-app.herokuapp.com/

Localhost: http://127.0.0.1:5000/

The code is conform to the PEP 8 style guide. It's automatically format by: $ autopep8 --in-place --aggressive --aggressive <filename>

Tech Stack

  • PostgreSQL as our database of choice
  • Python3 and Flask as our server language and server framework
  • Auth0 for authentication management
  • Heroku for deployment
  • JSON for rendering the results.
  • HTML, CSS is planned for the next development of the application.

Getting Started

  1. Initialize and activate a virtualenv:

    $ cd YOUR_PROJECT_DIRECTORY_PATH/
    $ virtualenv --no-site-packages venv
    $ source venv/bin/activate # for MAC
    $ source venv/Scripts/activate # for Windows
    
  2. Install the dependencies:

    $ pip install -r requirements.txt
    

    This will install all of the required packages we selected within the requirements.txt file.

  3. run source setup.sh to set the environnement variables, and the user tokens the user jwts, auth0 credentials

  4. Database Setup

# create capstone database
CREATE DATABASE capstone
  1. Run the development server:
    $ export FLASK_APP=myapp
    $ export FLASK_ENV=development  # enables debug mode
    $ flask run --reload  # reload server after any changes detected
    

Testing

To run the tests, run

dropdb capstone
createdb capstone
python -m unittest test_app.py

Casting app roles and permissions

Users can access the app's homepage anonymously and its functionality via three roles with specific access permissions.

  1. Casting assistant: Can view and list details of actors and movies.
Casting assistant login credentials
User: casting_assistant@gmail.com
Password: capstone123!
  1. Casting director: Can view and list actor and movie details, add, edit and delete actor, and finally it can only edit movie.
Casting assistant login credentials
User: casting_director@gmail.com
Password: capstone123!
  1. Executive producer: Full access, with the ability to view, edit, update, and delete both movie projects and actors.
Executive producer login credentials
User: executive_producer@gmail.com
Password: capstone123!

API Reference

Endpoints

GET '/movies'

  • General:
    • Return all movies in the database
    • Role Authorized: Casting Assistant, Casting Director, Executive Producer
  • Example: curl - H "Authorization: Bearer <Token>" http://127.0.0.1:5000/movies
{
    "movies":
        {
            "1":
                {
                    "actors": [
                        {
                            "age": 22,
                            "gender": "Male",
                            "id": 1,
                            "movie_id": 1,
                            "name": "Jack"
                        }],
                    "id": 1,
                    "release_date": "1966",
                    "title": "Bibro"
                },
            "2":
                {
                    "actors": [
                        {
                            "age": 35,
                            "gender": "Male",
                            "id": 11,
                            "movie_id": 2,
                            "name": "Brown"
                        }],
                    "id": 2,
                    "release_date": "2010",
                    "title": "March of the Penguins"
                },
            "3":
                {
                    "actors": [
                        {
                            "age": 60,
                            "gender": "Female",
                            "id": 10,
                            "movie_id": 3,
                            "name": "Michelle"
                        }],
                    "id": 3,
                    "release_date": "2010",
                    "title": "Way down"
                },
            "success": true
        }
}

GET '/actors'

  • General:
    • Return all actors in the database
    • Role Authorized: Casting Assistant, Casting Director, Executive Producer
  • Example: curl - H "Authorization: Bearer <Token>" http://127.0.0.1:5000/actors
{
    "actors":
        {
            "1":
                {
                    "age": 22,
                    "gender": "Male",
                    "id": 1,
                    "movie_id": 1,
                    "name": "Jack"
                },
            "3":
                {
                    "age": 32,
                    "gender": "Male",
                    "id": 3,
                    "movie_id": 10,
                    "name": "Julian"
                },
            "4":
                {
                    "age": 55,
                    "gender": "Female",
                    "id": 4,
                    "movie_id": 9,
                    "name": "Mary"
                }
        },
    "success": true
}

POST '/movies'

  • General:
    • Add a new movie. The new movie must have all two information.
    • Role Authorized: Executive Producer
  • Example: curl - X POST http://127.0.0.1:5000/movies - H "Content-Type: application/json" - H "Authorization: Bearer <TOKEN>" - d '{"title": "Locked Down", "release_date": "2021"}'
{
    "movies":
        {
            "45":
                {
                    "actors": [],
                    "id": 45,
                    "release_date": "2021",
                    "title": "Locked Down"
                }
        },
    "success": true
}

POST '/actors'

  • General:
    • Add a new actor. The new movie must have all four information.
    • Role Authorized: Casting Director, Executive Producer
  • Example: curl - X POST http://127.0.0.1:5000/actors - H "Content-Type: application/json" - H "Authorization: Bearer <TOKEN>" - d '{"name": "Anne Hathaway", "age": 39, "gender": "Female", "movie_id": 45}'
{
    "actors":
        {
            "12":
                {
                    "age": 39,
                    "gender": "Female",
                    "id": 12,
                    "movie_id": 45,
                    "name": "Anne Hathaway"
                }
        },
    "success": true
}

PATCH '/movies/int:movie_id'

  • General:
    • Update some information of a movie based on a payload.
    • Roles authorized: Casting Director, Executive Producer.
  • Example: curl - X PATCH http://127.0.0.1:5000/movies/42 - H "Content-Type: application/json" - H "Authorization: Bearer <TOKEN>" - d '{"title":"The Empire", "release_date":"1988"}'
{
    "movies":
        {
            "42":
                {
                    "actors": [
                        {
                            "age": 22,
                            "gender": "Female",
                            "id": 6,
                            "movie_id": 42,
                            "name": "Yu"
                        }],
                    "id": 42,
                    "release_date": "1988",
                    "title": "The Empire"
                },
            "success": true
        }
}

PATCH '/actors/int:actor_id'

  • General:
    • Update some information of an actor based on a payload.
    • Roles authorized: Casting Director, Executive Producer.
  • Example: curl - X PATCH http://127.0.0.1:5000/actors/1 - H "Content-Type: application/json" - H "Authorization: Bearer <TOKEN>" - d '{"name": "Julian Grey", "age": 32, gender:"Male", "movie_id":10}'
{
    "actors":
        {
            "3":
                {
                    "age": 32,
                    "gender": "Male",
                    "id": 3,
                    "movie_id": 10,
                    "name": "Julian Grey"
                }
        },
    "success": true
}

DELETE '/movis/int:movie_id'

  • General:
    • Deletes a movie by id from the url parameter.
    • Roles authorized: Executive Producer.
  • Example: curl - X DELETE http://127.0.0.1:5000/movies/10 - H "Content-Type: application/json" - H "Authorization: Bearer <TOKEN>"
{
    "deleted": 10,
    "success": true
}

DELETE '/actors/int:actor_id'

  • General:
    • Deletes a movie by id form the url parameter.
    • Roles authorized: Casting Director, Executive Producer.
  • Example: curl - X DELETE http://127.0.0.1:5000/actors/5 - H "Content-Type: application/json" - H "Authorization: Bearer <TOKEN>"
{
    "deleted": 5,
    "success": true
}

Error Handling

Errors are returned in the following json format:

{
    'success': False,
    'error': 404,
    'message': 'Resource not found. Input out of range.'
}

The API returns 7 types of errors:

  • 400: bad request
  • 401: unauthorized
  • 404: not found
  • 403: forbidden
  • 405: method not allowed
  • 422: unprocessable
  • 500: internal server error

About


Languages

Language:Python 88.6%Language:Shell 10.0%Language:Mako 1.4%