예제 #1
0
파일: server.py 프로젝트: ppv221/products
    def get(self):
        """ Returns all of the Products """
        app.logger.info('Request to list Products...')
        results = []
        category = request.args.get('category')
        #print (category)
        name = request.args.get('name')
        if category:
            # print("Category is " + category)
            results = Product.find_by_category(str(category).lower())
        elif name:
            results = Product.find_by_name(str(name).lower())
        else:
            results = Product.all()

            # for pro in results:
            #     print(pro.id)
        # app.logger.info('[%s] Products returned', len(results))
        # return make_response(jsonify([p.serialize() for p in results]),
        #                     HTTP_200_OK)
        resultsUpd = [prod.serialize() for prod in results]

        # for prod in resultsUpd:
        #     print(prod['id'])

        return resultsUpd, status.HTTP_200_OK
예제 #2
0
 def test_find_by_name(self):
     """ Find a Product by Name """
     Product(0, 'Asus2500', 'Laptop', '234', 'laptop', 'blue', 4).save()
     Product(0, 'GE4509', 'Microwave', '34324', 'microwave', 'black',
             4).save()
     products = Product.find_by_name("Asus2500")
     self.assertEqual(len(products), 1)
     self.assertEqual(products[0].category, "Laptop")
     self.assertEqual(products[0].name, "Asus2500")
예제 #3
0
def list_product():
    """ Retrieves a list of products from the database """
    results = []
    category = request.args.get('category')
    name = request.args.get('name')
    if category:
        results = Product.find_by_category(category)
    elif name:
        results = Product.find_by_name(name)
    else:
        results = Product.all()

    return jsonify([p.serialize() for p in results]), HTTP_200_OK
    def get(self):
        app.logger.info('Request to list Products...')
        category = request.args.get('category')
        name = request.args.get('name')
        if category:
            results = Product.find_by_category(str(category).lower())
        elif name:
            results = Product.find_by_name(str(name).lower())
        else:
            results = Product.all()

        resultsUpd = [prod.serialize() for prod in results]

        return resultsUpd, status.HTTP_200_OK