From 88170a28b61518a7832007c6f74626b91262716a Mon Sep 17 00:00:00 2001 From: ernestjx <73307945+ernestjx@users.noreply.github.com> Date: Wed, 24 Jul 2024 22:58:43 +0800 Subject: [PATCH] updated retrieve questions --- app/(main)/questions/searchlist/page.tsx | 15 ++++++++++++++- service/QuestionsService.tsx | 17 +++++++++++++++++ types/questions.d.ts | 5 +++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/app/(main)/questions/searchlist/page.tsx b/app/(main)/questions/searchlist/page.tsx index d7cdd72..f1e766e 100644 --- a/app/(main)/questions/searchlist/page.tsx +++ b/app/(main)/questions/searchlist/page.tsx @@ -13,13 +13,26 @@ const QuestioSearchList = () => { const [loading, setLoading] = useState(true); useEffect(() => { - QuestionsService.getMCQ().then((data) => { + const retrieveQuestionRequest: Questions.RetrieveQuestionRequest = { + "pageNumber": 0, + "pageSize": 10 + } + QuestionsService.retrieveMCQ(retrieveQuestionRequest).then((data) => { setMCQ(data); setLoading(false); }).catch(()=>{ setLoading(false); }); }, []); + + // useEffect(() => { + // QuestionsService.getMCQ().then((data) => { + // setMCQ(data); + // setLoading(false); + // }).catch(()=>{ + // setLoading(false); + // }); + // }, []); const formatDate = (value: Date | undefined) => { if(value == undefined) return ""; diff --git a/service/QuestionsService.tsx b/service/QuestionsService.tsx index 4ec6315..b2515f7 100644 --- a/service/QuestionsService.tsx +++ b/service/QuestionsService.tsx @@ -1,6 +1,7 @@ import { Questions } from '@/types'; const QuesionsSvcUrl = process.env.NEXT_PUBLIC_QUEMISTRY_QUESTIONS_URL || '' +const retrieveQuestionUrl = `${process.env.NEXT_PUBLIC_QUEMISTRY_GATEWAY_URL}/questions/retrieve` || '' export const QuestionsService = { getMCQ() { @@ -17,6 +18,22 @@ export const QuestionsService = { return data.mcqs as Questions.MCQ[]} ); }, + retrieveMCQ(data : Questions.RetrieveQuestionRequest) { + return fetch(retrieveQuestionUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + credentials: "include", + body: JSON.stringify(data) + }) + .then((res) => { + return res.json(); + }) + .then((data) => { + return data.mcqs as Questions.MCQ[]} + ); + }, getTopics() { return fetch('/demo/data/topics.json', { headers: { 'Cache-Control': 'no-cache' } }) .then((res) => res.json()) diff --git a/types/questions.d.ts b/types/questions.d.ts index 9dcd17c..7a620f4 100644 --- a/types/questions.d.ts +++ b/types/questions.d.ts @@ -33,5 +33,10 @@ declare namespace Questions { name: string; topicId: number; } + + interface RetrieveQuestionRequest { + pageNumber?: number; + pageSize?: number + } }