예제 #1
0
    def put(self, id_product):
        product_data = Product.attribute.parse_args()
        products = ProductModel(**product_data)

        product = ProductModel.find_product(id_product)
        id_provider = ProductModel.find_id_provider(products.id_provider)

        if not id_provider:
            return {
                "message":
                "The id '{}' does not found.".format(products.id_provider)
            }, 404

        if not product:
            return {
                "message": "Product id '{}' does not found.".format(id_product)
            }, 404

        product_found = ProductModel.find_product(id_product)
        if product_found:
            product_found.update_product(**product_data)
            product_found.save_product()
            return product_found.json(), 200
        product = ProductModel(id_product, **product_data)

        try:
            product.save_product()
        except:
            return {'message': 'Internal error'}, 500
        return product.json(), 201
예제 #2
0
 def delete(self, id_product):
     product = ProductModel.find_product(id_product)
     if product:
         try:
             product.delete_product()
         except:
             return {'message': 'Internal error.'}, 500
         return {'message': 'Deleted product.'}, 201
     return {'message': 'Product not found.'}, 204
예제 #3
0
 def put(self, codigo):
     data = Product.attribute.parse_args()
     product_find = ProductModel.find_product(codigo)
     if product_find:
         product_find.update_product(**data)
         product_find.save_product()
         return product_find.json(), 200
     product = ProductModel(codigo, **data)
     product.save_product()
     return product.json(), 201
예제 #4
0
 def delete(self, codigo):
     product = ProductModel.find_product(codigo)
     if product:
         try:
             product.delete_product()
         except:
             return {
                 'message': 'An error ocurre try to delete product'
             }, 500
         return {'message': 'Product deleted.'}
     return {'message': 'Product not found.'}, 404
예제 #5
0
 def delete(self, productId):
     product = ProductModel.find_product(productId)
     if product:
         try:
             product.delete_product()
         except:
             return {
                 'message':
                 'An internal error occurred while trying to delete the data.'
             }, 500
         return {'message': 'Product deleted.'}, 200
     return {'message': 'Product not found.'}, 404
예제 #6
0
    def delete(self, product_id):
        product = ProductModel.find_product(product_id)

        if product:
            try:
                product.delete_product()
            except:
                return {
                    'message': 'Oops, we have some problem here, try again.'
                }, 500  # internal error

            return {'message': 'This product was deleted.'}
        return {'message': 'This product was not found'}, 404
예제 #7
0
    def post(self):
        priceArguments = reqparse.RequestParser()
        priceArguments.add_argument('priceProduct', type=str,
                                    required=True)  #help
        priceArguments.add_argument('priceAmount', type=int,
                                    required=True)  #help
        data = priceArguments.parse_args()

        if ProductModel.find_product(data['priceProduct']):
            priceQuery = ProductModel.find_product(data['priceProduct']).json()
            if data['priceAmount'] <= priceQuery['amount']:
                finalPrice = data['priceAmount'] * priceQuery['price']
                return {
                    'priceProduct': data['priceProduct'],
                    'priceAmount': data['priceAmount'],
                    'finalPrice': "%.2f" % finalPrice
                }
            return {
                "message":
                "Amount unavaliable. Only '{}' left in stock.".format(
                    priceQuery['amount'])
            }
        return {'message': 'Product not found.'}, 404
예제 #8
0
 def post(self, codigo):
     if ProductModel.find_product(codigo):
         return {
             "message": "Code '{}', product already exists.".format(codigo)
         }, 400  # Bad Request
     data = Product.attribute.parse_args()
     product = ProductModel(codigo, **data)
     try:
         product.save_product()
     except:
         return {
             "message": "An error ocurred trying to create product."
         }, 500  # Internal Server Error
     return product.json(), 201
예제 #9
0
 def put(self, product_id):
     args = Product.parser.parse_args()
     product_found = ProductModel.find_product(product_id)
     if product_found:
         product_found.update_product(**args)
         product_found.save_product()
         return product_found.json(), 200
     product = ProductModel(product_id, **args)
     try:
         product.save_product()
     except:
         return {
             'message': 'Oops, we have some problem here, try again.'
         }, 500  # internal error
     return product.json(), 201
예제 #10
0
    def put(self, productId):
        data = Product.arguments.parse_args()
        productFound = ProductModel.find_product(productId)

        if productFound:
            productFound.update_product(**data)
            try:
                productFound.save_product()
            except:
                return {
                    'message':
                    'An internal error occurred while trying to update the data.'
                }, 500
            return productFound.json(), 200
        return {'messsage': 'Product not found.'}, 404
예제 #11
0
    def post(self, product_id):
        if ProductModel.find_product(product_id):
            return {
                'message':
                'Product ID: {}, already exists.'.format(product_id.upper())
            }, 400  # bad request

        args = Product.parser.parse_args()
        new_product = ProductModel(product_id, **args)
        try:
            new_product.save_product()
        except:
            return {
                'message': 'Oops, we have some problem here, try again.'
            }, 500  # internal error
        return new_product.json()
예제 #12
0
    def post(self, productId):
        if ProductModel.find_product(productId):
            return {
                "message": "Product id '{}' already exists.".format(productId)
            }, 400

        data = Product.arguments.parse_args()
        productObject = ProductModel(productId, **data)
        try:
            productObject.save_product()
        except:
            return {
                'message':
                'An internal error occurred while trying to save the data.'
            }, 500
        return productObject.json()
예제 #13
0
    def post(self):
        arguments = reqparse.RequestParser()
        arguments.add_argument('orderProduct', type=str, required=True)
        arguments.add_argument('orderAmount', type=int, required=True)
        arguments.add_argument('orderPrice', type=float)
        arguments.add_argument('orderEmail', type=str, required=True)
        arguments.add_argument('orderPassword', type=str, required=True)
        data = arguments.parse_args()

        if UserModel.find_by_email(data['orderEmail']):
            passwordCheck = data['orderPassword']
            if passwordCheck == UserModel.check_password(data['orderEmail']):
                productQuery = ProductModel.find_product(
                    data['orderProduct']).json()
                if data['orderAmount'] <= productQuery['amount']:
                    order = OrderModel(**data)
                    order.orderPrice = data['orderAmount'] * productQuery[
                        'price']
                    order.save_order()
                    newAmount = productQuery['amount'] - data['orderAmount']
                    return productQuery
                return {'message': 'Sorry. The item is now out of stock.'}
            return {'message': 'Wrong password. Try again.'}
        return {'message': 'User not found.'}
예제 #14
0
 def get(self, id_product):
     product = ProductModel.find_product(id_product)
     if product:
         return product.json()
     return {'message': 'Product not found'}, 204
예제 #15
0
 def get(self, product_id):
     product = ProductModel.find_product(product_id)
     if product is not None:
         return product.json()
     return {'message': 'Product not found'}, 404  # not found
예제 #16
0
 def get(self, codigo):
     product = ProductModel.find_product(codigo)
     if product:
         return product.json()
     return {'message': 'Product not found'}, 404  # not found
예제 #17
0
 def get(self, productId):
     product = ProductModel.find_product(productId)
     if product:
         return product.json()
     return {'message': 'Product not found.'}, 404
예제 #18
0
 def get(self, sku):
     return ProductModel.find_product(sku)