Skip to content

Commit

Permalink
Create release 1.2.0 (#252)
Browse files Browse the repository at this point in the history
Co-authored-by: Ong Jun Xiong <[email protected]>
Co-authored-by: chunweii <[email protected]>
  • Loading branch information
3 people authored Nov 13, 2023
1 parent 7d95ade commit 77b88b0
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ spec:
- name: PORT
value: "5005"
image: asia-southeast1-docker.pkg.dev/peerprep-group11-prod/codeparty-prod-images/admin-service:latest
imagePullPolicy: Always
name: admin-service
ports:
- containerPort: 5005
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ spec:
name: twilio-api-secret
key: twilio-api-secret
image: asia-southeast1-docker.pkg.dev/peerprep-group11-prod/codeparty-prod-images/collaboration-service:latest
imagePullPolicy: Always
name: collaboration-service
ports:
- containerPort: 5003
Expand Down
1 change: 1 addition & 0 deletions deployment/gke-prod-manifests/frontend-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ spec:
spec:
containers:
- image: asia-southeast1-docker.pkg.dev/peerprep-group11-prod/codeparty-prod-images/frontend:latest
imagePullPolicy: Always
name: frontend
ports:
- containerPort: 3000
Expand Down
1 change: 1 addition & 0 deletions deployment/gke-prod-manifests/gateway-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ spec:
- name: FRONTEND_ADDRESS
value: "https://www.codeparty.org"
image: asia-southeast1-docker.pkg.dev/peerprep-group11-prod/codeparty-prod-images/gateway:latest
imagePullPolicy: Always
name: gateway
ports:
- containerPort: 4000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ spec:
- name: PORT
value: "5002"
image: asia-southeast1-docker.pkg.dev/peerprep-group11-prod/codeparty-prod-images/matching-service:latest
imagePullPolicy: Always
name: matching-service
ports:
- containerPort: 5002
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ spec:
- name: PORT
value: "5004"
image: asia-southeast1-docker.pkg.dev/peerprep-group11-prod/codeparty-prod-images/question-service:latest
imagePullPolicy: Always
name: question-service
ports:
- containerPort: 5004
Expand Down
1 change: 1 addition & 0 deletions deployment/gke-prod-manifests/user-service-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ spec:
- name: PORT
value: "5001"
image: asia-southeast1-docker.pkg.dev/peerprep-group11-prod/codeparty-prod-images/user-service:latest
imagePullPolicy: Always
name: user-service
ports:
- containerPort: 5001
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/components/common/difficulty-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,16 @@ export default function DifficultySelector({
</div>
);
}

export const getDifficultyColor = (difficulty: Difficulty) => {
switch (difficulty) {
case "easy":
return "text-green-500";
case "medium":
return "text-orange-500";
case "hard":
return "text-red-500";
default:
return "text-gray-500";
}
};
14 changes: 1 addition & 13 deletions frontend/src/components/questions/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Badge } from "../ui/badge";
import { Button } from "../ui/button";
import { EditIcon, PlayIcon, ArrowUpDown } from "lucide-react";
import { Difficulty, Question } from "../../types/QuestionTypes";
import { getDifficultyColor } from "../common/difficulty-selector";

export const getColumnDefs: (isEditable: boolean) => ColumnDef<Question>[] = isEditable => [
{
Expand Down Expand Up @@ -84,16 +85,3 @@ export const getColumnDefs: (isEditable: boolean) => ColumnDef<Question>[] = isE
enableHiding: false,
},
];

const getDifficultyColor = (difficulty: Difficulty) => {
switch (difficulty) {
case "easy":
return "text-green-500";
case "medium":
return "text-orange-500";
case "hard":
return "text-red-500";
default:
return "text-gray-500";
}
};
2 changes: 1 addition & 1 deletion frontend/src/components/room/code-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export default function CodeEditor({
<Editor
key={frameWork}
height={height}
defaultLanguage={frameWork}
defaultLanguage={frameWork === "c++" ? "cpp" : frameWork}
defaultValue={defaultValue}
value={text}
theme={theme}
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/room/description.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Question } from "../../types/QuestionTypes";
import { Difficulty, Question } from "@/types/QuestionTypes";
import { Badge } from "../ui/badge";
import { Button } from "../ui/button";
import { Card } from "../ui/card";
import { TypographyH2, TypographySmall } from "../ui/typography";
import sanitizeHtml from "sanitize-html";
import Markdown from 'react-markdown'
import rehypeRaw from 'rehype-raw'
import { getDifficultyColor } from "../common/difficulty-selector";

type DescriptionProps = {
question: Question;
Expand Down Expand Up @@ -34,7 +35,7 @@ export default function Description({
<div className="flex items-center justify-center">
<TypographyH2 className="w-fit">{question.title}</TypographyH2>
<Badge variant="secondary" className="h-min">
<TypographySmall className="text-[#27CA40]">
<TypographySmall className={getDifficultyColor(question.difficulty as Difficulty)}>
{question.difficulty}
</TypographySmall>
</Badge>
Expand Down
6 changes: 2 additions & 4 deletions frontend/src/pages/room/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ import { TypographyBody } from "@/components/ui/typography";
import { useRouter } from "next/router";
import VideoRoom from "../../components/room/video-room";
import { Difficulty, Question } from "../../types/QuestionTypes";
import { Match } from "../../types/MatchTypes";
import { useQuestions } from "@/hooks/useQuestions";
import { useMatch } from "@/hooks/useMatch";
import { useContext, useEffect, useState } from "react";
import { MrMiyagi } from "@uiball/loaders";
import { useMatchmaking } from "@/hooks/useMatchmaking";
import Solution from "@/components/room/solution";
import { AuthContext } from "@/contexts/AuthContext";
import { toast } from "react-toastify";
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
import { AlertDialog, AlertDialogAction, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog";

export default function Room() {
const router = useRouter();
Expand Down Expand Up @@ -201,6 +198,7 @@ export default function Room() {
<div className="flex-1">
<CodeEditor
text={text}
language={match?.chosenProgrammingLanguage || "python"}
cursor={cursor}
onChange={setText}
onCursorChange={setCursor}
Expand Down
50 changes: 40 additions & 10 deletions services/matching-service/src/controllers/matchingController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Request, Response } from "express";
import e, { Request, Response } from "express";
import { Server, Socket } from "socket.io";
import { io } from "../app";
import prisma from "../prismaClient";
Expand Down Expand Up @@ -179,25 +179,55 @@ export function handleLooking(
};
}
}
);
).catch((err) => {
console.log(err);
socket.emit("error", "An error occurred in lookingForMatch.");
hasError = true;
return {newMatch: null, matchingUser: null};
});

if (hasError) {
return;
}

if (!foundMatch) {
console.log(`Queued user ${userId}.`);
return;
}

const qnId = await getRandomQuestionOfDifficulty(
const {_id: qnId, defaultCode} = await getRandomQuestionOfDifficulty(
foundMatch.chosenDifficulty
);
foundMatch = await prisma.match.update({
where: {
roomId: foundMatch.roomId,
},
data: {
questionId: qnId,
},
[foundMatch, ] = await prisma.$transaction([
prisma.match.update({
where: {
roomId: foundMatch.roomId,
},
data: {
questionId: qnId,
},
}),
prisma.room.update({
where: {
room_id: foundMatch.roomId,
},
data: {
status: EnumRoomStatus.active,
text: defaultCode?.[foundMatch.chosenProgrammingLanguage] || "",
question_id: qnId,
},
}),
]).catch((err) => {
console.log(err);
socket.emit("error", "An error occurred in lookingForMatch.");
hasError = true;
return [null, null];
});

if (hasError || !foundMatch) {
return;
}

console.log(
`Match found for user ${userId} with user ${
foundMatch.userId1 === userId ? foundMatch.userId2 : foundMatch.userId1
Expand Down
11 changes: 4 additions & 7 deletions services/matching-service/src/questionAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ import http from "http";

export async function getRandomQuestionOfDifficulty(
difficulty: string
): Promise<string> {
const requestBody = JSON.stringify({ difficulty });
): Promise<any> {

const options = {
hostname: process.env.QUESTION_SERVICE_HOSTNAME || "localhost",
port: 5004, // Port of the question service
path: "/api/question-service/random-question",
method: "POST",
path: "/api/question-service/random-question?difficulty=" + difficulty,
method: "GET",
headers: {
"Content-Type": "application/json",
"Content-Length": Buffer.byteLength(requestBody),
},
};

Expand All @@ -29,7 +27,7 @@ export async function getRandomQuestionOfDifficulty(
const parsedData = JSON.parse(data);
const qnId = parsedData[0]._id;
if (qnId) {
resolve(qnId);
resolve(parsedData[0]);
} else {
reject(new Error("Invalid response format"));
}
Expand All @@ -43,7 +41,6 @@ export async function getRandomQuestionOfDifficulty(
reject(err);
});

req.write(requestBody);
req.end();
});
}

0 comments on commit 77b88b0

Please sign in to comment.