def json(self): product = Product.findById(self.productId) return { "productId": self.productId, "productName": product.productName, "image": product.image, "price": product.price, "quantity": self.quantity, "total": product.price * self.quantity, }
def delete(self, productId: int): if not Product.findById(productId): return {"message": "This product does not exist"}, 404, else: userId = get_jwt_identity() trolleyProduct = SessionTrolleyProduct(productId, 1, userId) try: trolleyProduct.deleteOne() except: return { "message": "Something was wrong when deleting the TrolleyProduct." }, 500, return {"message": "TrolleyProduct was deleted."}, 200
def post(self, productId: int): if not Product.findById(productId): return {"message": "This product does not exist"}, 404, userId = get_jwt_identity() trolleyProduct = SessionTrolleyProduct(productId, 1, userId) try: trolleyProduct.add() except: return { "message": "Something was wrong when creating the TrolleyProduct." }, 500, return { "message": "Added to your trolley .", "trolleyProduct": trolleyProduct.json() }, 201,