From 2ac4eded7d2cc18b5ccfd4cd269801aa67b68879 Mon Sep 17 00:00:00 2001 From: Nick Stokoe Date: Thu, 24 Oct 2024 12:38:03 +0100 Subject: [PATCH 1/4] [common] rename getDataset as getDatasetLocations And adjust the endpoint from /dataset/:datasetId to /dataset/:datasetId/locations This seems to make more sense in the pattern of things than getLocations and /locations/:datasetId --- libs/common/src/api/contract.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/common/src/api/contract.ts b/libs/common/src/api/contract.ts index 3240ebb2..c54615a7 100644 --- a/libs/common/src/api/contract.ts +++ b/libs/common/src/api/contract.ts @@ -78,12 +78,12 @@ export const schemas = { }; export const contract = c.router({ - getDataset: { + getDatasetLocations: { method: "GET", - path: "/dataset/:datasetId", - summary: "obtains a dataset", + path: "/dataset/:datasetId/locations", + summary: "obtains a dataset's locations", description: - "Obtains a dataset by its ID, which by passing in the appropriate options, might be in different formats", + "Obtains all the locations for a dataset by the dataset ID, which by passing in the appropriate options, might be in different formats", pathParams: z.object({ datasetId: DatasetId.openapi({ // description: "uniquely specifies the dataset wanted", From 50b0974978078285b0b157bf8939b8891ad71e9a Mon Sep 17 00:00:00 2001 From: Nick Stokoe Date: Thu, 24 Oct 2024 12:39:45 +0100 Subject: [PATCH 2/4] [common] mykomap-openapi.json - regenerate --- libs/common/src/api/mykomap-openapi.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/common/src/api/mykomap-openapi.json b/libs/common/src/api/mykomap-openapi.json index 7bff9d9b..48eb24d9 100644 --- a/libs/common/src/api/mykomap-openapi.json +++ b/libs/common/src/api/mykomap-openapi.json @@ -1,10 +1,10 @@ { "openapi": "3.0.2", "paths": { - "/dataset/{datasetId}": { + "/dataset/{datasetId}/locations": { "get": { - "description": "Obtains a dataset by its ID, which by passing in the appropriate options, might be in different formats", - "summary": "obtains a dataset", + "description": "Obtains all the locations for a dataset by the dataset ID, which by passing in the appropriate options, might be in different formats", + "summary": "obtains a dataset's locations", "tags": [], "parameters": [ { @@ -17,7 +17,7 @@ } } ], - "operationId": "getDataset", + "operationId": "getDatasetLocations", "responses": { "200": { "description": "200", From 792bf861815d1a0a739b6fae8dd743461f64b493 Mon Sep 17 00:00:00 2001 From: Nick Stokoe Date: Thu, 24 Oct 2024 12:40:16 +0100 Subject: [PATCH 3/4] [back-end] rename getDataset as getDatasetLocations Tests pass --- apps/back-end/src/routes.ts | 6 +++--- apps/back-end/test/plugin.test.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/back-end/src/routes.ts b/apps/back-end/src/routes.ts index 40eaa87d..cafbb8a2 100644 --- a/apps/back-end/src/routes.ts +++ b/apps/back-end/src/routes.ts @@ -85,11 +85,11 @@ export function MykomapRouter( // Construct and return the implementation object return { - async getDataset({ params: { datasetId }, request, reply }) { + async getDatasetLocations({ params: { datasetId }, request, reply }) { // Validate the parameters some more if (!sendJson(request, reply, filePath("datasets", datasetId))) - throw new TsRestResponseError(contract.getDataset, { + throw new TsRestResponseError(contract.getDatasetLocations, { status: 404, body: { message: `unknown datasetId '${datasetId}'` }, }); @@ -141,7 +141,7 @@ export function MykomapRouter( // Validate the parameters some more if (!sendJson(request, reply, filePath("datasets", datasetId, "config"))) - throw new TsRestResponseError(contract.getDataset, { + throw new TsRestResponseError(contract.getConfig, { status: 404, body: { message: `unknown datasetId '${datasetId}'` }, }); diff --git a/apps/back-end/test/plugin.test.ts b/apps/back-end/test/plugin.test.ts index f43a3bae..851db9b9 100644 --- a/apps/back-end/test/plugin.test.ts +++ b/apps/back-end/test/plugin.test.ts @@ -17,7 +17,7 @@ const opts: MykomapRouterConfig = { // // Operation: dataset -// URL: /dataset/:datasetId +// URL: /dataset/:datasetId/locations // summary: obtains a dataset // req.params // type: object @@ -54,7 +54,7 @@ test("testing dataset", async (t) => { const res = await fastify.inject({ method: "GET", - url: "/dataset/test-A", + url: "/dataset/test-A/locations", payload: undefined, headers: undefined, }); From fd8d89dae22b63bc9dfbd9dc679bd381f07bb016 Mon Sep 17 00:00:00 2001 From: Nick Stokoe Date: Thu, 24 Oct 2024 12:40:34 +0100 Subject: [PATCH 4/4] [front-end] rename getDataset as getDatasetLocations --- apps/front-end/src/components/map/mapSlice.ts | 4 ++-- apps/front-end/src/services/index.ts | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/front-end/src/components/map/mapSlice.ts b/apps/front-end/src/components/map/mapSlice.ts index 83ece86f..c76bb3f4 100644 --- a/apps/front-end/src/components/map/mapSlice.ts +++ b/apps/front-end/src/components/map/mapSlice.ts @@ -1,6 +1,6 @@ import { createSelector } from "@reduxjs/toolkit"; import { createAppSlice } from "../../app/createAppSlice"; -import { getDataset } from "../../services"; +import { getDatasetLocations } from "../../services"; export interface MapSliceState { allLocations: number[][]; @@ -26,7 +26,7 @@ export const mapSlice = createAppSlice({ ); } - const response = await getDataset({ params: { datasetId } }); + const response = await getDatasetLocations({ params: { datasetId } }); if (response.status === 200) { const locations = response.body ?? []; diff --git a/apps/front-end/src/services/index.ts b/apps/front-end/src/services/index.ts index b8bff337..9b26ad79 100644 --- a/apps/front-end/src/services/index.ts +++ b/apps/front-end/src/services/index.ts @@ -6,4 +6,9 @@ const client = initClient(contract, { baseHeaders: {}, }); -export const { getDataset, searchDataset, getDatasetItem, getVersion } = client; +export const { + getDatasetLocations, + searchDataset, + getDatasetItem, + getVersion, +} = client;