Skip to content

Commit 2c7cc26

Browse files
committed
Merge branch 'main' into feat/collab-service/ai-chat
2 parents cc02356 + d8551f3 commit 2c7cc26

File tree

6 files changed

+45
-49
lines changed

6 files changed

+45
-49
lines changed

collab-service/app/controller/collab-controller.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
22
newRoom,
33
getRoomId,
4-
heartbeat,
54
getAllRooms,
5+
fetchRoomChatHistory,
66
getQuestionIdByRoomId,
77
} from "../model/repository.js";
88
import crypto from "crypto";
@@ -47,23 +47,6 @@ export async function getRoomByUser(req, res) {
4747
}
4848
}
4949

50-
// Update heartbeat for a room
51-
export async function updateHeartbeat(req, res) {
52-
const { roomId } = req.params;
53-
54-
if (!roomId) {
55-
return res.status(400).json({ error: "Room ID is required" });
56-
}
57-
58-
const updatedRoom = await heartbeat(roomId);
59-
60-
if (updatedRoom) {
61-
res.status(200).json(updatedRoom);
62-
} else {
63-
res.status(404).json({ error: `Room with ID ${roomId} not found` });
64-
}
65-
}
66-
6750
// Get all rooms
6851
export async function getAllRoomsController(req, res) {
6952
const rooms = await getAllRooms();
@@ -75,14 +58,29 @@ export async function getAllRoomsController(req, res) {
7558
}
7659
}
7760

61+
export async function getRoomChatHistory(req, res) {
62+
const { roomId } = req.params;
63+
64+
if (!roomId) {
65+
return res.status(400).json({ error: "Room ID is required" });
66+
}
67+
68+
const room = await fetchRoomChatHistory(roomId);
69+
70+
if (room) {
71+
res.status(200).json(room);
72+
} else {
73+
res.status(404).json({ error: `Room not found for ID: ${roomId}` });
74+
}
75+
}
76+
7877
// Get QuestionId from the room based on the roomId
7978
export async function getQuestionId(req, res) {
8079
const { roomId } = req.params;
8180

8281
if (!roomId) {
8382
return res.status(400).json({ error: "Room ID is required" });
8483
}
85-
8684
const questionId = await getQuestionIdByRoomId(roomId);
8785

8886
if (questionId) {

collab-service/app/model/repository.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,6 @@ export async function getRoomId(user) {
3535
}
3636
}
3737

38-
export async function heartbeat(roomId) {
39-
try {
40-
const room = await UsersSession.findOne({ roomId: roomId });
41-
room.lastUpdated = new Date();
42-
await room.save();
43-
return room;
44-
} catch (error) {
45-
console.error("Error updating room ${roomId}:", error);
46-
return null;
47-
}
48-
}
4938

5039
export async function getAllRooms() {
5140
try {
@@ -107,6 +96,15 @@ export async function addMessageToChat(roomId, userId, text) {
10796
}
10897
}
10998

99+
export async function fetchRoomChatHistory(roomId) {
100+
try {
101+
const room = await UsersSession.findOne({ roomId });
102+
return room.chatHistory;
103+
} catch (error) {
104+
console.error("Error finding room chat history:", error);
105+
}
106+
}
107+
110108
export async function getQuestionIdByRoomId(roomId) {
111109
try {
112110
const room = await UsersSession.findOne({ roomId });

collab-service/app/model/usersSession-model.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ const messageSchema = new Schema({
1515
type: String,
1616
required: true,
1717
},
18-
// timestamp: {
19-
// type: Date,
20-
// default: Date.now,
21-
// required: true
22-
// }
2318
});
2419

2520
const usersSessionSchema = new Schema({

collab-service/app/routes/collab-routes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import express from "express";
22
import {
33
createRoom,
44
getRoomByUser,
5-
updateHeartbeat,
65
getAllRoomsController,
6+
getRoomChatHistory,
77
getQuestionId
88
} from "../controller/collab-controller.js";
99

@@ -13,10 +13,10 @@ router.post("/create-room", createRoom);
1313

1414
router.get("/user/:user", getRoomByUser);
1515

16-
router.patch("/heartbeat/:roomId", updateHeartbeat);
17-
1816
router.get("/rooms", getAllRoomsController);
1917

18+
router.get("/chat-history/:roomId", getRoomChatHistory);
19+
2020
router.get("/rooms/:roomId/questionId", getQuestionId);
2121

2222
export default router;

frontend/components/collab/code-editor.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
SelectTrigger,
1010
SelectValue,
1111
} from "@/components/ui/select";
12+
import { Button } from "@/components/ui/button";
1213
import * as Y from "yjs";
1314
import { WebsocketProvider } from "y-websocket";
1415
import { MonacoBinding } from "y-monaco";
@@ -42,33 +43,28 @@ const languages: Record<string, LanguageEntry> = {
4243
export default function CodeEditor({ roomId }: { roomId: string }) {
4344
const monaco = useMonaco();
4445
const [language, setLanguage] = useState<string>("Javascript");
46+
const [theme, setTheme] = useState<string>("light");
4547
const ydoc = useMemo(() => new Y.Doc(), []);
4648
const [editor, setEditor] =
4749
useState<MonacoEditor.IStandaloneCodeEditor | null>(null);
4850
const [provider, setProvider] = useState<WebsocketProvider | null>(null);
4951
const languageMap = useMemo(() => ydoc.getMap("language"), [ydoc]);
5052

51-
// this effect manages the lifetime of the Yjs document and the provider
5253
useEffect(() => {
5354
const provider = new WebsocketProvider(
5455
"ws://localhost:3002/yjs",
5556
roomId,
5657
ydoc
5758
);
58-
console.log(provider);
5959
setProvider(provider);
6060
return () => {
6161
provider?.destroy();
6262
ydoc.destroy();
6363
};
6464
}, [ydoc, roomId]);
6565

66-
// this effect manages the lifetime of the editor binding
6766
useEffect(() => {
68-
if (provider == null || editor == null) {
69-
console.log(provider, editor);
70-
return;
71-
}
67+
if (provider == null || editor == null) return;
7268
const monacoBinding = new MonacoBinding(
7369
ydoc.getText(),
7470
editor.getModel()!,
@@ -80,9 +76,7 @@ export default function CodeEditor({ roomId }: { roomId: string }) {
8076
};
8177
}, [ydoc, provider, editor]);
8278

83-
// Sync language changes across clients
8479
useEffect(() => {
85-
// Update language when languageMap changes
8680
const handleLanguageChange = () => {
8781
const newLanguage = languageMap.get("selectedLanguage") as string;
8882
if (newLanguage && newLanguage !== language) {
@@ -96,7 +90,6 @@ export default function CodeEditor({ roomId }: { roomId: string }) {
9690
};
9791
}, [languageMap, language]);
9892

99-
// Apply language change in the editor model
10093
useEffect(() => {
10194
if (editor && monaco) {
10295
const model = editor.getModel();
@@ -106,6 +99,12 @@ export default function CodeEditor({ roomId }: { roomId: string }) {
10699
}
107100
}, [language, editor, monaco]);
108101

102+
useEffect(() => {
103+
if (monaco) {
104+
monaco.editor.setTheme(theme === "dark" ? "vs-dark" : "light");
105+
}
106+
}, [theme, monaco]);
107+
109108
return (
110109
<div className="w-3/5 p-4">
111110
<Card className="h-full flex flex-col">
@@ -126,6 +125,12 @@ export default function CodeEditor({ roomId }: { roomId: string }) {
126125
))}
127126
</SelectContent>
128127
</Select>
128+
<Button
129+
onClick={() => setTheme(theme === "light" ? "dark" : "light")}
130+
variant={theme === "light" ? "secondary" : "default"}
131+
>
132+
{theme === "light" ? "Light" : "Dark"} Mode
133+
</Button>
129134
</div>
130135
<div className="flex-1 h-7/5">
131136
<Editor
@@ -134,6 +139,7 @@ export default function CodeEditor({ roomId }: { roomId: string }) {
134139
onMount={(editor) => {
135140
setEditor(editor);
136141
}}
142+
theme={theme === "dark" ? "vs-dark" : "light"}
137143
/>
138144
</div>
139145
</CardContent>

matching-service/app/logic/matching.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ async def fetch_random_question(topic: str, difficulty: str) -> str:
135135
return question_data["id"]
136136

137137
async def create_room(user1: str, user2: str, question_id: str) -> str:
138-
logger.debug("Test!")
139138
async with httpx.AsyncClient() as client:
140139
response = await client.post(
141140
f"{COLLAB_SVC_URL}/collab/create-room",

0 commit comments

Comments
 (0)