Skip to content

Commit 14e8f49

Browse files
committed
Integrate question list endpoint
Signed-off-by: SeeuSim <[email protected]>
1 parent d110421 commit 14e8f49

File tree

4 files changed

+18
-23
lines changed

4 files changed

+18
-23
lines changed

backend/question/src/services/get/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ export const getQuestionsService = async (
3636
.from(questions)
3737
.where(and(...whereClause))
3838
.limit(recordsPerPage)
39-
.offset(offset);
39+
.offset(offset)
40+
.orderBy(questions.id);
4041

4142
const [results, totalCount] = await Promise.all([
4243
query,

frontend/src/components/providers/query-provider.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { FC, PropsWithChildren } from 'react';
22
import { QueryClientProvider } from '@tanstack/react-query';
33
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
4+
45
import { queryClient } from '@/lib/query-client';
56

6-
const IS_SHOW_DEVTOOLS = true;
7+
const IS_SHOW_DEVTOOLS = false;
78

89
export const QueryProvider: FC<PropsWithChildren> = ({ children }) => {
910
return (

frontend/src/routes/questions/table-columns.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ export const columns: ColumnDef<Question>[] = [
3939
filterFn: 'equals',
4040
},
4141
{
42-
accessorKey: 'topics',
42+
accessorKey: 'topic',
4343
header: 'Topics',
4444
cell: ({ row }) => {
45-
const topics: string[] = row.getValue('topics');
45+
const topics: string[] = row.getValue('topic');
4646
return (
4747
<div>
4848
{topics.map((topic) => (
Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { questionApiClient } from './api-clients';
2-
import { questions } from '@/assets/questions';
31
import type { IGetQuestionsResponse } from '@/types/question-types';
42

3+
import { questionApiClient } from './api-clients';
4+
55
const QUESTION_SERVICE_ROUTES = {
66
GET_QUESTIONS: '/questions',
77
GET_QUESTION_DETAILS: '/questions/<questionId>',
88
};
99

10-
// type QuestionDetails = (typeof questionDetails)[number];
1110
type IGetQuestionDetailsResponse = {
1211
question: {
1312
title: string;
@@ -18,30 +17,24 @@ type IGetQuestionDetailsResponse = {
1817
};
1918
};
2019

21-
type IQuestionDetails = Required<IGetQuestionDetailsResponse>['question'];
22-
2320
export const getQuestionDetails = (questionId: number): Promise<IGetQuestionDetailsResponse> => {
21+
// TODO: Add error handling and notifs
2422
return questionApiClient
2523
.get(QUESTION_SERVICE_ROUTES.GET_QUESTION_DETAILS.replace(/<questionId>/, String(questionId)))
2624
.then((v) => {
2725
return v.data as IGetQuestionDetailsResponse;
2826
});
29-
// // return questionApiClient.get
30-
// console.log(questionDetails.find(({ id }) => id === questionId));
31-
// return new Promise((resolve, _reject) => {
32-
// setTimeout(() => resolve(questionDetails.find(({ id }) => id === questionId)!), 1000);
33-
// });
3427
};
3528

3629
export const ROWS_PER_PAGE = 8;
37-
export async function fetchQuestions(pageParam: number = 0): Promise<IGetQuestionsResponse> {
38-
// return questionApiClient.get
39-
const start = pageParam * ROWS_PER_PAGE;
40-
const end = start + ROWS_PER_PAGE;
41-
await new Promise((r) => setTimeout(r, 10));
30+
export async function fetchQuestions(pageNum: number = 0): Promise<IGetQuestionsResponse> {
31+
const params = new URLSearchParams({
32+
pageNum: String(pageNum),
33+
recordsPerPage: String(ROWS_PER_PAGE),
34+
}).toString();
4235

43-
return {
44-
questions: questions.slice(start, end),
45-
totalQuestions: questions.length,
46-
};
36+
// TODO: Add error handling and notifs
37+
return questionApiClient
38+
.get(QUESTION_SERVICE_ROUTES.GET_QUESTIONS + `?${params}`)
39+
.then((res) => res.data as IGetQuestionsResponse);
4740
}

0 commit comments

Comments
 (0)