Skip to content

Commit dc4e03b

Browse files
committed
add changes
1 parent 17e7bb3 commit dc4e03b

File tree

5 files changed

+48
-18
lines changed

5 files changed

+48
-18
lines changed

backend/user-service/.env.sample

Lines changed: 0 additions & 3 deletions
This file was deleted.

backend/user-service/src/app.module.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import { UsersModule } from './users/users.module';
77
import { MongooseModule } from '@nestjs/mongoose';
88

99
@Module({
10-
imports: [AuthModule, ConfigModule.forRoot(),
11-
MongooseModule.forRoot('mongodb://127.0.0.1/cs3219-questionrepo'),
12-
UsersModule],
10+
imports: [
11+
AuthModule,
12+
ConfigModule.forRoot(),
13+
MongooseModule.forRoot('mongodb://127.0.0.1/PeerPrep'),
14+
UsersModule,
15+
],
1316
controllers: [AppController],
1417
providers: [AppService],
15-
1618
})
17-
export class AppModule { }
19+
export class AppModule {}

backend/user-service/src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { AppModule } from './app.module';
44
async function bootstrap() {
55
const app = await NestFactory.create(AppModule);
66
app.enableCors({
7-
origin: 'http://localhost:3000'
8-
})
7+
origin: 'http://localhost:3000',
8+
});
99
await app.listen(3001);
1010
}
11-
bootstrap();
11+
bootstrap();

frontend/src/components/questiontable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface Question {
88
categories: string;
99
complexity: string;
1010
link: string;
11-
}
11+
}
1212

1313
interface QuestionTableProps {
1414
searchTerm: string;

frontend/src/components/uploadquestion.tsx

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,54 @@
1-
import React from 'react';
2-
import { Question } from './questiontable';
1+
import React from "react";
2+
import { Question } from "./questiontable";
3+
import axios from 'axios';
34

45
interface UploadFileProps {
56
setQuestions: React.Dispatch<React.SetStateAction<Question[]>>;
67
}
78

9+
export interface JSONQuestion {
10+
title: string;
11+
description: string;
12+
categories: string;
13+
complexity: string;
14+
link: string;
15+
}
16+
817
const UploadFile: React.FC<UploadFileProps> = ({ setQuestions }) => {
918
const handleUpload = (event: React.ChangeEvent<HTMLInputElement>) => {
1019
const file = event.target.files?.[0];
1120
if (file) {
1221
const reader = new FileReader();
1322
reader.onload = (e) => {
1423
const content = e.target?.result;
15-
if (typeof content === 'string') {
24+
console.log("content is ", content);
25+
if (typeof content === "string") {
1626
try {
17-
const jsonQuestions: Question[] = JSON.parse(content);
18-
setQuestions((prevQuestions) => [...prevQuestions, ...jsonQuestions]);
27+
const jsonQuestions: JSONQuestion[] = JSON.parse(content)["questions"];
28+
console.log("json questions are ", jsonQuestions);
29+
for (let i = 0; i < jsonQuestions.length; i++) {
30+
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);
40+
} catch (error) {
41+
console.error('Error creating question:', error);
42+
}
43+
44+
}
45+
46+
// setQuestions((prevQuestions) => [
47+
// ...prevQuestions,
48+
// ...jsonQuestions,
49+
// ]);
1950
} catch (error) {
20-
alert('Error parsing JSON: ' + error);
51+
alert("Error parsing JSON: " + error);
2152
}
2253
}
2354
};

0 commit comments

Comments
 (0)