Skip to content

Commit

Permalink
Reorder question endpoints and sessionId in session creation
Browse files Browse the repository at this point in the history
  • Loading branch information
sp4ce-cowboy committed Nov 3, 2024
1 parent c25d200 commit e1fdc9e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
17 changes: 9 additions & 8 deletions peerprep/backend/matching-service/src/utils/redisUtils3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,14 @@ const createSession = async (
): Promise<string> =>{
const sessionId = "lol";
try {
let sessionId = `${userId1}-${userId2}-${Date.now()}`;
let sessionId = `${userId1}-${userId2}-${Date.now()}-Q`;

/* RANDOM QUESTION STARTS HERE */
const randomQuestion = await getRandomQuestionFromQuestionService(topic, difficulty);
console.log("Random Question:", randomQuestion?.title);
sessionId += randomQuestion?.title
console.log("UPDATED Session ID:", sessionId);

const session: Session = {
sessionId: sessionId,
userId1,
Expand All @@ -315,12 +322,6 @@ const createSession = async (
timestamp: Date.now(),
};

/* RANDOM QUESTION STARTS HERE @MAHI
const randomQuestion = await getRandomQuestionFromQuestionService(topic, difficulty);
console.log("Random Question:", randomQuestion?.title);
sessionId = sessionId + "Q" + randomQuestion?.title
*/

await saveSession(session);
// return sessionId as string
// convert to string to match the return type
Expand All @@ -335,7 +336,7 @@ const createSession = async (
try {
//const response = await axios.get(`http://localhost:8080/api/questions/random-question`, {
const response = await axios.get(`http://question-service:8080/api/questions/random-question`, {
params: { topic: topic, difficulty: difficulty }
params: { topic, difficulty }
});
return response.data;
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { getQuestions, getQuestionById, createQuestion, updateQuestion, deleteQu
const router: Router = Router();

// Define routes for CRUD operations
router.get('/questions/random-question', getRandomQuestionEndpoint);
router.get('/questions', getQuestions);
router.get('/questions/:id', getQuestionById);
router.post('/questions', createQuestion);
router.put('/questions/:id', updateQuestion);
router.delete('/questions/:id', deleteQuestion);
router.get('/questions/random-question', getRandomQuestionEndpoint);


export default router;
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ const MatchingServiceMainView: React.FC = () => {

// Check if there is a part after the delimiter
if (parts.length > 1) {
return "Q" + parts[1]; // Return the part after "-Q"
return parts[1]; // Return the part after "-Q"
} else {
return "Empty Q"
}
return null;
};
Expand Down

0 comments on commit e1fdc9e

Please sign in to comment.