def delete(ad_id): ad = Ad.get(id=ad_id) if not ad: abort(404) ad.delete() db.commit() return '', 204
def show(ad_id): # This will serialize our data schema = AdSchema() # This gets a ad by ID ad = Ad.get(id=ad_id) # If we can't find a ad, send a 404 response if not ad: abort(404) # otherwise, send back the ad data as JSON return schema.dumps(ad)
def update(ad_id): schema = AdSchema() ad = Ad.get(id=ad_id) if not ad: abort(404) try: data = schema.load(request.get_json()) ad.set(**data) db.commit() except ValidationError as err: return jsonify({ 'message': 'Validation failed', 'errors': err.messages }), 422 return schema.dumps(ad)