From 6856c63835ab68f059b7bdc76857bdcdce63ee42 Mon Sep 17 00:00:00 2001 From: Alessandra Vertrees Date: Wed, 27 Nov 2024 08:52:00 -0500 Subject: [PATCH 1/3] first run of adding schemas for phase 3 endpoints --- app/api/collections/[uuid]/route.tsx | 8 ++ .../collections/[uuid]/structure/route.tsx | 8 ++ app/api/search/facets/route.tsx | 8 ++ app/api/search/route.tsx | 8 ++ .../schemas/collectionsLandingPageSchema.ts | 37 +++++++++ .../schemas/collectionsStructureSchema.ts | 14 ++++ app/src/data/schemas/searchFacetsSchema.ts | 14 ++++ app/src/data/schemas/searchSchema.ts | 77 +++++++++++++++++++ app/src/utils/api.ts | 23 ++++++ 9 files changed, 197 insertions(+) create mode 100644 app/api/collections/[uuid]/route.tsx create mode 100644 app/api/collections/[uuid]/structure/route.tsx create mode 100644 app/api/search/facets/route.tsx create mode 100644 app/api/search/route.tsx create mode 100644 app/src/data/schemas/collectionsLandingPageSchema.ts create mode 100644 app/src/data/schemas/collectionsStructureSchema.ts create mode 100644 app/src/data/schemas/searchFacetsSchema.ts create mode 100644 app/src/data/schemas/searchSchema.ts diff --git a/app/api/collections/[uuid]/route.tsx b/app/api/collections/[uuid]/route.tsx new file mode 100644 index 00000000..23dd69a9 --- /dev/null +++ b/app/api/collections/[uuid]/route.tsx @@ -0,0 +1,8 @@ +import { NextResponse } from "next/server"; +import collectionsLandingPageSchema from "../../../src/data/schemas/collectionsLandingPageSchema"; + +export const GET = async () => { + return NextResponse.json(collectionsLandingPageSchema, { status: 200 }); +}; + +// http://localhost:3000/api/collections/:uuid diff --git a/app/api/collections/[uuid]/structure/route.tsx b/app/api/collections/[uuid]/structure/route.tsx new file mode 100644 index 00000000..42b501cd --- /dev/null +++ b/app/api/collections/[uuid]/structure/route.tsx @@ -0,0 +1,8 @@ +import { NextResponse } from "next/server"; +import collectionsStructureSchema from "../../../../src/data/schemas/collectionsStructureSchema"; + +export const GET = async () => { + return NextResponse.json(collectionsStructureSchema, { status: 200 }); +}; + +// http://localhost:3000/api/collections/:uuid/structure diff --git a/app/api/search/facets/route.tsx b/app/api/search/facets/route.tsx new file mode 100644 index 00000000..5a9404dc --- /dev/null +++ b/app/api/search/facets/route.tsx @@ -0,0 +1,8 @@ +import { NextResponse } from "next/server"; +import searchFacetsSchema from "../../../src/data/schemas/searchFacetsSchema"; + +export const GET = async () => { + return NextResponse.json(searchFacetsSchema, { status: 200 }); +}; + +// http://localhost:3000/api/search/facets diff --git a/app/api/search/route.tsx b/app/api/search/route.tsx new file mode 100644 index 00000000..021cc973 --- /dev/null +++ b/app/api/search/route.tsx @@ -0,0 +1,8 @@ +import { NextResponse } from "next/server"; +import searchSchema from "../../src/data/schemas/searchSchema"; + +export const GET = async () => { + return NextResponse.json(searchSchema, { status: 200 }); +}; + +// http://localhost:3000/api/search diff --git a/app/src/data/schemas/collectionsLandingPageSchema.ts b/app/src/data/schemas/collectionsLandingPageSchema.ts new file mode 100644 index 00000000..63dcf001 --- /dev/null +++ b/app/src/data/schemas/collectionsLandingPageSchema.ts @@ -0,0 +1,37 @@ +const collectionsLandingPageSchema = { + response: { + headers: { + status: "200", + code: "200", + message: "some copy", + }, + numResults: "6", + page: "1", + perPage: "40", + items: [ + { + uuid: "string", + title: "string", + url: "string", + imageID: "string | null", + imageURL: "string", + }, + { + uuid: "string", + title: "string", + url: "string", + imageID: "string | null", + imageURL: "string", + }, + { + uuid: "string", + title: "string", + url: "string", + imageID: "string | null", + imageURL: "string", + }, + ], + }, +}; + +export default collectionsLandingPageSchema; diff --git a/app/src/data/schemas/collectionsStructureSchema.ts b/app/src/data/schemas/collectionsStructureSchema.ts new file mode 100644 index 00000000..f7c98ba6 --- /dev/null +++ b/app/src/data/schemas/collectionsStructureSchema.ts @@ -0,0 +1,14 @@ +const collectionsStructureSchema = { + response: { + headers: { + status: "200", + code: "200", + message: "some copy", + }, + numResults: "6", + page: "1", + perPage: "40", + }, +}; + +export default collectionsStructureSchema; diff --git a/app/src/data/schemas/searchFacetsSchema.ts b/app/src/data/schemas/searchFacetsSchema.ts new file mode 100644 index 00000000..b878e0a7 --- /dev/null +++ b/app/src/data/schemas/searchFacetsSchema.ts @@ -0,0 +1,14 @@ +const searchFacetsSchema = { + response: { + headers: { + status: "200", + code: "200", + message: "some copy", + }, + numResults: "6", + page: "1", + perPage: "40", + }, +}; + +export default searchFacetsSchema; diff --git a/app/src/data/schemas/searchSchema.ts b/app/src/data/schemas/searchSchema.ts new file mode 100644 index 00000000..43baca3d --- /dev/null +++ b/app/src/data/schemas/searchSchema.ts @@ -0,0 +1,77 @@ +const searchSchema = { + // Sort fields + // Filter fields + // Keyword included in search + response: { + headers: { + status: "200", + code: "200", + message: "some copy", + }, + // Pagination fields + numResults: "6", + page: "1", + perPage: "40", + sort: "title DESC", + collections: [ + { + uuid: "string", + title: "string", + url: "string", + imageID: "string | null", + imageURL: "string", + numberOfDigitizedItems: "number", + containsOnSiteMaterials: "boolean", + containsAVMaterial: "boolean", + }, + { + uuid: "string", + title: "string", + url: "string", + imageID: "string | null", + imageURL: "string", + numberOfDigitizedItems: "number", + containsOnSiteMaterials: "boolean", + containsAVMaterial: "boolean", + }, + { + uuid: "string", + title: "string", + url: "string", + imageID: "string | null", + imageURL: "string", + numberOfDigitizedItems: "number", + containsOnSiteMaterials: "boolean", + containsAVMaterial: "boolean", + }, + ], + items: [ + { + uuid: "string", + title: "string", + url: "string", + imageID: "string | null", + imageURL: "string", + containsMultipleImages: "booleam", + }, + { + uuid: "string", + title: "string", + url: "string", + imageID: "string | null", + imageURL: "string", + containsMultipleImages: "booleam", + }, + { + uuid: "string", + title: "string", + url: "string", + imageID: "string | null", + imageURL: "string", + containsMultipleImages: "booleam", + }, + ], + }, +}; + +export default searchSchema; diff --git a/app/src/utils/api.ts b/app/src/utils/api.ts index 3d91eb7d..12b4e488 100644 --- a/app/src/utils/api.ts +++ b/app/src/utils/api.ts @@ -245,3 +245,26 @@ export const apiResponse = async ( throw new Error(error.message); } }; + +export const getCollectionsData = async ({ + keyword = "", + sortID = "chronological-descending", + pageNum = 1, + perPage = CARDS_PER_PAGE, +}: { + keyword?: string; + sortID?: string; + pageNum?: number; + perPage?: number; +} = {}) => { + let sortOptions = { + date_desc: "date DESC", + date_asc: "date ASC", + "title-desc": "title DESC", + "title-asc": "title ASC", + }; + + let apiUrl = `${process.env.API_URL}/api/v2/collections?page=${pageNum}&per_page=${perPage}&sort=${sortOptions[sortID]}&q=${keyword}`; + const res = await apiResponse(apiUrl); + return res; +}; From 3e58ea7159997d05e54b9997676dfdf9b0fc3c9b Mon Sep 17 00:00:00 2001 From: Alessandra Vertrees Date: Mon, 2 Dec 2024 14:25:18 -0500 Subject: [PATCH 2/3] fix typo --- app/src/data/schemas/searchSchema.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/data/schemas/searchSchema.ts b/app/src/data/schemas/searchSchema.ts index 43baca3d..14c2b581 100644 --- a/app/src/data/schemas/searchSchema.ts +++ b/app/src/data/schemas/searchSchema.ts @@ -52,7 +52,7 @@ const searchSchema = { url: "string", imageID: "string | null", imageURL: "string", - containsMultipleImages: "booleam", + containsMultipleImages: "boolean", }, { uuid: "string", @@ -60,7 +60,7 @@ const searchSchema = { url: "string", imageID: "string | null", imageURL: "string", - containsMultipleImages: "booleam", + containsMultipleImages: "boolean", }, { uuid: "string", @@ -68,7 +68,7 @@ const searchSchema = { url: "string", imageID: "string | null", imageURL: "string", - containsMultipleImages: "booleam", + containsMultipleImages: "boolean", }, ], }, From 503eddf04c70e26241f8c6d019f58171043161cc Mon Sep 17 00:00:00 2001 From: Alessandra Vertrees Date: Tue, 3 Dec 2024 13:58:01 -0500 Subject: [PATCH 3/3] fix broken method ref --- app/src/utils/apiHelpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/utils/apiHelpers.ts b/app/src/utils/apiHelpers.ts index ce4d1363..0a56c412 100644 --- a/app/src/utils/apiHelpers.ts +++ b/app/src/utils/apiHelpers.ts @@ -194,6 +194,6 @@ export const getCollectionsData = async ({ }; let apiUrl = `${process.env.API_URL}/api/v2/collections?page=${pageNum}&per_page=${perPage}&sort=${sortOptions[sortID]}&q=${keyword}`; - const res = await apiResponse(apiUrl); + const res = await fetchApi(apiUrl); return res; };