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 get single sale #4

Merged
merged 28 commits into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
adfde33
Create users and products table
oma0256 Oct 28, 2018
ca9177a
Setup database connection
oma0256 Oct 28, 2018
45472af
Create an admin
oma0256 Oct 28, 2018
df3b790
Setup jwt [Delivers #161530702]
oma0256 Oct 28, 2018
d432e0a
Allow user to login
oma0256 Oct 28, 2018
38fa8ca
Setup test db
oma0256 Oct 28, 2018
a58d5e4
Add attendant with valid data
oma0256 Oct 28, 2018
00372eb
Add attendant after all checks
oma0256 Oct 28, 2018
35b1adc
Add missing attendant sigin test
oma0256 Oct 28, 2018
d0d3fe5
Restructure create product test to fit database operations
oma0256 Oct 28, 2018
fe2bbfd
Restructure ProductView post method to handle database
oma0256 Oct 28, 2018
adba514
Add function to retrieve all products from database [Delievers #16153…
oma0256 Oct 28, 2018
ab4f680
Add function to retrieve a single product
oma0256 Oct 28, 2018
ba3e80e
Add funtion to modify product in database
oma0256 Oct 28, 2018
4ed538c
Prevent store attendant from modifying a product
oma0256 Oct 28, 2018
0ef4364
Allow modifying only existing products
oma0256 Oct 28, 2018
2da08c7
Prevent modifying a product with invalid data [Delivers #161527806]
oma0256 Oct 28, 2018
48e00b6
Add method to delete product from database
oma0256 Oct 28, 2018
a10ba22
Prevent store attendant from deleting a product
oma0256 Oct 28, 2018
13f182f
Prevent deleting non-existant product [Delivers #161527929]
oma0256 Oct 28, 2018
02ab4d8
Update requirements.txt
oma0256 Oct 29, 2018
cf55260
Add function to retrieve all sale records
oma0256 Oct 29, 2018
90b9543
Prevent store owner from making a sale
oma0256 Oct 29, 2018
01fbf64
Prevent making a sale with invalid data [Delivers #161565503]
oma0256 Oct 29, 2018
601c0a2
Allow store owners to get all products [Delivers #161559329]
oma0256 Oct 29, 2018
2b9aa08
Add endpoint to retrieve a single sale record
oma0256 Oct 29, 2018
3447373
Remove redundant code
oma0256 Oct 29, 2018
6200a24
Pause travis
oma0256 Oct 29, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Build Status](https://travis-ci.org/oma0256/store-manager-api.svg?branch=develop)](https://travis-ci.org/oma0256/store-manager-api)
<!-- [![Build Status](https://travis-ci.org/oma0256/store-manager-api.svg?branch=develop)](https://travis-ci.org/oma0256/store-manager-api)
[![Coverage Status](https://coveralls.io/repos/github/oma0256/store-manager-api/badge.svg?branch=develop)](https://coveralls.io/github/oma0256/store-manager-api)
[![Maintainability](https://api.codeclimate.com/v1/badges/3303ae1c369c0bd693df/maintainability)](https://codeclimate.com/github/oma0256/store-manager-api/maintainability)
[![Maintainability](https://api.codeclimate.com/v1/badges/3303ae1c369c0bd693df/maintainability)](https://codeclimate.com/github/oma0256/store-manager-api/maintainability) -->
# Store Manager Api
Store Manager is a web application that helps store owners manage sales and product inventory records. This application is meant for use in a single store.

Expand Down
12 changes: 5 additions & 7 deletions api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
Set up flask
"""

from flask import Flask, session
from flask import Flask
from flask_jwt_extended import JWTManager

app = Flask(__name__)
app.secret_key = 'super secret key'


@app.before_first_request
def clear_session():
"""
Clear session whenever server restarts
"""
session.clear()
# Setup flask-jwt-extended
app.config['JWT_SECRET_KEY'] = 'sajsvhca'
jwt = JWTManager(app)

from api import views
7 changes: 3 additions & 4 deletions api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ class Product:
def __init__(self, **kwargs):
self.id = kwargs.get("product_id")
self.name = kwargs.get("name")
self.price = kwargs.get("price")
self.unit_cost = kwargs.get("unit_cost")
self.quantity = kwargs.get("quantity")
self.category = kwargs.get("category")


class Sale:
"""
Define sale structure
"""
def __init__(self, sale_id, cart_items,
attendannt_email, total):
attendannt, total):
self.id = sale_id
self.cart_items = cart_items
self.attendant_email = attendannt_email
self.attendant = attendannt
self.total = total
76 changes: 0 additions & 76 deletions api/utils/auth_functions.py

This file was deleted.

48 changes: 0 additions & 48 deletions api/utils/decorators.py

This file was deleted.

13 changes: 0 additions & 13 deletions api/utils/generate_id.py

This file was deleted.

60 changes: 48 additions & 12 deletions api/utils/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@

from flask import jsonify
from validate_email import validate_email
from db import DB


def validate_register_data(first_name, last_name, email, password):
def validate_register_data(**kwargs):
"""
Function to validate registration data
"""
first_name = kwargs.get("first_name")
last_name = kwargs.get("last_name")
email = kwargs.get("email")
password = kwargs.get("password")
confirm_password = kwargs.get("confirm_password")
# Check for empty fields
if not first_name or not last_name or not email or not password:
if not first_name or not last_name or not email or not password or not confirm_password:
return jsonify({
"error": "First name, last name, email and password field is required"
"error": "First name, last name, email, password and confirm password fields are required"
}), 400
# Check if email is valid
is_valid = validate_email(email)
Expand All @@ -26,10 +32,10 @@ def validate_register_data(first_name, last_name, email, password):
return jsonify({
"error": "First and last name should only be alphabets"
}), 400
# Check if password has more than 5 characters
if len(password) < 5:
# Check if password and confirm password are equal
if password != confirm_password:
return jsonify({
"error": "Password should be more than 5 characters"
"error": "Passwords must match"
}), 400


Expand All @@ -45,20 +51,50 @@ def validate_login_data(email, password):
return None


def validate_product(name, price, quantity):
def validate_product(name, unit_cost, quantity):
"""
Funtion to validate product data
"""
# Check if fields are empty
if not name or not price or not quantity:
if not name or not unit_cost or not quantity:
return jsonify({
"error": "Product name, price and quantity is required"
"error": "Product name, unit_cost and quantity is required"
}), 400

# Check for valid price and quantity input
if not isinstance(price, int) or not isinstance(quantity, int):
# Check for valid unit_cost and quantity input
if not isinstance(unit_cost, int) or not isinstance(quantity, int):
return jsonify({
"error": "Product price and quantity must be integers"
"error": "Product unit_cost and quantity must be integers"
}), 400

return None

def validate_cart_item(product_id, quantity):
"""
Function to validate cart item
"""
db_conn = DB()
# Check if fields are empty
if not product_id or not quantity:
return jsonify({
"error": "Product id and quantity is required"
}), 400

# Check for valid product id and quantity
if type(product_id) is not int or type(quantity) is not int:
return jsonify({
"error": "Product id and quantity must be integers"
}), 400

# Check if product exists in database
product = db_conn.get_product_by_id(product_id)
if not product:
return jsonify({
"error": "This product doesn't exist"
}), 404

# Check if quantity is more than product quantity in database
if quantity > product["quantity"]:
return jsonify({
"error": "This product has only a quantity of " + str(product["quantity"])
}), 400
Loading