Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ft models implemetation 161413448 #22

Merged
merged 67 commits into from
Dec 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
d65f18b
CI started
invalid-email-address Oct 17, 2018
b6ca0de
CI started
invalid-email-address Oct 17, 2018
38a8370
CI started
invalid-email-address Oct 17, 2018
59912b3
CI started
invalid-email-address Oct 17, 2018
2e9c99d
Coveralls
invalid-email-address Oct 17, 2018
9c11059
Coveralls
invalid-email-address Oct 17, 2018
80bd103
Merge branch 'store-manager-use-pager' into project-app
invalid-email-address Oct 18, 2018
a050155
sales resourcecreated
invalid-email-address Oct 19, 2018
417f580
specified outfut fields for elements
invalid-email-address Oct 19, 2018
30ecd09
all-sales resource made existent
invalid-email-address Oct 19, 2018
75f62c5
solved for datetime format
invalid-email-address Oct 19, 2018
64ec1c9
access to individual sale record added
invalid-email-address Oct 19, 2018
a57d1bf
parse and validate request data
invalid-email-address Oct 19, 2018
98032ff
option to create new sale resource
invalid-email-address Oct 19, 2018
c641fe5
edit sale resource made possible # looked for this bug for hou…
invalid-email-address Oct 19, 2018
b6cff4b
added delete-sale-resource
invalid-email-address Oct 19, 2018
a9f5f95
verification for users
invalid-email-address Oct 19, 2018
4986764
solved for verification types
invalid-email-address Oct 19, 2018
8c53738
access to individual product resource
invalid-email-address Oct 19, 2018
115ec18
authorized access to product resource
invalid-email-address Oct 19, 2018
bd48ac8
changed path to module
invalid-email-address Oct 19, 2018
5434c30
tests for product resource
invalid-email-address Oct 20, 2018
8a17a9e
tests for productsresource
invalid-email-address Oct 20, 2018
8f27ac2
changed before-build
invalid-email-address Oct 20, 2018
52287aa
changed before-build
invalid-email-address Oct 20, 2018
2e57e89
changed before-build
invalid-email-address Oct 20, 2018
c2b4185
changed before-build
invalid-email-address Oct 20, 2018
c6324f6
changed before-build
invalid-email-address Oct 20, 2018
a7eeb43
solve for build-status
invalid-email-address Oct 20, 2018
916b0ce
solve for build-status
invalid-email-address Oct 20, 2018
a4fa713
set up to Initialize app
invalid-email-address Oct 21, 2018
1bb8aef
initial deploy
invalid-email-address Oct 21, 2018
6f4d3a2
resolve for app initialzation
invalid-email-address Oct 21, 2018
2eed883
resolve for app initialzation
invalid-email-address Oct 21, 2018
da735f4
Coverage config
invalid-email-address Oct 21, 2018
2cf3d08
Coverage config
invalid-email-address Oct 21, 2018
72081f7
Coverage issue solved
invalid-email-address Oct 21, 2018
8da784d
Change config settings to try deploy
invalid-email-address Oct 21, 2018
531ddaa
Change config settings to try deploy
invalid-email-address Oct 21, 2018
b912fca
Traceback actual gunicorn error
invalid-email-address Oct 21, 2018
64540e1
checked for missing module error
invalid-email-address Oct 21, 2018
32f8f9d
checked missing config module
invalid-email-address Oct 21, 2018
a558945
add heroku flat style
invalid-email-address Oct 21, 2018
ab18b35
add heroku flat style
invalid-email-address Oct 21, 2018
3f5dcd8
add heroku flat style
invalid-email-address Oct 21, 2018
7e52fe8
feature [#161361755] Move all test to the root folder
invalid-email-address Oct 22, 2018
d5d2010
chore [#161395208] Rename tests to show resources tested
invalid-email-address Oct 22, 2018
4be09b5
feature [#161413576] create a model for the sales resource
invalid-email-address Oct 23, 2018
8137048
feature [#161413600] create a model for the product resource
invalid-email-address Oct 23, 2018
4d09ee7
feature [#161414536] create a VIEW for the product resource
invalid-email-address Oct 23, 2018
e43b99d
feature [#161414982] create a VIEW for the sales resource
invalid-email-address Oct 23, 2018
46f2f9e
feature [#161416118] configure app to run
invalid-email-address Oct 23, 2018
849194a
feature [#161416449] Solve for module importation errors
invalid-email-address Oct 23, 2018
1301773
bug [#161416449] Solve for module importation errors
invalid-email-address Oct 23, 2018
8dc9a79
bug [#161416449] Solve for module importation errors
invalid-email-address Oct 23, 2018
4ad3b17
bug [#161417681] Resolve badge conflicts between branches
invalid-email-address Oct 23, 2018
8862332
feature [#161415070] make availbale endpoints for an individual sale …
invalid-email-address Oct 23, 2018
b266470
feature [#161414822] make availbale endpoints for an individual produ…
invalid-email-address Oct 23, 2018
22ecaa8
feature [#161422102] Provide for a working heroku link
invalid-email-address Oct 23, 2018
5803e98
chore [#161437785] Give app instance access to configurations
invalid-email-address Oct 24, 2018
34606a7
chore [#161437785] Resolve for environment configuration
invalid-email-address Oct 24, 2018
a6b2dd4
chore [#161437962] tell importing files where to get the app instance
invalid-email-address Oct 24, 2018
4b1e1cd
bug [#161416449] Give correct paths for every imported module
invalid-email-address Oct 24, 2018
64fb290
chore [#161416449] Solve for the missing attribute in records elements
invalid-email-address Oct 24, 2018
986d458
chore [#161438886] Create a model for users data
invalid-email-address Oct 24, 2018
b1e3abf
feature [#161439619] allow for creation of new users
invalid-email-address Oct 24, 2018
2474423
feature [#161439619] allow for creation of new users
invalid-email-address Oct 24, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!coverage.py: This is a private format, don't read it directly!{"lines":{"/root/Documents/save_me/storeManager/app/__init__.py":[1],"/root/Documents/save_me/storeManager/app/app.py":[2,3,4,5,7,8,9,10,14,15,18,19,20,23,24,25,26,27,28,30,31,35,36,39,40,41,44,45,46,47,48,49,51,52,59,60,61,62,63,64,69,70,71,72,73,74,75,81,82,84,85,86,91,92,93,94,95,96,101,102,103,104,105,111,112,113,116,117,125,127,128,129,131,132,134,135,137,138,140,141,146,150,151,155,163,171,179,187,188,190,245,250,286,287,290,301,309,326,340,341,342,368,374,394,395,396,416,426,442,455,456,457,460,461,462,463,343,344,345,346,349,350,351,354,355,357,358,361,362,363,366,370,371,397,398,399,402,403,406,407,410,411,414,417,419,423,165,166,167,157,158,376,379,380,381,382,383,384,387,390,391,420,444,446,448,451,428,430,432,434,435,439,431,173,174,196,197,198,199,200,203,204,205,207,208,209,211,212,213,217,218,219,220,222,223,224,226,227,228,230,231,232,234,236,237,239,240,241,243,247,291,292,293,294,295,296,297,299,302,304,307,251,254,255,256,257,258,259,260,261,262,263,264,265,266,270,272,273,274,279,282,283,181,182,183,305,327,328,331,333,336,310,311,314,317,320,321,324,315],"/root/Documents/save_me/storeManager/app/api/app.py":[],"/root/Documents/save_me/storeManager/app/api/__init__.py":[]}}
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.DS_Store

__pycache__/
*.py[cod]
*$py.class

# virtualenv
.pyvirtual/
pyvirtual/
env/

14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: python
python:
- "3.6"
cache: pip

install:
- pip install -r requirements.txt

script:
- coverage run -m pytest
- py.test --cov=app

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:my_app --preload --workers 4
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# storeManager


[![Coverage Status](https://coveralls.io/repos/github/hogum/storeManager/badge.svg)](https://coveralls.io/github/hogum/storeManager)

[![Code Climate](https://codeclimate.com/github/codeclimate/codeclimate/badges/gpa.svg)](https://codeclimate.com/github/hogum/storeManager)

[![GitHub issues](https://img.shields.io/github/issues/hogum/storeManager.svg?style=for-the-badge)](https://github.com/hogum/storeManager/issues)

A web application to help store managers maintain their inventories and manage sale records.


Try on Heroku: https://store-man90.herokuapp.com/stman/api/v1.0/products


[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
1 change: 1 addition & 0 deletions app/.coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!coverage.py: This is a private format, don't read it directly!{"lines":{"/root/Documents/save_me/storeManager/app/api/app.py":[],"/root/Documents/save_me/storeManager/app/api/__init__.py":[]}}
Empty file added app/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions app/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .app import create_app

def app_instance(app_setting):
return create_app(app_setting)
29 changes: 29 additions & 0 deletions app/api/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from flask import Flask, Blueprint
from flask_restful import Api
from .views import product_views, sale_views, user_views
from app.instance.config import app_config

store_blueprint = Blueprint("store-man", __name__)


def create_app(config_setting):
my_app = Flask(__name__)
my_app.config.from_object(app_config[config_setting])
api = Api(store_blueprint)

api.add_resource(sale_views.SalesAPI,
'/stman/api/v1.0/sales', endpoint='sales')
api.add_resource(product_views.ProductsAPI,
'/stman/api/v1.0/products', endpoint='products')
api.add_resource(sale_views.SaleAPI,
'/stman/api/v1.0/sales/<int:sales_record>',
endpoint='sale')
api.add_resource(product_views.ProductAPI,
'/stman/api/v1.0/products/<int:id>',
endpoint='product')
api.add_resource(user_views.UsersAPI,
'/stman/api/v1.0/users/',
endpoint='users')

my_app.register_blueprint(store_blueprint)
return my_app
Empty file added app/api/models/__init__.py
Empty file.
22 changes: 22 additions & 0 deletions app/api/models/products.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from datetime import datetime


products = []

product_record_example = {
'title': 'Innocent Coconut Water',
'category': 'Women sure can Sleep',
'price': 94534,
'in stock': True,
'date received': datetime(
2018, 5, 30, 22, 12, 38, 649),
'id': 2
}


class Products(object):
@staticmethod
def productsList():
products.append(product_record_example)

return products
34 changes: 34 additions & 0 deletions app/api/models/sales.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from datetime import datetime

sales = []

# example of a sale record

sale_example = {
'sales_record': 1,
'attendant': u'Attendant One',

# Customer contacts
'name': u'Customer One',
'address': u'45 bright street',
'contact': [u'+00012345', u'customer_c@example.co'],

# Transaction Info
'product': u'Spam 2.0',
'quantity': 1,
'date': datetime(2018, 6, 6, 5, 28, 56, 243),
'description': u'Hot with extra extra spam',
'transaction_type': u'Cash on Delivery',
'complete': False,

'gifts': 100, # Anything to reduce sale e.g discounts
'price': 276,
}


class Sales():
@staticmethod
def salesList():
sales.append(sale_example)

return sales
27 changes: 27 additions & 0 deletions app/api/models/users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from werkzeug.security import generate_password_hash

users = []

cool_user_sample = {
'name': 'Evil Cow',
'username': 'e-cow',
'email': 'ecow@isus.mammals',
'password': generate_password_hash('wah!-things-we-do!'),
'user id': 1
}


class Users(object):
"""docstring for Users"""
def __init__(self, name, username, email, password):
super(Users, self).__init__()
self.name = name
self.username = username
self.email = email
self.password = password

@staticmethod
def usersList():
users.append(cool_user_sample)

return users
Empty file added app/api/views/__init__.py
Empty file.
131 changes: 131 additions & 0 deletions app/api/views/product_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
from flask_restful import Resource, reqparse, marshal, fields
from app.api.models import products
from datetime import datetime
from flask import abort

products = products.Products.productsList()


class ProductsAPI(Resource):
def __init__(self):
self.parse = reqparse.RequestParser()
self.parse.add_argument('title', type=str, required=True,
help="Please add a title",
location='json'
)

self.parse.add_argument('category', type=str,
default='None',
location='json'
)

self.parse.add_argument('price', type=int,
required=True,
help="You are not \
allowed to give out stuff for free",
location='json'
)

self.parse.add_argument('in stock', type=bool,
default=True,
location='json'
)

super(ProductsAPI, self).__init__()

def get(self):
return {
'product': [marshal(product, product_fields)
for product in products]
}

def post(self):
elements = self.parse.parse_args()

product = {
'title': elements['title'],
'category': elements['category'],
'price': elements['price'],
'in stock': True,
'date received': datetime.now(),
'id': products[-1]['id'] + 1
}

products.append(product)

return {
'product': marshal(product, product_fields)
}, 201


class ProductAPI(Resource):
"""docstring for ProductAPI"""
def __init__(self):
self.parse = reqparse.RequestParser()
self.parse.add_argument('title', type=str,
location='json'
)

self.parse.add_argument('category', type=str,
location='json'
)

self.parse.add_argument('price', type=int,
location='json'
)

self.parse.add_argument('in stock', type=bool,
location='json'
)

super(ProductAPI, self).__init__()

def get(self, id):
product = [product for product in
products if product['id'] is id]

if not product:
abort(404)

return {
'product': marshal(product[0], product_fields)
}

def put(self, id):
product = [product for product in
products if product['id'] is id]

if not product:
abort(404)
elements = self.parse.parse_args()

for key, value in list(elements.items()):
if value:
product[0][key] = value

return {
'product': marshal(product, product_fields)
}

def delete(self, id):
product = [product for product
in products if product['id'] is id]

if not product:
abort(404)
products.remove(product[0])

return {
'Status': True
}


product_fields = {
'title': fields.String,
'category': fields.String,
'price': fields.Integer,
'in stock': fields.Boolean,
'date received': fields.DateTime,
'url': fields.Url('product') # Ensure user doen't
# need to know how to generate url
}