def post(self, code): if ProductModel.find_by_code(code): return { 'message': "A product with code '{}' already exists.".format(code) }, 400 data = Product.parser.parse_args() product = ProductModel(code, data["value"]) try: product.save_to_db() except: return {"message": "An error ocorrued inserting the item."}, 500 return product.json(), 201
def get(self, code): product = ProductModel.find_by_code(code) if product: return product.json(), 200 return {'message': 'Product not found'}, 404