项目作者: Philipotieno

项目描述 :
Capstone manages actors and movies
高级语言: Python
项目地址: git://github.com/Philipotieno/Capstone.git
创建时间: 2020-01-10T22:11:25Z
项目社区:https://github.com/Philipotieno/Capstone

开源协议:

下载


Coffee Shop Backend

Getting Started

Setup Auth0

  1. Create a new Auth0 Account
  2. Select a unique tenant domain
  3. Create a new, single page web application
  4. Create a new API
    • in API Settings:
      • Enable RBAC
      • Enable Add Permissions in the Access Token
  5. Create new API permissions:
    • get:actors
    • post:actors
    • patch:actors
    • delete:actors
    • get:movies
    • post:movies
    • patch:movies
    • delete:movies
  6. Create new roles for:
    • Casting Assistant
      • can - get:actors
        1. - `get:movies`
    • Casting Director
      • can - get:actors
        1. - `post:actors`
        2. - `patch:actors`
        3. - `delete:actors`
        4. - `get:movies`
        5. - `patch:movies`
    • Executive Producer
      • can - get:actors
        1. - `get:movies`
        2. - `post:movies`
        3. - `delete:movies`
  7. Test your endpoints with Postman.

    • Register 3 users and assign them the three roles
      1. User 1 - Casting Assistant
      2. User 2 - Casting Director
      3. User 3 - Executive Producer
    • Sign into each account and make note of the JWT.

      1. GET https://YOUR_DOMAIN/authorize?
      2. audience=YOUR_AUDIENCE&
      3. response_type=token&
      4. client_id=YOUR_CLIENT_ID&
      5. redirect_uri=https://callbackurl&
    • Import the postman collection ``
    • Right-clicking the collection folder for Casting Assistant, Casting Director, and Executive Producer
    • Navigate to the authorization tab, and including the JWT in the token field (you should have noted these JWTs).

Create Database

  1. $ sudo su postgres
  2. $ psql`
  3. postgres=# CREATE DATABASE capstone;
  4. postgres=# CREATE DATABASE capstone_test;`
  5. postgres=# \q
  6. $ exit

Installing Dependencies

Python 3.6

To run the server, execute:

  1. - Then add a .env file as shown in the following sample
  • source venv/bin/activate

  • export FLASK_APP="run.py"

  • export SECRET="some-very-long-string-of-random-characters-CHANGE-TO-YOUR-LIKING"
  • export APP_SETTINGS="development"

  • export DATABASE_URL="postgres://mitch:mufasa2019@localhost/capstone"

  • export TESTDB_URL="postgres://mitch:mufasa2019@localhost/capstone_test"

  • export AUTH0_DOMAIN="domain.auth0.com"

  • export API_AUDIENCE="your api audience"
    ```

To Create and activate the virtual environment

  1. $ virtualenv -p python3 venv
  2. $ pip install -r requirements.txt
  3. $ source .env

To Run migrations

  1. $ python manage.py db init
  2. $ python manage.py db migrate
  3. $ exit

To run the app

  1. $ flask run --reload

To run tests

  1. $ python test_app.py

Endpoints…

  1. localhost:5000
  2. heroku: https://capstone-philip.herokuapp.com/

POST ‘/actors’

  • Adds a new actor
  • Authorization required: Casting Director
  • Request Arguments: Actors body
  1. - Actors body:
  2. {
  3. "name": "Brad Pitt",
  4. "age": 56,
  5. "gender": "Male"
  6. }
  • Returns:
  1. {
  2. "actors": [
  3. {
  4. "age": 16,
  5. "gender": "Male",
  6. "id": 56,
  7. "name": "Brad Pitt"
  8. }
  9. ],
  10. "success": true
  11. }

GET ‘/actors’

  • Fetches a dictionary of all actors
  • Authorisation required: Casting Assistant/Casting Director/Executive Producer
  • Returns:
  1. {
  2. "actors": [
  3. {
  4. "age": 65,
  5. "gender": "Male",
  6. "id": 2,
  7. "name": "Brad"
  8. },
  9. {
  10. "age": 65,
  11. "gender": "Male",
  12. "id": 1,
  13. "name": "Jim Carrey"
  14. }
  15. ],
  16. "success": true
  17. }

GET ‘/actors/1’

  • Fetches a dictionary of one actor
  • Authorization required: Casting Assistant/Casting Director/Executive Producer
  • Returns:
  1. {
  2. "actor": {
  3. "age": 65,
  4. "gender": "Male",
  5. "id": 1,
  6. "name": "Jim Carrey"
  7. },
  8. "success": true
  9. }

DELETE ‘/actors/1’

  • Deletes an actor
  • Authorization required: Casting Director
  • Returns:
  1. {
  2. "deleted": 2,
  3. "success": true
  4. }

PATCH ‘/actors/1’

  • update actors name
  • Authorization required: Casting Director
  • Request Arguments: Actors body
  1. - Actors body:
  2. ```json5
  3. {
  4. "name": "Brad Pitt Jr",
  5. "age": 56,
  6. "gender": "Male"
  7. }
  • Returns:
  1. {
  2. "actors": [
  3. {
  4. "age": 16,
  5. "gender": "Male",
  6. "id": 56,
  7. "name": "Brad Pitt Jr"
  8. }
  9. ],
  10. "success": true
  11. }

POST ‘/movies’

  • Adds a new movies
  • Authorization required: Executive Producer
  • Request Arguments: movies body
  1. {
  2. "title": "Mad Max",
  3. "release_date": "5-6-2020"
  4. }
  • Returns:
  1. {
  2. "movie": [
  3. {
  4. "id": 14,
  5. "release_date": "Sat, 02 Feb 3202 00:00:00 GMT",
  6. "title": "Dark Night"
  7. }
  8. ],
  9. "success": true
  10. }

GET ‘/actors’

  • Fetches a dictionary of all movies
  • Authorisation required: Casting Assistant/Casting Director/Executive Producer
  • Returns:
  1. {
  2. "movie": [
  3. {
  4. "id": 14,
  5. "release_date": "Sat, 02 Feb 3202 00:00:00 GMT",
  6. "title": "Dark Night"
  7. },
  8. {
  9. "id": 14,
  10. "release_date": "Sat, 02 Feb 3202 00:00:00 GMT",
  11. "title": "Dark Night"
  12. }
  13. ],
  14. "success": true
  15. }

GET ‘/movie/1’

  • Fetches a dictionary of one movie
  • Authorization required: Casting Assistant/Casting Director/Executive Producer
  • Returns:
  1. {
  2. "movie": [
  3. {
  4. "id": 14,
  5. "release_date": "Sat, 02 Feb 3202 00:00:00 GMT",
  6. "title": "Dark Night"
  7. }
  8. ],
  9. "success": true
  10. }

DELETE ‘/movie/1’

  • Deletes a movies
  • Authorization required: Executive Producer
  • Returns:
  1. {
  2. "deleted": 2,
  3. "success": true
  4. }

PATCH ‘/movies/1’

  • Update movies title
  • Authorization required: Casting Director
  • Request Arguments: Movies body
  1. {
  2. "title": "Mad Max",
  3. "release_date": "5-6-2020"
  4. }
  • Returns:
  1. {
  2. "movie": [
  3. {
  4. "id": 14,
  5. "release_date": "Sat, 02 Feb 3202 00:00:00 GMT",
  6. "title": "Dark Night"
  7. }
  8. ],
  9. "success": true
  10. }

Errors

Bad request (400)

  1. {
  2. 'success': false,
  3. 'error': 400,
  4. 'message': 'Bad request'
  5. }

Not found (404)

  1. {
  2. 'success': false,
  3. 'error': 404,
  4. 'message': 'Resource Not Found'
  5. }

Unprocessable request (422)

  1. {
  2. 'success': false,
  3. 'error': 422,
  4. 'message': 'Unable to process request'
  5. }

Duplicate (409)

  1. {
  2. 'success': false,
  3. 'error': 409,
  4. 'message': 'Duplicate found'
  5. }
  6. ### Internal server error (500)
  7. ```json5
  8. {
  9. 'success': false,
  10. 'error': 500,
  11. 'message': 'Internal server error'
  12. }