Skip to content

Commit

Permalink
Merge pull request #6 from JoshuaOndieki/develop
Browse files Browse the repository at this point in the history
Tested API version v1.0
  • Loading branch information
JoshuaOndieki authored Mar 10, 2018
2 parents 6582f77 + bc89b79 commit 2f98fa0
Show file tree
Hide file tree
Showing 28 changed files with 1,239 additions and 6 deletions.
104 changes: 104 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pytest
.pytest_cache

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
.venv
venv/
ENV/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: python
python:
- "3.6"
# command to install dependencies
install:
- pip install -r requirements.txt

# command to run tests
script: nosetests --with-coverage --cover-package=weconnect && coveralls

after_success: coveralls
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn app:app
40 changes: 34 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# WeConnect ui
This repo contains(currently) non-functional UI templates for the WeConnect project. A platform that brings businesses and individuals together. This platform creates awareness for businesses and gives the users the ability to write reviews about the businesses they have interacted with.
# WeConnect
This repo contains(currently) non-functional UI templates and a Flask API for the WeConnect project. A platform that brings businesses and individuals together. This platform creates awareness for businesses and gives the users the ability to write reviews about the businesses they have interacted with.

[![Maintainability](https://api.codeclimate.com/v1/badges/cc73c060a8797ec0099f/maintainability)](https://codeclimate.com/github/JoshuaOndieki/weconnect-ui/maintainability) [![Coverage Status](https://coveralls.io/repos/github/JoshuaOndieki/weconnect/badge.svg?branch=master)](https://coveralls.io/github/JoshuaOndieki/weconnect?branch=master) [![Build Status](https://travis-ci.org/JoshuaOndieki/weconnect.svg?branch=master)](https://travis-ci.org/JoshuaOndieki/weconnect) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/1cdd8a328b3a4ae3ab03854da7521aa9)](https://www.codacy.com/app/JoshuaOndieki/weconnect?utm_source=github.com&utm_medium=referral&utm_content=JoshuaOndieki/weconnect&utm_campaign=Badge_Grade)
[![Maintainability](https://api.codeclimate.com/v1/badges/fd1b6c22bebb59492101/maintainability)](https://codeclimate.com/github/JoshuaOndieki/weconnect/maintainability) [![Coverage Status](https://coveralls.io/repos/github/JoshuaOndieki/weconnect/badge.svg?branch=master)](https://coveralls.io/github/JoshuaOndieki/weconnect?branch=master) [![Build Status](https://travis-ci.org/JoshuaOndieki/weconnect.svg?branch=master)](https://travis-ci.org/JoshuaOndieki/weconnect) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/1cdd8a328b3a4ae3ab03854da7521aa9)](https://www.codacy.com/app/JoshuaOndieki/weconnect?utm_source=github.com&utm_medium=referral&utm_content=JoshuaOndieki/weconnect&utm_campaign=Badge_Grade)


## Motivation
Expand All @@ -11,14 +11,42 @@ The project defination can be found [here](https://docs.google.com/document/d/1i

## Installation

(Currently) This project does not need any other installation apart from a browser.
The UIs can be viewed and tested at [joshuaondieki.github.io](https://joshuaondieki.github.io/)
To test the UIs install a browser of your choice.
The UIs can be viewed and manually tested at [joshuaondieki.github.io](https://joshuaondieki.github.io/)
Alternatively, clone this repo and test the UIs locally.

### Flask API
1. Install Python 3.6.4
2. Git clone this repo.
3. cd to the root dir of this repo.
4. Create a virtual env and `pip install -r requirements.txt`
5. Run the app with `python app.py` or `python3 app.py`
6. Checkout the endpoints and test them with a tool like [POSTMAN](https://www.getpostman.com)

#### Heroku
This Flask API has been hosted to heroku at [Wecon](https://wecon.herokuapp.com)

## API ENDPOINTS


EndPoint | Functionality
-- | --
POST `/api/v1/auth/register` | Creates a user account
POST `/api/v1/auth/login` | Logs in a user
POST `/api/v1/auth/logout` | Logs out a user
POST `/api/v1/auth/reset-password` | Password reset
POST  `/api/v1/businesses` | Register a business
PUT `/api/v1/businesses/<businessId>` | Updates a business profile
DELETE `/api/v1//businesses/<businessId>` | Remove a business
GET  `/api/v1/businesses` | Retrieves all businesses
GET  `/api/v1/businesses/<businessId>` | Get a business
POST  `/api/v1/businesses/<businessId>/reviews` | Add a review for a business
GET  `/api/v1/businesses/<businessId>/reviews` | Get all reviews for a business


## Contributors
- [Joshua Ondieki](https://www.github.com/JoshuaOndieki/)
- Some credits go to fellow bootcampers for the support and assistance.
- Some credits go to fellow bootcampers, LFAs and Andela for the support and assistance.

A Pivotal tracker board was used in planning and managing this project. The board is publicly available [here](https://www.pivotaltracker.com/n/projects/2153376)

Expand Down
8 changes: 8 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from weconnect import create_app


app = create_app('development')


if __name__ == "__main__":
app.run()
27 changes: 27 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
basedir = os.path.abspath(os.path.dirname(__file__))


class Config:
"""
Application configuration
"""
SECRET_KEY = 'secret'
WTF_CSRF_ENABLED = False


class DevelopmentConfig(Config):
DEBUG = True


class ProductionConfig(Config):
DEBUG = False


class TestingConfig(Config):
DEBUG = True


config = {'development': DevelopmentConfig,
'testing': TestingConfig,
'production': ProductionConfig}
26 changes: 26 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
aniso8601==2.0.1
attrs==17.4.0
certifi==2018.1.18
chardet==3.0.4
click==6.7
coverage==4.5.1
coveralls==1.3.0
docopt==0.6.2
Flask==0.12.2
Flask-JWT-Extended==3.7.1
Flask-RESTful==0.3.6
gunicorn==19.7.1
idna==2.6
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
nose==1.3.7
pluggy==0.6.0
py==1.5.2
PyJWT==1.6.0
pytest==3.4.2
pytz==2018.3
requests==2.18.4
six==1.11.0
urllib3==1.22
Werkzeug==0.14.1
1 change: 1 addition & 0 deletions runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.6.4
53 changes: 53 additions & 0 deletions weconnect/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from flask import Flask
from config import config
from .api.v1.routes import v1
from flask_jwt_extended import JWTManager


# multi dimentional dict storing app data in form of objects
database = {"Users": {}, "Businesses": {}, "Reviews": {}}

"""
---------------------- DATA STRUCTURE -----------------
{
Users:
{
userx: [email, password]
...
}
Businesses:
{
bsx: [name, location, category, userid]
...
}
Reviews:
{
revx: [content, bsid, userid]
...
}
}
"""


def create_app(config_name):
"""
Usage: Factory function used to setup the application instance
:return: application instance
"""
app = Flask(__name__)
app.database = database
app.config.from_object(config[config_name])
app.config['JWT_SECRET_KEY'] = 'super-secret'
app.config['JWT_BLACKLIST_ENABLED'] = True
app.config['JWT_BLACKLIST_TOKEN_CHECKS'] = ['access', 'refresh']
app.jwt = JWTManager(app)
app.blacklist = set()

@app.jwt.token_in_blacklist_loader
def check_if_token_in_blacklist(decrypted_token):
jti = decrypted_token['jti']
return jti in app.blacklist
app.register_blueprint(v1, url_prefix="/api/v1")
return app
Empty file added weconnect/api/__init__.py
Empty file.
Empty file added weconnect/api/v1/__init__.py
Empty file.
23 changes: 23 additions & 0 deletions weconnect/api/v1/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from flask import Blueprint
from flask_restful import Api
from weconnect import resources as r


v1 = Blueprint('v1', __name__)
api = Api(v1)
add = api.add_resource


add(r.All, '/all') # GET
# User Routes
add(r.UserRegistration, '/auth/register') # POST
add(r.UserLogin, '/auth/login') # POST
add(r.UserLogout, '/auth/logout') # POST
add(r.UserResetPassword, '/auth/reset-password') # POST

# Business Routes
add(r.Business, '/businesses') # GET, POST
add(r.BusinessHandler, '/businesses/<int:businessId>') # GET, PUT, DEL

# Review Routes
add(r.Reviews, '/businesses/<int:businessId>/reviews') # GET, POST
Loading

0 comments on commit 2f98fa0

Please sign in to comment.