def on_put(self, req, resp, productId): try: productId = int(productId) product = bl.getProduct(productId) if product is None: return falcon.HTTP_404 doc = req.context['doc'] newProduct = Product.from_json(doc) if newProduct.productId is None: newProduct.productId = product.productId #If updated object has id which doesn't match old one, return http forbidden-status elif newProduct.productId != productId: return falcon.HTTP_403 #update product bl.setProduct(newProduct) resp.status = falcon.HTTP_200 #Status Ok except: #Return 500 - internal error resp.status = falcon.HTTP_500
def on_post(self, req, resp): try: doc = req.context['doc'] product = Product.from_json(doc) bl.setProduct(product) resp.status = falcon.HTTP_200 except: resp.status = falcon.HTTP_500