From 45e94213f2e95793702d8a600acb3d26c4219b57 Mon Sep 17 00:00:00 2001 From: Aaron Chong Date: Mon, 27 Nov 2023 09:34:59 +0000 Subject: [PATCH] Query multiple task requests Signed-off-by: Aaron Chong --- packages/api-client/lib/openapi/api.ts | 86 +++++++++++++++++++ packages/api-client/lib/version.ts | 2 +- packages/api-client/schema/index.ts | 40 +++++++++ .../api_server/repositories/tasks.py | 7 ++ .../api_server/routes/tasks/tasks.py | 26 ++++++ 5 files changed, 160 insertions(+), 1 deletion(-) diff --git a/packages/api-client/lib/openapi/api.ts b/packages/api-client/lib/openapi/api.ts index 508ee14bf..173fe08ed 100644 --- a/packages/api-client/lib/openapi/api.ts +++ b/packages/api-client/lib/openapi/api.ts @@ -9086,6 +9086,46 @@ export const TasksApiAxiosParamCreator = function (configuration?: Configuration options: localVarRequestOptions, }; }, + /** + * + * @summary Query Task Requests + * @param {string} [taskIds] comma separated list of task ids + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + queryTaskRequestsTasksRequestsGet: async ( + taskIds?: string, + options: AxiosRequestConfig = {}, + ): Promise => { + const localVarPath = `/tasks/requests`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options }; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + if (taskIds !== undefined) { + localVarQueryParameter['task_ids'] = taskIds; + } + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, /** * * @summary Query Task States @@ -9668,6 +9708,23 @@ export const TasksApiFp = function (configuration?: Configuration) { ); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, + /** + * + * @summary Query Task Requests + * @param {string} [taskIds] comma separated list of task ids + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async queryTaskRequestsTasksRequestsGet( + taskIds?: string, + options?: AxiosRequestConfig, + ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise>> { + const localVarAxiosArgs = await localVarAxiosParamCreator.queryTaskRequestsTasksRequestsGet( + taskIds, + options, + ); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, /** * * @summary Query Task States @@ -10088,6 +10145,21 @@ export const TasksApiFactory = function ( .postUndoSkipPhaseTasksUndoSkipPhasePost(undoPhaseSkipRequest, options) .then((request) => request(axios, basePath)); }, + /** + * + * @summary Query Task Requests + * @param {string} [taskIds] comma separated list of task ids + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + queryTaskRequestsTasksRequestsGet( + taskIds?: string, + options?: any, + ): AxiosPromise> { + return localVarFp + .queryTaskRequestsTasksRequestsGet(taskIds, options) + .then((request) => request(axios, basePath)); + }, /** * * @summary Query Task States @@ -10534,6 +10606,20 @@ export class TasksApi extends BaseAPI { .then((request) => request(this.axios, this.basePath)); } + /** + * + * @summary Query Task Requests + * @param {string} [taskIds] comma separated list of task ids + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof TasksApi + */ + public queryTaskRequestsTasksRequestsGet(taskIds?: string, options?: AxiosRequestConfig) { + return TasksApiFp(this.configuration) + .queryTaskRequestsTasksRequestsGet(taskIds, options) + .then((request) => request(this.axios, this.basePath)); + } + /** * * @summary Query Task States diff --git a/packages/api-client/lib/version.ts b/packages/api-client/lib/version.ts index aad4b50fc..f1990d980 100644 --- a/packages/api-client/lib/version.ts +++ b/packages/api-client/lib/version.ts @@ -3,6 +3,6 @@ import { version as rmfModelVer } from 'rmf-models'; export const version = { rmfModels: rmfModelVer, - rmfServer: '3a67ed6377eef8d31c181986e67618fa7c5dec70', + rmfServer: '1970313b2544aa6fb1ee65c9356f2eface9b174b', openapiGenerator: '6.2.1', }; diff --git a/packages/api-client/schema/index.ts b/packages/api-client/schema/index.ts index 68e4a17f4..fddc56842 100644 --- a/packages/api-client/schema/index.ts +++ b/packages/api-client/schema/index.ts @@ -785,6 +785,46 @@ export default { }, }, }, + '/tasks/requests': { + get: { + tags: ['Tasks'], + summary: 'Query Task Requests', + operationId: 'query_task_requests_tasks_requests_get', + parameters: [ + { + description: 'comma separated list of task ids', + required: false, + schema: { + title: 'Task Ids', + type: 'string', + description: 'comma separated list of task ids', + }, + name: 'task_ids', + in: 'query', + }, + ], + responses: { + '200': { + description: 'Successful Response', + content: { + 'application/json': { + schema: { + title: 'Response Query Task Requests Tasks Requests Get', + type: 'array', + items: { $ref: '#/components/schemas/TaskRequest' }, + }, + }, + }, + }, + '422': { + description: 'Validation Error', + content: { + 'application/json': { schema: { $ref: '#/components/schemas/HTTPValidationError' } }, + }, + }, + }, + }, + }, '/tasks': { get: { tags: ['Tasks'], diff --git a/packages/api-server/api_server/repositories/tasks.py b/packages/api-server/api_server/repositories/tasks.py index 76fd37842..2c55f69fc 100644 --- a/packages/api-server/api_server/repositories/tasks.py +++ b/packages/api-server/api_server/repositories/tasks.py @@ -43,6 +43,13 @@ async def get_task_request(self, task_id: str) -> Optional[TaskRequest]: return None return TaskRequest(**result.request) + async def query_task_requests(self, task_ids: List[str]) -> List[DbTaskRequest]: + filters = {"id___in": task_ids} + try: + return await DbTaskRequest.filter(**filters) + except FieldError as e: + raise HTTPException(422, str(e)) from e + async def save_task_state(self, task_state: TaskState) -> None: db_task_state = await DbTaskState.get_or_none(id_=task_state.booking.id) if db_task_state is not None: diff --git a/packages/api-server/api_server/routes/tasks/tasks.py b/packages/api-server/api_server/routes/tasks/tasks.py index 74f132f6b..0314d4c71 100644 --- a/packages/api-server/api_server/routes/tasks/tasks.py +++ b/packages/api-server/api_server/routes/tasks/tasks.py @@ -13,6 +13,7 @@ start_time_between_query, ) from api_server.fast_io import FastIORouter, SubscriptionRequest +from api_server.models.tortoise_models import TaskRequest as DbTaskRequest from api_server.models.tortoise_models import TaskState as DbTaskState from api_server.repositories import TaskRepository, task_repo_dep from api_server.response import RawJSONResponse @@ -32,6 +33,31 @@ async def get_task_request( return result +@router.get("/requests", response_model=List[Optional[mdl.TaskRequest]]) +async def query_task_requests( + task_repo: TaskRepository = Depends(task_repo_dep), + task_ids: Optional[str] = Query( + None, description="comma separated list of task ids" + ), +): + task_id_splits = [] + if task_ids is not None: + task_id_splits = task_ids.split(",") + valid_task_requests = await task_repo.query_task_requests(task_id_splits) + + valid_task_request_map = {} + for valid_req in valid_task_requests: + valid_task_request_map[valid_req.id_] = mdl.TaskRequest(**valid_req.request) + + return_requests = [] + for id_query in task_id_splits: + if id_query in valid_task_request_map: + return_requests.append(valid_task_request_map[id_query]) + else: + return_requests.append(None) + return return_requests + + @router.get("", response_model=List[mdl.TaskState]) async def query_task_states( task_repo: TaskRepository = Depends(task_repo_dep),