-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from CS3219-AY2425S1/testcase-title
Testcase addition to collabservice ui
- Loading branch information
Showing
7 changed files
with
212 additions
and
21 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
peerprep/backend/question-service/src/models/testcaseModel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import mongoose, { Document, Schema } from 'mongoose'; | ||
|
||
export interface ITestcase extends Document { | ||
questionId: number; | ||
title: string; | ||
input1: string; | ||
output1: string; | ||
input2: string; | ||
output2: string; | ||
} | ||
|
||
const TestcaseSchema: Schema = new Schema({ | ||
questionId: { type: Number, unique: true }, | ||
title: { type: String, unique: true }, | ||
input1: { type: String, required: true }, | ||
output1: { type: String, required: true }, | ||
input2: { type: String, required: true }, | ||
output2: { type: String, required: true }, | ||
}); | ||
|
||
export default mongoose.model<ITestcase>('Testcase', TestcaseSchema); |
20 changes: 20 additions & 0 deletions
20
peerprep/backend/question-service/src/routes/testcaseRoutes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import express, { Request, Response } from 'express'; | ||
import Testcase, { ITestcase } from '../models/testcaseModel'; | ||
|
||
const router = express.Router(); | ||
|
||
router.get('/testcases/:title', async (req: Request, res: Response) => { | ||
const { title } = req.params; | ||
try { | ||
const testcase: ITestcase | null = await Testcase.findOne({ title }); | ||
if (!testcase) { | ||
return res.status(404).json({ message: 'Testcases not found' }); | ||
} | ||
res.json(testcase); | ||
} catch (error) { | ||
console.error('Error fetching testcases:', error); | ||
res.status(500).json({ message: 'Server error' }); | ||
} | ||
}); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import axios from 'axios'; | ||
|
||
const API_URL = 'http://localhost:8080/api/testcases'; | ||
|
||
export interface Testcase { | ||
questionId: number; | ||
title: string; | ||
input1: string; | ||
output1: string; | ||
input2: string; | ||
output2: string; | ||
} | ||
|
||
export const getTestcasesByTitle = async (title: string): Promise<Testcase | null> => { | ||
try { | ||
const response = await axios.get<Testcase>(`${API_URL}/${title}`); | ||
console.log('Fetched testcases:', response.data); | ||
return response.data; | ||
} catch (error) { | ||
console.error('Error fetching testcases:', error); | ||
throw error; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters