Skip to content

Commit

Permalink
updated retrieve questions
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestjx committed Jul 24, 2024
1 parent ca05c2a commit 88170a2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
15 changes: 14 additions & 1 deletion app/(main)/questions/searchlist/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
Expand Down
17 changes: 17 additions & 0 deletions service/QuestionsService.tsx
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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())
Expand Down
5 changes: 5 additions & 0 deletions types/questions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,10 @@ declare namespace Questions {
name: string;
topicId: number;
}

interface RetrieveQuestionRequest {
pageNumber?: number;
pageSize?: number
}
}

0 comments on commit 88170a2

Please sign in to comment.