def patch(self, config_key): config = Configs.query.filter_by(key=config_key).first() data = request.get_json() if config: schema = ConfigSchema(instance=config, partial=True) response = schema.load(data) else: schema = ConfigSchema() data['key'] = config_key response = schema.load(data) db.session.add(response.data) if response.errors: return response.errors, 400 db.session.commit() response = schema.dump(response.data) db.session.close() clear_config() clear_standings() return { 'success': True, 'data': response.data }
def get(self): configs = Configs.query.all() schema = ConfigSchema(many=True) response = schema.dump(configs) if response.errors: return {"success": False, "errors": response.errors}, 400 return {"success": True, "data": response.data}
def get(self): configs = Configs.query.all() schema = ConfigSchema(many=True) response = schema.dump(configs) if response.errors: return { 'success': False, 'errors': response.errors, }, 400 return {'success': True, 'data': response.data}
def get(self, query_args): q = query_args.pop("q", None) field = str(query_args.pop("field", None)) filters = build_model_filters(model=Configs, query=q, field=field) configs = Configs.query.filter_by(**query_args).filter(*filters).all() schema = ConfigSchema(many=True) response = schema.dump(configs) if response.errors: return {"success": False, "errors": response.errors}, 400 return {"success": True, "data": response.data}
def post(self): req = request.get_json() schema = ConfigSchema() response = schema.load(req) if response.errors: return {"success": False, "errors": response.errors}, 400 db.session.add(response.data) db.session.commit() response = schema.dump(response.data) db.session.close() clear_config() clear_standings() return {"success": True, "data": response.data}
def post(self): req = request.get_json() schema = ConfigSchema() response = schema.load(req) if response.errors: # Inject config key into error config_key = response.data["key"] response.errors["value"][0] = f"{config_key} config is too long" return {"success": False, "errors": response.errors}, 400 db.session.add(response.data) db.session.commit() response = schema.dump(response.data) db.session.close() clear_config() clear_standings() return {"success": True, "data": response.data}
def get(self, config_key): config = Configs.query.filter_by(key=config_key).first_or_404() schema = ConfigSchema() response = schema.dump(config) return {"success": True, "data": response.data}