Skip to content

Commit 65d0459

Browse files
authored
Merge pull request #15 from CS3219-AY2425S1/filter-category
Filter category
2 parents 60301d6 + b18ccd4 commit 65d0459

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

apps/question-service/src/app/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export default function Home() {
129129
limit,
130130
sortBy,
131131
difficulty,
132+
categories,
132133
delayedSearch
133134
);
134135
setQuestions(data.questions);
@@ -141,7 +142,7 @@ export default function Home() {
141142

142143
useEffect(() => {
143144
loadQuestions();
144-
}, [limit, currentPage, sortBy, difficulty, delayedSearch]);
145+
}, [limit, currentPage, sortBy, difficulty, categories, delayedSearch]);
145146

146147
// Delay the fetching of data only after user stops typing for awhile
147148
useEffect(() => {

apps/question-service/src/app/services/question.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export const GetQuestions = async (
2626
currentPage?: number,
2727
limit?: number,
2828
sortBy?: string,
29-
difficulty?: string[],
29+
difficulties?: string[],
30+
categories?: string[],
3031
title?: string
3132
): Promise<QuestionListResponse> => {
3233
let query_url = `${process.env.NEXT_PUBLIC_API_URL}questions`;
@@ -47,20 +48,23 @@ export const GetQuestions = async (
4748
}sortField=${field}&sortValue=${order}`;
4849
}
4950

50-
if (difficulty && difficulty.length > 0) {
51-
const value = difficulty.join(","); // Change them from ["easy", "medium"] to "easy,medium"
51+
if (difficulties && difficulties.length > 0) {
52+
const value = difficulties.join(","); // Change them from ["easy", "medium"] to "easy,medium"
5253
query_params += `${query_params.length > 0 ? "&" : "?"}complexity=${value}`;
5354
}
5455

56+
if (categories && categories.length > 0) {
57+
const value = categories.join(",");
58+
query_params += `${query_params.length > 0 ? "&" : "?"}categories=${value}`;
59+
}
60+
5561
if (title && title != "") {
5662
const urlEncodedTitle = encodeURIComponent(title);
5763
query_params += `${
5864
query_params.length > 0 ? "&" : "?"
5965
}title=${urlEncodedTitle}`;
6066
}
6167

62-
// TODO: (Ryan) Filtering via categories
63-
6468
query_url += query_params;
6569
const response = await fetch(query_url);
6670
const data = await response.json();

apps/question-service/src/utils/SelectOptions.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
export const CategoriesOption = [
2-
{ label: "Array", value: "Array" },
3-
{ label: "String", value: "String" },
2+
{ label: "Arrays", value: "Arrays" },
3+
{ label: "Algorithms", value: "Algorithms" },
4+
{ label: "Data Structures", value: "Data Structures" },
5+
{ label: "Strings", value: "Strings" },
6+
{ label: "Recursion", value: "Recursion" },
47
{ label: "Hash Table", value: "Hash Table" },
58
{ label: "Dynamic Programming", value: "Dynamic Programming" },
69
{ label: "Math", value: "Math" },
710
{ label: "Sorting", value: "Sorting" },
811
{ label: "Greedy", value: "Greedy" },
912
{ label: "Depth-First Search", value: "Depth-First Search" },
10-
{ label: "Database", value: "Database" },
13+
{ label: "Databases", value: "Databases" },
1114
{ label: "Binary Search", value: "Binary Search" },
1215
{ label: "Matrix", value: "Matrix" },
1316
{ label: "Breadth-First Search", value: "Breadth-First Search" },

0 commit comments

Comments
 (0)