def get(self, type): """ --- summary: Get stored quick queries description: Returns all saved queries related with specified object type. tags: - query parameters: - in: path name: type schema: type: string enum: [file, config, blob, object] description: Type of objects view. responses: 200: description: List of saved queries attached to the type of objects view. content: application/json: schema: type: array items: QuickQueryResponseSchema """ quick_queries = (db.session.query(QuickQuery).filter( QuickQuery.type == type).filter( QuickQuery.user_id == g.auth_user.id).all()) schema = QuickQueryResponseSchema(many=True) return schema.dump(quick_queries)
def post(self, type): """ --- summary: Create a new query description: | Create a new saved quick query. Requires `personalize` capability. tags: - query requestBody: description: Basic information for saving query content: application/json: schema: QuickQuerySchemaBase responses: 200: description: List of saved queries attached to the type of objects view. content: application/json: schema: type: array items: QuickQueryResponseSchema 403: description: When user doesn't have `personalize` capability. 400: description: When query is invalid 503: description: | Request canceled due to database statement timeout. """ schema = QuickQuerySchemaBase() obj = loads_schema(request.get_data(as_text=True), schema) quick_query = QuickQuery( query=obj["query"], name=obj["name"], type=type, user_id=g.auth_user.id, ) db.session.add(quick_query) db.session.commit() logger.info("Query saved", extra={"query": quick_query.name}) db.session.refresh(quick_query) schema = QuickQueryResponseSchema() return schema.dump(quick_query)
def post(self, type): """ --- summary: Create a new query description: Create a new saved quick query. tags: - query requestBody: description: Basic information for saving query content: application/json: schema: QuickQuerySchemaBase responses: 200: description: List of saved queries attached to the type of objects view. content: application/json: schema: type: array items: QuickQueryResponseSchema 400: description: When query is invalid """ schema = QuickQuerySchemaBase() obj = loads_schema(request.get_data(as_text=True), schema) quick_query = QuickQuery( query=obj["query"], name=obj["name"], type=type, user_id=g.auth_user.id, ) db.session.add(quick_query) db.session.commit() logger.info('Query saved', extra={'query': quick_query.name}) db.session.refresh(quick_query) schema = QuickQueryResponseSchema() return schema.dump(quick_query)