Skip to content

Commit d51a264

Browse files
Added temp code changes to branch
1 parent e92a723 commit d51a264

File tree

8 files changed

+60
-37
lines changed

8 files changed

+60
-37
lines changed

backend/question-service/src/dto/CreateQuestion.dto.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class CreateQuestionDto {
3939
message:
4040
'Category must be Algorithm, DynamicProgramming, Array, SQL, Heap, Recursion, Graph, Sorting',
4141
})
42-
categories: Category;
42+
categories: Category[];
4343

4444
@IsNotEmpty()
4545
@IsEnum(Difficulty, {
@@ -50,4 +50,4 @@ export class CreateQuestionDto {
5050
@IsNotEmpty()
5151
@IsString()
5252
link: string;
53-
}
53+
}

backend/question-service/src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { AppModule } from './app.module';
33

44
async function bootstrap() {
55
const app = await NestFactory.create(AppModule);
6+
app.enableShutdownHooks();
67
await app.listen(3002);
8+
console.log(app.getHttpAdapter().getInstance()._router.stack);
79
}
810
bootstrap();

backend/question-service/src/schemas/Question.schema.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import mongoose from 'mongoose';
44
@Schema()
55
export class Question {
66
@Prop({ unique: true })
7-
id: string;
7+
id: number;
88

99
@Prop({ unique: true, required: true })
1010
title: string;
@@ -13,10 +13,13 @@ export class Question {
1313
description: string;
1414

1515
@Prop({ required: true })
16-
category: string;
16+
categories: string;
1717

1818
@Prop({ required: true })
19-
difficulty: string;
19+
complexity: string;
20+
21+
@Prop({ required: true })
22+
link: string;
2023
}
2124

2225
export const QuestionSchema = SchemaFactory.createForClass(Question)

frontend/package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"react-dom": "^18.3.1",
2020
"react-router-dom": "^6.26.2",
2121
"react-scripts": "^5.0.1",
22+
"react-services": "^0.1.2",
2223
"typescript": "^4.9.5",
2324
"web-vitals": "^2.1.4"
2425
},

frontend/src/components/questiontable.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import axios from 'axios';
12
import React, { useState } from 'react';
23
import EditQuestionForm from './editquestionform';
34

45
export interface Question {
5-
id: number;
6+
id: string;
67
title: string;
78
description: string;
89
categories: string;
@@ -29,24 +30,35 @@ const QuestionTable: React.FC<QuestionTableProps> = ({ searchTerm, category, com
2930
return matchesSearchTerm && matchesCategory && matchesComplexity;
3031
});
3132

32-
const handleDelete = (id: number) => {
33+
const handleDelete = async(id: string) => {
34+
try {
35+
await axios.delete(`http://localhost:3000/questions/${id}`);
36+
setQuestions((prevQuestions) => prevQuestions.filter(question => question.id !== id));
37+
} catch (error) {
38+
alert('Error deleting question: ' + error);
39+
}
3340
setQuestions((prevQuestions) => prevQuestions.filter(question => question.id !== id));
3441
};
3542

36-
const handleUpdate = (updatedQuestion: Question) => {
37-
setQuestions((prevQuestions) =>
38-
prevQuestions.map(question => (question.id === updatedQuestion.id ? updatedQuestion : question))
39-
);
43+
const handleUpdate = async(updatedQuestion: Question) => {
44+
try {
45+
const response = await axios.patch(`http://localhost:3000/questions/${updatedQuestion.id}`, updatedQuestion);
46+
setQuestions((prevQuestions) =>
47+
prevQuestions.map(question => (question.id === updatedQuestion.id ? response.data : question))
48+
);
49+
} catch (error) {
50+
alert('Error updating question: ' + error);
51+
}
4052
};
4153

4254
const closeEditForm = () => {
4355
setEditingQuestion(null);
4456
};
4557

4658
return (
47-
<div>
59+
<div className="bg-gray-800 text-white">
4860
<table className="min-w-full table-auto">
49-
<thead>
61+
<thead className="bg-gray-700">
5062
<tr>
5163
<th className="border px-4 py-2">ID</th>
5264
<th className="border px-4 py-2">Title</th>
@@ -57,7 +69,7 @@ const QuestionTable: React.FC<QuestionTableProps> = ({ searchTerm, category, com
5769
<th className="border px-4 py-2">Actions</th>
5870
</tr>
5971
</thead>
60-
<tbody>
72+
<tbody className="bg-gray-800">
6173
{filteredQuestions.map((question) => (
6274
<tr key={question.id}>
6375
<td className="border px-4 py-2">{question.id}</td>

frontend/src/components/uploadquestion.tsx

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ interface UploadFileProps {
77
}
88

99
export interface JSONQuestion {
10+
id: string;
1011
title: string;
1112
description: string;
1213
categories: string;
@@ -15,38 +16,36 @@ export interface JSONQuestion {
1516
}
1617

1718
const UploadFile: React.FC<UploadFileProps> = ({ setQuestions }) => {
18-
const handleUpload = (event: React.ChangeEvent<HTMLInputElement>) => {
19+
const handleUpload = async (event: React.ChangeEvent<HTMLInputElement>) => {
1920
const file = event.target.files?.[0];
2021
if (file) {
2122
const reader = new FileReader();
22-
reader.onload = (e) => {
23+
reader.onload = async (e) => {
2324
const content = e.target?.result;
24-
console.log("content is ", content);
25+
console.log("Content is: ", content);
2526
if (typeof content === "string") {
2627
try {
27-
const jsonQuestions: JSONQuestion[] = JSON.parse(content)["questions"];
28-
console.log("json questions are ", jsonQuestions);
29-
for (let i = 0; i < jsonQuestions.length; i++) {
28+
const jsonQuestions: JSONQuestion[] = JSON.parse(content);
29+
console.log("JSON questions are: ", jsonQuestions);
30+
for (const question of jsonQuestions) {
31+
const questionData = {
32+
title: question.title,
33+
description: question.description,
34+
link: question.link,
35+
categories: question.categories,
36+
complexity: question.complexity,
37+
};
3038
try {
31-
const questionData = {
32-
"title": jsonQuestions[i]["title"],
33-
"description": jsonQuestions[i]["description"],
34-
"link": jsonQuestions[i]["link"],
35-
"category": jsonQuestions[i]["categories"],
36-
"difficulty": jsonQuestions[i]["categories"]
37-
}
38-
// const response = await axios.post('http://localhost:3000/questions', questionData);
39-
// console.log('Question created successfully:', response.data);
39+
const response = await axios.post('http://localhost:3000/questions', questionData);
40+
console.log('Question created successfully:' + response.data);
4041
} catch (error) {
41-
console.error('Error creating question:', error);
42+
console.log('Error creating question: ' + error);
4243
}
43-
4444
}
45-
46-
// setQuestions((prevQuestions) => [
47-
// ...prevQuestions,
48-
// ...jsonQuestions,
49-
// ]);
45+
setQuestions((prevQuestions) => [
46+
...prevQuestions,
47+
...jsonQuestions,
48+
]);
5049
} catch (error) {
5150
alert("Error parsing JSON: " + error);
5251
}

frontend/src/pages/questionservicepage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const QuestionServicePage: React.FC = () => {
2323
}
2424

2525
return (
26-
<div className="p-4">
26+
<div className="p-4 text-white">
2727
<h1 className="text-2xl font-bold text-left mb-6">Peer Prep</h1>
2828
<div className="flex justify-start items-center space-x-2 mb-4 text-sm">
2929
<SearchBar searchTerm={searchTerm} setSearchTerm={setSearchTerm} />

0 commit comments

Comments
 (0)