Skip to content

Commit

Permalink
Query multiple task requests
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
  • Loading branch information
aaronchongth committed Nov 27, 2023
1 parent 1970313 commit 45e9421
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 1 deletion.
86 changes: 86 additions & 0 deletions packages/api-client/lib/openapi/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RequestArgs> => {
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
Expand Down Expand Up @@ -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<Array<TaskRequest>>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.queryTaskRequestsTasksRequestsGet(
taskIds,
options,
);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
*
* @summary Query Task States
Expand Down Expand Up @@ -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<Array<TaskRequest>> {
return localVarFp
.queryTaskRequestsTasksRequestsGet(taskIds, options)
.then((request) => request(axios, basePath));
},
/**
*
* @summary Query Task States
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/lib/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { version as rmfModelVer } from 'rmf-models';

export const version = {
rmfModels: rmfModelVer,
rmfServer: '3a67ed6377eef8d31c181986e67618fa7c5dec70',
rmfServer: '1970313b2544aa6fb1ee65c9356f2eface9b174b',
openapiGenerator: '6.2.1',
};
40 changes: 40 additions & 0 deletions packages/api-client/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
7 changes: 7 additions & 0 deletions packages/api-server/api_server/repositories/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 26 additions & 0 deletions packages/api-server/api_server/routes/tasks/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down

0 comments on commit 45e9421

Please sign in to comment.