def show(listing_id): schema = ListingSchema() listing = Listing.get(id=listing_id) if not listing: abort(404) return schema.dumps(listing)
def delete(listing_id): listing = Listing.get(id=listing_id) if not listing: abort(404) listing.delete() db.commit() return '', 204
def update(listing_id): schema = ListingSchema() listing = Listing.get(id=listing_id) if not listing: abort(404) try: data = schema.load(request.get_json()) listing.set(**data) db.commit() except ValidationError as err: return jsonify({'message': 'Validation failed', 'errors': err.messages}), 422 return schema.dumps(listing)
def load_item(self, data): data['item'] = Listing.get(id=data['item_id']) del data['item_id'] return data