Skip to content

Commit

Permalink
Merge pull request #102 from CS3219-AY2324S1/revert-100-feat/add-noti…
Browse files Browse the repository at this point in the history
…fication

Revert "Feat/add notification"
  • Loading branch information
Guo-KeCheng authored Nov 13, 2023
2 parents a038ab0 + a112401 commit 4cfc0c1
Show file tree
Hide file tree
Showing 45 changed files with 260 additions and 811 deletions.
5 changes: 0 additions & 5 deletions apps/backend/chat/src/controllers/messageController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,13 @@ class MessageController {

handleConnection(socket: Socket) {
socket.on("connectToChatroom", async ({ chatroomId }) => {
this.io.to(chatroomId).emit("other user connecting");
socket.join(chatroomId);
const messages = await this.chatroomService.getMessages(chatroomId);
console.log(messages);
socket.emit("receiveMessage", { messages });
socket.on("sendMessage", (message) =>
this.handleSendMessage(message, chatroomId)
);
socket.on("disconnect", () => {
console.log("starting to disconnect");
this.io.to(chatroomId).emit("other user disconnecting");
});
});
socket.emit("connected");
}
Expand Down
19 changes: 3 additions & 16 deletions apps/backend/question/src/controllers/api/questionRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,7 @@ questionRouter.put(
}
);

questionRouter.get(
"/random-question/:difficulty/:language",
async (req, res, next) => {
const difficulty = req.params.difficulty;
console.log(difficulty);
const languageId = req.params.language

const questions = await Question.aggregate([{
$match: {
complexity: difficulty,
'starterCode.languageId': Number(languageId),
}
},
{ $sample: { size: 1 } }]);
res.status(200).json({questions});
}
questionRouter.post(
"/:id/run",

)
19 changes: 2 additions & 17 deletions apps/backend/queue/src/queue/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,21 @@ import axios from "axios";
import { SESSION_URL } from "../utils/config";
import Producer from "../message-queue/Producer";
import Consumer from "../message-queue/Consumer";
import { ProgrammingLanguages } from "../enum/ProgrammingLanguages";
import { Difficulty } from "../enum/Difficulty";

export class Queue {
waitList: number[];
socketMap: Map<number, Socket>;
nameSpace: string;
producer: Producer;
consumer: Consumer;
diff: Difficulty;
language: ProgrammingLanguages;
next?: Queue;

constructor(
nameSpace: string,
diff: Difficulty,
language: ProgrammingLanguages,
nextQueue?: Queue
) {
constructor(nameSpace: string, nextQueue?: Queue) {
this.nameSpace = nameSpace;
this.waitList = [];
this.socketMap = new Map();
this.producer = new Producer(nameSpace);
this.consumer = new Consumer(nameSpace, (uid) => this.matchUsers(uid));
this.diff = diff;
this.language = language;
this.next = nextQueue;
}

Expand Down Expand Up @@ -129,11 +118,7 @@ export class Queue {

private async generateSession(user1: number, user2: number) {
const sessionID = await axios
.post(SESSION_URL, {
users: [user1, user2],
difficulty: this.diff,
language: this.language,
})
.post(SESSION_URL, { users: [user1, user2] })
.then((response) => {
return response.data.sessionId;
})
Expand Down
8 changes: 4 additions & 4 deletions apps/backend/queue/src/services/queueService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ class QueueService {

constructor() {
this.queues = new Map();
// this.queues.set(Difficulty.EASY, new Queue(Difficulty.EASY));
// this.queues.set(Difficulty.MEDIUM, new Queue(Difficulty.MEDIUM));
// this.queues.set(Difficulty.HARD, new Queue(Difficulty.HARD));
this.queues.set(Difficulty.EASY, new Queue(Difficulty.EASY));
this.queues.set(Difficulty.MEDIUM, new Queue(Difficulty.MEDIUM));
this.queues.set(Difficulty.HARD, new Queue(Difficulty.HARD));

for (const diff of Object.values(Difficulty)) {
for (const language of Object.values(ProgrammingLanguages)) {
const nameSpace = diff + "/" + language;
this.queues.set(nameSpace, new Queue(nameSpace, diff, language));
this.queues.set(nameSpace, new Queue(nameSpace, this.queues.get(diff)));
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions apps/backend/session/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ SESSION_PORT= # Port that session microservice is hosted on
WS_PORT= # Port that websocket microservice is hosted on
HOST= # Hostname of the server
MONGODB_URI= # MongoDB URI
QUESTION_URL= # Question microservice URL
USER_SERVICE_URL= # User microservice URL
28 changes: 1 addition & 27 deletions apps/backend/session/src/controllers/sessionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,7 @@ export class SessionController {
) {
logger.info(req.body);
const [user1, user2] = req.body.users;
const difficulty = req.body.difficulty;
const language = req.body.language;
const sessionId = await this.sessionManager.createNewSession(
user1,
user2,
difficulty,
language
);
const sessionId = await this.sessionManager.createNewSession(user1, user2);
console.log(`Created a sessionId: ${sessionId}`);
res.status(200).json({ sessionId: sessionId.toString() });
}
Expand Down Expand Up @@ -72,23 +65,4 @@ export class SessionController {
console.log("Saving to database");
await this.sessionManager.saveToDatabase();
}

public async handleGetSessionsForUser(
req: Request,
res: Response,
next: NextFunction
) {
console.log(req.params.user);
const uid = Number(req.params.user);
if (!uid) {
return res.status(500).json({ err: "UID passed in was not valid." });
}
const sessions = await this.sessionManager.getAllSessionsForUser(uid);
if (!sessions) {
return res.status(500).json({
err: "Something went wrong when searching for the sessions for this user.",
});
}
return res.status(200).json({ sessions });
}
}
5 changes: 0 additions & 5 deletions apps/backend/session/src/enums/Difficulty.ts

This file was deleted.

4 changes: 0 additions & 4 deletions apps/backend/session/src/enums/OAuthType.ts

This file was deleted.

7 changes: 0 additions & 7 deletions apps/backend/session/src/enums/ProgrammingLanguage.ts

This file was deleted.

4 changes: 0 additions & 4 deletions apps/backend/session/src/enums/Role.ts

This file was deleted.

66 changes: 0 additions & 66 deletions apps/backend/session/src/guards/jwtGuard.ts

This file was deleted.

70 changes: 0 additions & 70 deletions apps/backend/session/src/guards/sessionGuard.ts

This file was deleted.

21 changes: 0 additions & 21 deletions apps/backend/session/src/guards/userGuard.ts

This file was deleted.

16 changes: 3 additions & 13 deletions apps/backend/session/src/model/Session.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import mongoose, { Document, Schema } from "mongoose";

export interface SessionEntity extends Document {
interface Session extends Document {
users: number[];
chatroomId: string;
code: string;
question: string;
language: string;
}

const sessionSchema = new Schema({
Expand All @@ -23,20 +21,12 @@ const sessionSchema = new Schema({
code: {
type: String,
},
question: {
type: String,
required: true,
},
language: {
type: String,
required: true,
},
});

const SessionModel = mongoose.model<SessionEntity>(
const SessionModel = mongoose.model<Session>(
"Session",
sessionSchema,
"sessions"
);

export default SessionModel;
export default SessionModel;
Loading

0 comments on commit 4cfc0c1

Please sign in to comment.