def custom_model_post(endpoint): model_db_cached = fetch_model(request.headers['X-Internal-AccessToken'], endpoint) instance = model_db_cached(**request.json) to_persist(instance) serializer_class = build_serializer(model_db_cached) serializer = serializer_class() save_all() return jsonify({'result': serializer.dump(instance).data})
def custom_model_delete(endpoint, model_id): model_db_cached = fetch_model(request.headers['X-Internal-AccessToken'], endpoint) instance = model_acessor.find(model_db_cached, model_id) if not instance: raise ApiException(code=404) model_acessor.remove(instance) save_all() return 'OK', 200
def custom_model_put(endpoint, model_id): model_db_cached = fetch_model(request.headers['X-Internal-AccessToken'], endpoint) instance = model_acessor.find(model_db_cached, model_id) if not instance: raise ApiException(code=404) for key, value in request.json.items(): setattr(instance, key, value) to_persist(instance) save_all() serializer_class = build_serializer(model_db_cached) serializer = serializer_class() return jsonify({'result': serializer.dump(instance).data})
def wrap(*args, **kwargs): result = f(*args, **kwargs) save_all() return result