def delete(self, name):
        claims = get_jwt_claims()
        if not claims["isAdmin"]:
            return {"message": "you are not admin"}, 401

        product = Product.findByProductName(name)
        if product:
            product.delete()
            return {"message": "Product deleted."}, 200
        return {"message": "Product not found."}, 404
    def put(self, name):
        claims = get_jwt_claims()
        if not claims["isAdmin"]:
            return {"message": "you are not admin"}, 401

        props = ProductController.parser.parse_args()

        product = Product.findByProductName(name)

        if product:
            product.price = props["price"]
            product.image = props["image"]
            product.isInStock = props["isInStock"]
            product.description = props["description"]
        else:
            product = Product(name, **props)

        product.save()

        return product.json(), 200
    def post(self, name):
        claims = get_jwt_claims()
        if not claims["isAdmin"]:
            return {"message": "you are not admin"}, 401

        if Product.findByProductName(name):
            return {
                "message": "An product with same name already exists."
            }, 400

        props = ProductController.parser.parse_args()
        product = Product(name, **props)

        try:
            product.save()
        except:
            return {
                "message": "Something was wrong when creating the store."
            }, 500

        return product.json(), 201
 def get(self, name):
     product = Product.findByProductName(name)
     if product:
         return product.json(), 200
     return {"message": "Product not found."}, 404