def get_products_by_version_id(version_id, is_indexed, offset=0, limit=5): start_time = time.time() orm = Products() res = GetProductsResponse() response_status = 200 try: response = orm.products.find({"version_id": version_id, "is_indexed": is_indexed})\ .skip(offset).limit(limit) res.message = 'Successful' products = [] for r in response: # log.debug(r) product = Product.from_dict(r) product.id = str(r['_id']) products.append(product) if len(products) == 0: res.message = 'No matched products' response_status = 404 res.data = None else: res.data = products except Exception as e: res.message = str(e) response_status = 400 # log.debug(res) elapsed_time = time.time() - start_time log.debug('get_products_by_version_id time: ' + str(elapsed_time)) return res, response_status
def get_products_by_host_code(host_code, offset=0, limit=1000): start_time = time.time() orm = Products() res = GetProductsResponse() response_status = 200 try: response = orm.products.find({"host_code": host_code}).skip(offset).limit(limit) res.message = 'Successful' products = [] for r in response: # log.debug(r) product = Product.from_dict(r) product.id = str(r['_id']) products.append(product) res.data = products except Exception as e: res.message = str(e) response_status = 400 # log.debug(res) elapsed_time = time.time() - start_time log.info('get_products_by_host_code time: ' + str(elapsed_time)) return res, response_status
def get_products_by_ids(product_ids): start_time = time.time() orm = Products() res = GetProductsResponse() response_status = 200 try: ids = [] for id in product_ids: ids.append(ObjectId(id)) res_products = orm.products.find({"_id": {"$in": ids}}) products = [] for p in res_products: p['sub_images'] = None products.append(Product.from_dict(p)) res.message = 'Successful' res.data = products except Exception as e: res.message = str(e) response_status = 400 elapsed_time = time.time() - start_time log.debug('get_products_by_ids time: ' + str(elapsed_time)) return res, response_status
def put_product(product_id, body): # noqa: E501 """actuliza la información de un producto # noqa: E501 :param product_id: id del producto a actualizar :type product_id: int :param body: :type body: dict | bytes :rtype: None """ if connexion.request.is_json: body = Product.from_dict(connexion.request.get_json()) # noqa: E501 collection = db.product myquery = {"product_id": product_id} new_values = { "$set": { 'id': body.id, 'name': body.name, 'price': body.price } } collection.update_one(myquery, new_values) return 'OK!'
def test_add_product(self): """Test case for add_product Create a new Product """ body = Product() response = self.client.open('/motta/bampli/1.0.0-oas3/product/', method='POST', data=json.dumps(body), content_type='application/json') self.assert200(response, 'Response body is : ' + response.data.decode('utf-8'))
def add_product(body): # noqa: E501 """Create a new Product Adds a Product # noqa: E501 :param body: :type body: dict | bytes :rtype: Product """ if connexion.request.is_json: body = Product.from_dict(connexion.request.get_json()) # noqa: E501 return 'do some magic!'
def test_put_product(self): """Test case for put_product actuliza la información de un producto """ body = Product() response = self.client.open( '/omogollo2/ServerAPI/1.0.0/product/{productId}'.format(product_id=56), method='PUT', data=json.dumps(body), content_type='application/json') self.assert200(response, 'Response body is : ' + response.data.decode('utf-8'))
def test_update_product(self): """Test case for update_product Updates a product in the store with form data """ body = Product() response = self.client.open( '/v1/products/{productId}'.format(productId=789), method='POST', data=json.dumps(body), content_type='application/json') self.assert200(response, 'Response body is : ' + response.data.decode('utf-8'))
def test_add_product(self): """ Test case for add_product Added a new Product """ body = Product() response = self.client.open('//products', method='POST', data=json.dumps(body), content_type='application/json') self.assert200(response, "Response body is : " + response.data.decode('utf-8'))
def test_update_product(self): """Test case for update_product Update a Product """ body = Product() response = self.client.open( '/motta/bampli/1.0.0-oas3/product/{productid}'.format( productid='\"0e8c9fb0-ad98-11e6-bf2e-47644ada7c0f\"'), method='PUT', data=json.dumps(body), content_type='application/json') self.assert200(response, 'Response body is : ' + response.data.decode('utf-8'))
def test_update_product_by_id(self): """ Test case for update_product_by_id Update an existing Product """ body = Product() response = self.client.open( '//products/{productId}'.format(productId='productId_example'), method='PUT', data=json.dumps(body), content_type='application/json') self.assert200(response, "Response body is : " + response.data.decode('utf-8'))
def get_product(product_id): # noqa: E501 """devuelve la información de un producto # noqa: E501 :param product_id: id del producto a consultar :type product_id: int :rtype: Product """ collection = db.product product = collection.find_one({'id': product_id}) return Product(product['id'], product['name'], product['price'])
def remove_get(userId, productName, sku): """ Remove Item from a user's shopping cart :param userId: Customer userId :type userId: str :param productName: The name of the product :type productName: str :param sku: SKU of product to be removed :type sku: str :rtype: Product """ database.removeProductFromCart(userId, sku) return Product(productName, sku)
def test_update_product_by_hostcode_and_productno(self): """ Test case for update_product_by_hostcode_and_productno Update an existing Product """ body = Product() response = self.client.open( '//products/hosts/{hostCode}/products/{productNo}'.format( hostCode='hostCode_example', productNo='productNo_example'), method='PUT', data=json.dumps(body), content_type='application/json') self.assert200(response, "Response body is : " + response.data.decode('utf-8'))
def update_product(body, productid): # noqa: E501 """Update a Product Stores a Product # noqa: E501 :param body: :type body: dict | bytes :param productid: Identifier of the Product :type productid: str :rtype: Product """ if connexion.request.is_json: body = Product.from_dict(connexion.request.get_json()) # noqa: E501 return 'do some magic!'
def update_product(productId, body): # noqa: E501 """Updates a product in the store with form data # noqa: E501 :param productId: ID of productId to update :type productId: int :param body: Product object that needs to be added to the store :type body: dict | bytes :rtype: None """ if connexion.request.is_json: body = Product.from_dict(connexion.request.get_json()) # noqa: E501 return 'do some magic!'
def add_get(userId, productName, sku): """ Adds an item to a user's shopping cart :param userId: Customer userId :type userId: str :param productName: The name of the product :type productName: str :param sku: SKU of product to be added :type sku: str :rtype: Product """ database.addProductToCollection(sku, productName) database.addProductToCart(userId, sku) return Product(productName, sku)
def get_product_by_id(product_id): start_time = time.time() orm = Products() res = GetProductResponse() response_status = 200 try: r = orm.products.find_one({"_id": ObjectId(product_id)}) res.message = 'Successful' product = Product.from_dict(r) product.id = str(r['_id']) res.data = product.to_dict() except Exception as e: res.message = str(e) response_status = 400 elapsed_time = time.time() - start_time log.debug('get_product_by_id time: ' + str(elapsed_time)) return res, response_status
def get_product_by_host_code_and_product_no(host_code, product_no): start_time = time.time() orm = Products() res = GetProductResponse() response_status = 200 try: r = orm.products.find_one({"host_code": host_code, "product_no": product_no}) res.message = 'Successful' product = Product.from_dict(r) product.id = str(r['_id']) res.data = product.to_dict() except Exception as e: res.message = str(e) response_status = 400 elapsed_time = time.time() - start_time log.debug('get_product_by_host_code_and_product_no time: ' + str(elapsed_time)) return res, response_status