ebanutsya

This commit is contained in:
2023-10-27 06:04:15 +03:00
parent 56792b892d
commit 1d2ee676ff
19 changed files with 196 additions and 13 deletions

View File

@@ -1 +1,3 @@
from routes.auth import auth_blueprint
from routes.orders import orders_blueprint
from routes.barcode import barcode_blueprint

View File

@@ -29,16 +29,9 @@ def login_endpoint():
login = data.get('login')
user = User.query.filter_by(login=login).first()
if not user:
return jsonify(ok=False), 401
return jsonify(ok=False, accessToken=''), 401
password = data.get('password')
if not check_password_hash(user.password_hash, password):
return jsonify(ok=False), 401
return jsonify(ok=False, accessToken=''), 401
access_token = create_access_token(identity=user.id)
return jsonify(access_token=access_token)
@auth_blueprint.get('/protected')
@jwt_required()
def protected_endpoint():
print(type(get_jwt_identity()))
return 'test'
return jsonify(ok=True, accessToken=access_token)

12
routes/barcode.py Normal file
View File

@@ -0,0 +1,12 @@
from flask import Blueprint, jsonify, request
from routes.utils import jwt_protect_blueprint
import sipro.api.barcode
barcode_blueprint = jwt_protect_blueprint(Blueprint('barcode', __name__))
@barcode_blueprint.get('/searchProducts')
def search_product():
args = request.args
barcode = args.get('barcode')
return sipro.api.barcode.get_products_by_barcode(barcode)

17
routes/orders.py Normal file
View File

@@ -0,0 +1,17 @@
from flask import Blueprint, jsonify, request
from routes.utils import jwt_protect_blueprint
import sipro.api.orders
orders_blueprint = jwt_protect_blueprint(Blueprint('orders', __name__))
@orders_blueprint.get('/<int:order_id>')
def get_order(order_id: int):
return jsonify(id=order_id)
@orders_blueprint.get('/getBySupplierProductId')
def get_orders_by_supplier_product_id():
args = request.args
supplier_product_id = args.get('supplierProductId')
return sipro.api.orders.get_orders_by_supplier_product_id(supplier_product_id)

12
routes/utils.py Normal file
View File

@@ -0,0 +1,12 @@
from functools import wraps
from flask import Blueprint
from flask_jwt_extended import verify_jwt_in_request
def jwt_protect_blueprint(blueprint) -> Blueprint:
@blueprint.before_request
def require_token():
verify_jwt_in_request()
return blueprint