Cart and purchase
This commit is contained in:
1 parent
ca8366d950
commit
e6ed37ad5e
2 files changed
+154
-14
No files matched your search
@@ -5,12 +5,55 @@ from app.api import bp_cart
|
||||
|
||||
from app.services.cart_service import CartService
|
||||
|
||||
@bp_cart.route('add/<int:product_id>', methods=['PUT'])
|
||||
@bp_cart.route('', methods=['GET'])
|
||||
@jwt_required()
|
||||
def show_cart():
|
||||
user_id = get_jwt_identity()
|
||||
|
||||
result, status_code = CartService.show_cart(user_id)
|
||||
|
||||
return result, status_code
|
||||
|
||||
@bp_cart.route('/add/<int:product_id>', methods=['PUT'])
|
||||
@jwt_required()
|
||||
def add_to_cart(product_id: int):
|
||||
user_id = get_jwt_identity()
|
||||
count = request.args.get('count', default=1, type=int)
|
||||
|
||||
if count < 1:
|
||||
return abort(400)
|
||||
|
||||
result, status_code = CartService.add_to_cart(user_id, product_id, count)
|
||||
|
||||
return result, status_code
|
||||
|
||||
@bp_cart.route('/remove/<int:product_id>', methods=['DELETE'])
|
||||
@jwt_required()
|
||||
def remove_from_cart(product_id: int):
|
||||
user_id = get_jwt_identity()
|
||||
|
||||
result, status_code = CartService.delete_from_cart(user_id, product_id)
|
||||
|
||||
return result, status_code
|
||||
|
||||
@bp_cart.route('/update/<int:product_id>', methods=['PUT'])
|
||||
@jwt_required()
|
||||
def update_count_in_cart(product_id: int):
|
||||
user_id = get_jwt_identity()
|
||||
count = request.args.get('count', type=int)
|
||||
|
||||
if not count:
|
||||
return abort(400)
|
||||
|
||||
result, status_code = CartService.update_count(user_id, product_id, count)
|
||||
|
||||
return result, status_code
|
||||
|
||||
@bp_cart.route('/purchase', methods=['GET'])
|
||||
@jwt_required()
|
||||
def purchase():
|
||||
user_id = get_jwt_identity()
|
||||
|
||||
result, status_code = CartService.purchase(user_id)
|
||||
|
||||
return result, status_code
|
||||
Reference in new issue
Block a user