Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
linxiaoxin committed Jul 24, 2024
2 parents 870c62c + 88170a2 commit 2a0855c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
25 changes: 19 additions & 6 deletions 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 All @@ -39,11 +52,11 @@ const QuestioSearchList = () => {
<div className='card mb-1'>
<div className="grid" key={rowData.id}>
<div className="col-12">{rowData.stem}</div>
<div className="col-12 md:col-6"><label>Topics:</label>{topics}</div>
<div className="col-12 md:col-6"><label>Skills:</label>{skills}</div>
<div className="col-12 md:col-3"><label>Status:</label>{rowData.status}</div>
<div className="col-12 md:col-3"><label>Publised on:</label>{formatDate(rowData.published_on)}</div>
<div className="col-12 md:col-6"><label>Publised by:</label>{rowData.published_by}</div>
<div className="col-12 md:col-6"><label>Topics: </label>{topics}</div>
<div className="col-12 md:col-6"><label>Skills: </label>{skills}</div>
<div className="col-12 md:col-3"><label>Status: </label>{rowData.status}</div>
<div className="col-12 md:col-3"><label>Published on: </label>{formatDate(rowData.publishedOn)}</div>
<div className="col-12 md:col-6"><label>Published by: </label>{rowData.publishedBy}</div>
<div className="col-12 md:col-10">&nbsp;</div>
<div className="col-12 md:col-2">
<span></span>
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
18 changes: 12 additions & 6 deletions types/questions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ declare namespace Questions {
topics: Topic[];
skills: Skills[];
status: string ;
published_on?: Date ;
published_by?: string ;
closed_on?: Date,
closed_by?: string,
created_on?: Date,
created_by?: string,
publishedOn?: Date ;
publishedBy?: string ;
closedOn?: Date,
closedBy?: string,
createdOn?: Date,
createdBy?: string,
}

interface Option{
Expand All @@ -35,6 +35,12 @@ declare namespace Questions {
name: string;
active: boolean;
topic_id: number;
topicId: number;
}

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

0 comments on commit 2a0855c

Please sign in to comment.