diff --git a/collab-service/app/controller/collab-controller.js b/collab-service/app/controller/collab-controller.js
index 87f3f807b8..0d72e5bedf 100644
--- a/collab-service/app/controller/collab-controller.js
+++ b/collab-service/app/controller/collab-controller.js
@@ -4,6 +4,7 @@ import {
getAllRooms,
fetchRoomChatHistory,
getQuestionIdByRoomId,
+ getAllRoomsByUserId,
} from "../model/repository.js";
import crypto from "crypto";
@@ -12,11 +13,13 @@ export async function createRoom(req, res) {
const { user1, user2, question_id } = req.body;
if (!user1 || !user2 || !question_id) {
- return res.status(400).json({ error: "user1,user2 and question_id are required" });
+ return res
+ .status(400)
+ .json({ error: "user1,user2 and question_id are required" });
}
// Generate a unique room ID by hashing the two user IDs
- const timeSalt = new Date().toISOString().slice(0, 13);
+ const timeSalt = new Date().toISOString().slice(0, 19);
const roomId = crypto
.createHash("sha256")
.update(user1 + user2 + timeSalt)
@@ -58,6 +61,17 @@ export async function getAllRoomsController(req, res) {
}
}
+// Get all rooms by user
+export async function getAllRoomsByUser(req, res) {
+ const { user } = req.params;
+ const rooms = await getAllRoomsByUserId(user);
+
+ if (rooms) {
+ res.status(200).json(rooms);
+ } else {
+ res.status(500).json({ error: "Failed to retrieve rooms" });
+ }
+}
export async function getRoomChatHistory(req, res) {
const { roomId } = req.params;
@@ -86,6 +100,8 @@ export async function getQuestionId(req, res) {
if (questionId) {
res.status(200).json({ questionId });
} else {
- res.status(404).json({ error: `Question ID not found for room ID: ${roomId}` });
+ res
+ .status(404)
+ .json({ error: `Question ID not found for room ID: ${roomId}` });
}
-}
\ No newline at end of file
+}
diff --git a/collab-service/app/model/repository.js b/collab-service/app/model/repository.js
index 73073a855b..9c304a819a 100644
--- a/collab-service/app/model/repository.js
+++ b/collab-service/app/model/repository.js
@@ -7,9 +7,6 @@ export async function connectToMongo() {
export async function newRoom(user1, user2, roomId, questionId) {
try {
- // Remove any existing rooms where either user1 or user2 is a participant
- await UsersSession.deleteMany({ users: { $in: [user1, user2] } });
-
const newRoom = new UsersSession({
users: [user1, user2],
roomId: roomId,
@@ -35,7 +32,6 @@ export async function getRoomId(user) {
}
}
-
export async function getAllRooms() {
try {
const rooms = await UsersSession.find({});
@@ -46,6 +42,16 @@ export async function getAllRooms() {
}
}
+export async function getAllRoomsByUserId(user) {
+ try {
+ const rooms = await UsersSession.find({ users: user });
+ return rooms;
+ } catch (error) {
+ console.error("Error getting all rooms of user:", error);
+ return null;
+ }
+}
+
// Function to add a new message to chatHistory with transaction support
export async function addMessageToChat(roomId, userId, text) {
// Start a session for the transaction
@@ -113,4 +119,4 @@ export async function getQuestionIdByRoomId(roomId) {
console.error(`Error finding questionId for roomId ${roomId}:`, error);
return null;
}
-}
\ No newline at end of file
+}
diff --git a/collab-service/app/routes/collab-routes.js b/collab-service/app/routes/collab-routes.js
index 088321b041..08a324508f 100644
--- a/collab-service/app/routes/collab-routes.js
+++ b/collab-service/app/routes/collab-routes.js
@@ -3,8 +3,9 @@ import {
createRoom,
getRoomByUser,
getAllRoomsController,
+ getAllRoomsByUser,
getRoomChatHistory,
- getQuestionId
+ getQuestionId,
} from "../controller/collab-controller.js";
const router = express.Router();
@@ -15,6 +16,8 @@ router.get("/user/:user", getRoomByUser);
router.get("/rooms", getAllRoomsController);
+router.get("/rooms/:user", getAllRoomsByUser);
+
router.get("/chat-history/:roomId", getRoomChatHistory);
router.get("/rooms/:roomId/questionId", getQuestionId);
diff --git a/frontend/app/app/history/page.tsx b/frontend/app/app/history/page.tsx
new file mode 100644
index 0000000000..d1b0616f63
--- /dev/null
+++ b/frontend/app/app/history/page.tsx
@@ -0,0 +1,13 @@
+import AuthPageWrapper from "@/components/auth/auth-page-wrapper";
+import UserRooms from "@/components/collab/user-rooms";
+import { Suspense } from "react";
+
+export default function CollabPage() {
+ return (
+