コード例 #1
0
ファイル: brand.py プロジェクト: nasdaqPaul/animalFood
 def patch(self, id):
     brand = Brand.query.get(id)
     if brand is None:
         return "Brand not found", 404
     else:
         try:
             data = request.get_json()
             schema = Schema.PATCH()
             new_brand = schema.load(data)
         except ValidationError as err:
             return err.messages, 404
         for key, value in new_brand.items():
             setattr(brand, key, value)
         try:
             db.session.add(brand)
             db.session.commit()
         except IntegrityError as err:
             db.session.rollback()
             return f"ID {new_brand['id']} already exists for another record", 400
         return "patched", 200
コード例 #2
0
ファイル: feed.py プロジェクト: nasdaqPaul/animalFood
    def patch(self, sku):
        feed = Feed.query.get(sku)
        if feed is None:
            return "Feed not found", 404
        else:
            try:
                data = request.get_json()
                schema = Schema.PATCH()
                new_feed = schema.load(data)
            except ValidationError as err:
                return err.messages, 400
            for key, value in new_feed.items():
                setattr(feed, key, value)
            try:
                db.session.add(feed)
                db.session.commit()
            except IntegrityError as err:
                db.session.rollback()
                return f"sku {new_feed['sku']} already exists.", 400

            return "patched", 200