Skip to content

Thembahank/events-manager-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Events Manager API

Welcome to the events manager API.

This API is intended as a backend to support the On Air Events Manager web app. which is currently in development.

The api provides endpoints for creating and managing events.

The API is organized around REST. All request and response bodies, including errors, encoded in JSON.

Getting Started

Install dependencies and setup your environment

Setup your virtual environment & then use the package manager pip

pip install -r requirements.txt

Setup your database

The app depends on postgres.

Create a new .env file at the root of your project to store the following variables:

DATABASE_URL=postgres://localhost:5432/events
TEST_DATABASE_URL=postgres://localhost:5432/em_test

With postgres running create new database 'events'.

Running the app

To run the server, execute the following (on windows use set instead of export:

export FLASK_APP=app.py
export FLASK_ENV=development
flask run

Setting the FLASK_ENV variable to development will detect file changes and restart the server automatically.

The application is run on http://127.0.0.1:5000/ by default.

Testing

Running the full test suite requires that the OAuth tokens be present in the env.

OAUTH_TEST_CREATOR_USER_TOKEN=eyJhbGci
OAUTH_TEST_ADMIN_CREATOR_USER_TOKEN=eyJhbGci

To run the test suite, recreate db and run the command.



dropdb em_test && createdb em_test && psql em_test < events.psql
python test_app.py

# heroku db
heroku login
heroku pg:reset DB_URL_HERE
heroku psql DB_URL_HERE < ./em.psql --app=app_name

The first time you run the tests, omit the dropdb command. All tests are kept in that file and should be maintained as updates are made to app functionality.

Deployment to heroku

  • Login to your heroku
heroku login
  • Create new app if one doesn't yet exist
heroku create
  • Create a new postgres database for your app and set vars
heroku addons:create heroku-postgresql:hobby-dev --app=eman-udacity
heroku config:set VARIABLE=VALUE
  • Deploy to Heroku
git add .
git commit -m "your message"
git push heroku master

The API Reference

Getting Started

The API is running at https://eman-udacity.herokuapp.com

Authentication & Endpoints

The API includes a public endpoint for viewing events as well as protected endpoints.

To access protected resources, an access token must be provided in the header. Please see example requests below.

The Events Manager API currently has two main types of users Creators and Admins (also known as admin-creators).

Admin-creators have elevated access scope with permissions including:

create:events
delete:events
get:creator
get:events-detail
patch:creator
patch:events
post:creator
read:events
update:events

Creators have limited access scopes with permission for managing events including:

create:events
get:creator	
get:events-detail	
patch:events	
read:events		
update:events

Public endpoints

GET /events/
  • General:
    • Returns a list of public events & success.
  • Sample: curl --location --request GET 'https://eman-udacity.herokuapp.com/events'
{
    "events": [
        {
            "category": "kids",
            "date": "Fri, 06 Aug 2021 00:00:00 GMT",
            "id": 6,
            "img": "https://images.unsplash.com/photo-1549451371-64aa98a6f660?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60",
            "title": "Sport jam at fun park"
        },
		...
        {
            "category": "funta",
            "date": "Fri, 01 Apr 2022 00:00:00 GMT",
            "id": 1,
            "img": "https://images.unsplas1510743006598-4845616e044f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60",
            "title": "Another fund event"
        }
    ],
    "success": true,
    "total_events": 11
}
Protected endpoints
GET /creatorEvents/
  • General:
    • Requires Auth: Returns of events by creator
  • Sample: curl --location --request GET 'https://eman-udacity.herokuapp.com/creatorEvents/1' --header 'Authorization: Bearer XX
{
    "creator": {
        "email": "creator@email.com",
        "id": 1,
        "oauth": "5ea5b6061cc1ac0c1467d4ee"
    },
    "events": [
        {
            "category": "kids",
            "date": "Fri, 06 Aug 2021 00:00:00 GMT",
            "id": 6,
            "img": "https://images.unsplash.com/photo-1549451371-64aa98a6f660?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60",
            "title": "Sport jam at fun park"
        },
        {
            "category": "sports",
            "date": "Wed, 05 Jan 2022 00:00:00 GMT",
            "id": 3,
            "img": "https://images.unsplash.com/photo-1502635385003-ee1e6a1a742d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60",
            "title": "Football on main"
        },
        {
            "category": "fun",
            "date": "Tue, 04 Jan 2022 00:00:00 GMT",
            "id": 5,
            "img": "https://images.unsplash.com/photo-1510743006598-4845616e044f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60",
            "title": "Fun day out with the kids"
        },
        {
            "category": "business",
            "date": "Wed, 06 Oct 2021 00:00:00 GMT",
            "id": 7,
            "img": "https://images.unsplash.com/photo-1570246159995-57eaeeca884b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60",
            "title": "Conference online"
        },
        {
            "category": "other",
            "date": "Sun, 07 Nov 2021 00:00:00 GMT",
            "id": 8,
            "img": "https://images.unsplash.com/photo-1530491396055-5aca4203edbf?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60",
            "title": "What do we have here"
        },
        {...},
        {
            "category": "business",
            "date": "Wed, 06 Oct 2021 00:00:00 GMT",
            "id": 11,
            "img": "https://images.unsplash.com/photo-1571411185401-e1e1682a2677?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60",
            "title": "Tell me some thing"
        },
        {
            "category": "other",
            "date": "Sun, 07 Nov 2021 00:00:00 GMT",
            "id": 12,
            "img": "https://images.unsplash.com/photo-1550057899-4c98740dc057?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60",
            "title": "Event four 30"
        },
    ],
    "success": true
}
POST
  • General:
    • Requires Auth: Creates a new event
  • Sample:curl --location --request POST 'https://eman-udacity.herokuapp.com/events' --header 'Authorization: Bearer
{
    "event": [
        {
            "category": "Sports",
            "date": "Thu, 08 Dec 2022 00:00:00 GMT",
            "id": 2,
            "img": "https://images.unsplas1510743006598-4845616e044f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60",
            "title": "Another fund event"
        }
    ],
    "success": true
}
PATCH (Admin access only)
  • General:
    • Requires Auth: Updates existing event
  • Sample curl --location --request PATCH 'https://eman-udacity.herokuapp.com/events/2' --header 'Authorization: Bearer
{
    "events": [
        {
            "category": "Dance",
            "date": "Thu, 08 Dec 2022 00:00:00 GMT",
            "id": 2,
            "img": "https://images.unsplas1510743006598-4845616e044f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60",
            "title": "Changed evend name"
        }
    ],
    "success": true
}
PATCH (Admin access only)
  • General:
    • Requires Auth: Delete existing events
  • Sample curl --location --request DELETE 'https://eman-udacity.herokuapp.com/events/2' --header 'Authorization: Bearer
{
    "delete": "2",
    "success": true
}

Endpoints for Creators (admin access only)

API endpoints for creating,viewing, updating and deleting Creators are not publicly available at this stage and require admin access.

Creation of user accounts will be available soon via the On Air Events Manager Dashboard. Please contact us to get on the waiting list.

  • General:
    • Requires Auth: Create a new creator
  • Sample: curl --location --request POST 'https://eman-udacity.herokuapp.com/creators' --header 'Authorization: Bearer
{
    "events": [
        {
            "age": "28",
            "email": "creator@email.com",
            "gender": null,
            "id": 3,
            "oauth": null,
            "phone": "0987892323"
        }
    ],
    "success": true
}

Error Handling

Errors are returned as JSON objects in the following format:

{
  "error": 404,
  "message": "Resource not found",
  "success": false
}

The API will return the following error types when requests fail:

  • 400: Bad Request
  • 404: Resource Not Found
  • 422: unprocessable
  • 405: Method not allowed
  • 500: Server error

Authors

Thembelani Mahlangu

Acknowledgements

Udacity team - Full stack dev course

OAuth - On permissions

Rudra Narayan. - Markdown in HTML

Marcelo Canina - Env variables in flask

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages