-
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 branch 'dev' into branch-rubesh-collabIntegration
- Loading branch information
Showing
5 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
peerprep/backend/question-service/src/controllers/databaseController.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,53 @@ | ||
import { Request, Response } from 'express'; | ||
import Topic from '../models/topicModel'; | ||
import Difficulty from '../models/difficultyModel'; | ||
|
||
// Get all topics | ||
export const getAllTopics = async (req: Request, res: Response): Promise<void> => { | ||
try { | ||
const topics = await Topic.find(); | ||
res.status(200).json(topics); | ||
} catch (error) { | ||
res.status(500).json({ message: 'Error fetching topics', error }); | ||
} | ||
}; | ||
|
||
// Check if a topic exists | ||
export const topicExists = async (req: Request, res: Response): Promise<void> => { | ||
try { | ||
const { topicName } = req.params; | ||
const topic = await Topic.findOne({ name: topicName }); | ||
if (topic) { | ||
res.status(200).json({ exists: true }); | ||
} else { | ||
res.status(404).json({ exists: false, message: 'Topic not found' }); | ||
} | ||
} catch (error) { | ||
res.status(500).json({ message: 'Error checking topic', error }); | ||
} | ||
}; | ||
|
||
// Get all difficulties | ||
export const getDifficulties = async (req: Request, res: Response): Promise<void> => { | ||
try { | ||
const difficulties = await Difficulty.find(); | ||
res.status(200).json(difficulties); | ||
} catch (error) { | ||
res.status(500).json({ message: 'Error fetching difficulties', error }); | ||
} | ||
}; | ||
|
||
// Check if a difficulty exists | ||
export const difficultyExists = async (req: Request, res: Response): Promise<void> => { | ||
try { | ||
const { difficultyName } = req.params; | ||
const topic = await Topic.findOne({ name: difficultyName }); | ||
if (topic) { | ||
res.status(200).json({ exists: true }); | ||
} else { | ||
res.status(404).json({ exists: false, message: 'Difficulty not found' }); | ||
} | ||
} catch (error) { | ||
res.status(500).json({ message: 'Error checking difficulty', error }); | ||
} | ||
}; |
11 changes: 11 additions & 0 deletions
11
peerprep/backend/question-service/src/models/difficultyModel.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,11 @@ | ||
import mongoose, { Schema, Document } from 'mongoose'; | ||
|
||
interface IDifficulty extends Document { | ||
difficulty: string; | ||
} | ||
|
||
const DifficultySchema: Schema = new Schema({ | ||
difficulty: { type: String, required: true, unique: true } | ||
}); | ||
|
||
export default mongoose.model<IDifficulty>('Difficulty', DifficultySchema); |
11 changes: 11 additions & 0 deletions
11
peerprep/backend/question-service/src/models/topicModel.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,11 @@ | ||
import mongoose, { Schema, Document } from 'mongoose'; | ||
|
||
interface ITopic extends Document { | ||
topic: string; | ||
} | ||
|
||
const TopicSchema: Schema = new Schema({ | ||
topic: { type: String, required: true, unique: true } | ||
}); | ||
|
||
export default mongoose.model<ITopic>('Topic', TopicSchema); |
12 changes: 12 additions & 0 deletions
12
peerprep/backend/question-service/src/routes/databaseRoutes.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,12 @@ | ||
import express from 'express'; | ||
import { getAllTopics, topicExists, getDifficulties } from '../controllers/databaseController'; | ||
|
||
const router = express.Router(); | ||
|
||
router.get('/topics', getAllTopics); | ||
router.get('/topics/exists/:topicName', topicExists); | ||
router.get('/difficulties', getDifficulties); | ||
router.get('/difficulties/exists/:difficultyName', topicExists); | ||
|
||
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