Giter VIP home page Giter VIP logo

casting-agency's Introduction

Casting Agency

Site live at : https://casting-agency-0426.herokuapp.com

This project is my capstone project for Udacity's Fullstack Nanodegree program. It models a company that is responsible for creating movies and managing and assigning actors to those movies. Authorized users can interact with the API to view,add,update,delete Movies and Actors details.

API

In order to use the API users need to be authenticated. Jwt tokens can be generated by logging in with the provided credentials on the hosted site.

Endpoints

GET /movies

  • General:

    • Returns all the movies.
    • Roles authorized : Casting Assistant,Casting Director,Executive Producer.
  • Sample: curl http://127.0.0.1:5000/movies

{
  "movies": [
    {
      "id": 1,
      "release_date": "Mon, 06 May 2019 00:00:00 GMT",
      "title": "Terminator Dark Fate"
    },
    {
      "id": 2,
      "release_date": "Tue, 06 May 2003 00:00:00 GMT",
      "title": "Terminator Rise of the machines"
    }
  ],
  "success": true
}

GET /movies/<int:id>

  • General:

    • Route for getting a specific movie.
    • Roles authorized : Casting Assistant,Casting Director,Executive Producer.
  • Sample: curl http://127.0.0.1:5000/movies/1

{
  "movie": {
    "id": 1,
    "release_date": "Mon, 06 May 2019 00:00:00 GMT",
    "title": "Terminator Dark Fate"
  },
  "success": true
}

POST /movies

  • General:

    • Creates a new movie based on a payload.
    • Roles authorized : Executive Producer.
  • Sample: curl http://127.0.0.1:5000/movies -X POST -H "Content-Type: application/json" -d '{ "title": "Natasha romanov", "release_date": "2020-05-06" }'

{
  "movie": {
    "id": 3,
    "release_date": "Wed, 06 May 2020 00:00:00 GMT",
    "title": "Natasha romanov"
  },
  "success": true
}

PATCH /movies/<int:id>

  • General:

    • Patches a movie based on a payload.
    • Roles authorized : Casting Director, Executive Producer.
  • Sample: curl http://127.0.0.1:5000/movies/3 -X POST -H "Content-Type: application/json" -d '{ "title": "Natasha romanov patched", "release_date": "2020-05-06" }'

{
  "movie": {
    "id": 3,
    "release_date": "Wed, 06 May 2020 00:00:00 GMT",
    "title": "Natasha romanov patched"
  },
  "success": true
}

DELETE /movies/int:id\

  • General:

    • Deletes a movies by id form the url parameter.
    • Roles authorized : Executive Producer.
  • Sample: curl http://127.0.0.1:5000/movies/3 -X DELETE

{
  "message": "movie id 3, titled Natasha romanov patched was deleted",
  "success": true
}

GET /actors

  • General:

    • Returns all the actors.
    • Roles authorized : Casting Assistant,Casting Director,Executive Producer.
  • Sample: curl http://127.0.0.1:5000/actors

{
  "actors": [
    {
      "age": 40,
      "gender": "male",
      "id": 1,
      "name": "Will Smith"
    },
    {
      "age": 50,
      "gender": "male",
      "id": 2,
      "name": "Bruce Wills"
    }
  ],
  "success": true
}

GET /actors/<int:id>

  • General:

    • Route for getting a specific actor.
    • Roles authorized : Casting Assistant,Casting Director,Executive Producer.
  • Sample: curl http://127.0.0.1:5000/actors/1

{
  "actor": {
    "age": 40,
    "gender": "male",
    "id": 1,
    "name": "Will Smith"
  },
  "success": true
}

POST /actors

  • General:

    • Creates a new actor based on a payload.
    • Roles authorized : Casting Director,Executive Producer.
  • Sample: curl http://127.0.0.1:5000/actors -X POST -H "Content-Type: application/json" -d '{ "name": "Mary", "age": 22, "gender": "female" }'

{
  "actor": {
    "age": 22,
    "gender": "female",
    "id": 3,
    "name": "Mary"
  },
  "success": true
}

PATCH /actors/<int:id>

  • General:

    • Patches an actor based on a payload.
    • Roles authorized : Casting Director, Executive Producer.
  • Sample: curl http://127.0.0.1:5000/actors/3 -X POST -H "Content-Type: application/json" -d '{ "name": "John", "age": 22, "gender": "female" }'

{
  "actor": {
    "age": 22,
    "gender": "female",
    "id": 3,
    "name": "John"
  },
  "success": true
}

DELETE /actors/int:id\

  • General:

    • Deletes an actor by id form the url parameter.
    • Roles authorized : Casting Director,Executive Producer.
  • Sample: curl http://127.0.0.1:5000/actors/3 -X DELETE

{
  "message": "actor id 3, named John was deleted",
  "success": true
}

Project dependencies

Getting Started

Installing Dependencies

Python 3.7

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

Virtual Enviornment

To setup vurtual environment run the following command

pipenv shell

Installing Dependencies

pipenv install -r requirements.txt

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

Database Setup

The project uses Postgresql as its database, you would need to create one locally and reflect it in setup.sh. To update the database and seed run the following :

python manage.py db upgrade
python manage.py seed
  • you may need to change the database url in setup.sh after which you can run
source setup.sh
  • Start server by running
flask run
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.

  • Pycodestyle - pycodestyle is a tool to check your Python code against some of the style conventions in PEP 8.

Testing

Replace the jwt tokens in test_app.py with the ones generated on the website.

For testing locally, we need to reset database. To reset database, run

python manage.py db downgrade
python manage.py db upgrade
python manage.py seed

Error Handling

  • 401 errors due to RBAC are returned as
{
  "code": "unauthorized",
  "description": "Permission not found."
}

Other Errors are returned in the following json format:

{
  "success": "False",
  "error": 422,
  "message": "Unprocessable entity"
}

The error codes currently returned are:

  • 400 – bad request
  • 401 – unauthorized
  • 404 – resource not found
  • 422 – unprocessable
  • 500 – internal server error

casting-agency's People

Contributors

pranavswaroopreddy avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.