swag-shop/app/api/routes/cart_routes.py

17 lines
483 B
Python
Raw Normal View History

2024-03-08 14:04:40 +01:00
from flask import jsonify, abort, request
from flask_jwt_extended import jwt_required, get_jwt_identity
from app.api import bp_cart
from app.services.cart_service import CartService
@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)
result, status_code = CartService.add_to_cart(user_id, product_id, count)
return result, status_code