Skip to content

Api built with Python Flask Web Framework and Postgres backend for voting system

License

Notifications You must be signed in to change notification settings

odaridavid/POLITICO-API

Repository files navigation

POLITICO-API

POLITICO API Is a pure Flask REST API app that serves endpoints for political parties,government offices, petitioning,voting and user login and sign up to be consumed by front end frameworks.

'PythonVersion'' 'License' 'Travis' Coverage Status Maintainability Codacy Badge Known Vulnerabilities

Endpoints

Url Prefix - /api/v1/

Version 1
ENDPOINT METHOD STATUS
/offices GET Gets List of offices
/offices POST Adds an office to List of offices
/parties GET Gets List of Parties
/parties POST Adds a party to list of parties
/parties/<party_id> GET Gets a specific party
/parties/<party_id>/name PATCH Updates Name value of a party
/parties/<office_id>/name PATCH Updates Office value of a office
/parties/<party_id> DELETE Deletes Specified Party
/offices/<office_id> DELETE Deletes Specified Office
/offices/<offices_id> GET Gets a specific office
/users POST Adds User to List Of Users

Url Prefix - /api/v2/

Version 2
ENDPOINT METHOD STATUS
/offices GET Gets List of offices
/offices POST Adds an office to List of offices
/parties GET Gets List of Parties
/parties POST Adds a party to list of parties
/parties/<party_id> GET Gets a specific party
/parties/<party_id>/name PATCH Updates Name value of a party
/parties/<office_id>/name PATCH Updates Office value of a office
/parties/<party_id> DELETE Deletes Specified Party
/offices/<office_id> DELETE Deletes Specified Office
/offices/<offices_id> GET Gets a specific office
/auth/signup POST Sign Up A User
/auth/login POST Login An Existing User
/offices/<office_id>/register POST Sign Up A Candidate For An Office
/offices/<office_id>/register GET Get A Candidate For A Specific Office
/auth/login POST Login An Existing User
/votes/ POST Users Can Vote
/office/<office_id>/results POST Users Can Vote

Author

David Odari

Testing and Running Of App

Heroku

App Link Hosted On Heroku

POLITICO-API on Heroku

API Documentation

POLITICO DOCS

Local Machine
  1. From your terminal clone The Repository on your machine \ it will be on develop branch git clone https://github.com/Davidodari/POLITICO-API.git

  2. Start virtual env if is installed and created ,with python 3\ . venv/bin/activate
    to install the virtual env if missing use
    pip3 install virtualenv
    and create virtual environment using the
    python3 -m venv venv

    Then Run The Above Commands to activate the virtual env when on the root folder of the project which will be Politico API

  3. Install Flask in Virtual Environment

    • The terminal will be instatiate a virtual env and appear similar to what is shown below
      (venv)blackcoder@blackPC:~/POLITICO-API$
    • Then Run
      pip install -r requirements.txt
      to download required packages for Flask
  4. Run Flask App

    • Then run the following commands to set up the environment and config in the terminal
      • export FLASK_APP=run.py
      • export FLASK_ENV=development
      • export FLASK_DEBUG=1 ,This will reduce need to restart server in case you make changes
    • A link to where the app is hosted will appear in the terminal as shown in the below format
          * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
    
    • With the above link apply a url prefix /api/v1 such that its http://127.0.0.1:5000/api/v1/endpoints
  5. Using an API Test Client like Postman or Insomnia you can run the above endpoints for each request. The Bodys of Requests are below\

    Models

    Office

    {
    "name":"office_name",
    "type":"office_type"
    }
    

    Party

    {
    "name":"party_name",
    "hqAddress":"party_address",
    "logoUrl":"party_logo"
    }
    

    User

    {
    "firstname":"first_name",
    "lastname":"last_name",
    "othername":"other_name",
    "email":"dedaap@them.mail.com",
    "phoneNumber":"+123442211",
    "password":"password"
    }
    

    As for update just use name key and value on offices and parties

  6. For unit tests on the root folder run pytest --cov api tests command and tests will automatically be run with coverage If not installed run the following command in terminal to install pytest with coverage in venv and run above
    pip install -U pytest-cov