Skip to content

Commit 7f3a449

Browse files
committed
Merge branch 'formatter' into post-ms6
2 parents 952fcdb + 6fcd886 commit 7f3a449

File tree

8 files changed

+71
-37
lines changed

8 files changed

+71
-37
lines changed

kubernetes/apply_k8s_configs.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Array of Kubernetes YAML files to apply
2+
$files = @(
3+
"backend-deployment.yaml",
4+
"backend-service.yaml",
5+
"collab-service-deployment.yaml",
6+
"collab-service-service.yaml",
7+
"matching-service-api-deployment.yaml",
8+
"matching-service-api-service.yaml",
9+
"matching-service-deployment.yaml",
10+
"nginx-deployment.yaml",
11+
"nginx-service.yaml",
12+
"peerprep-deployment.yaml",
13+
"peerprep-service.yaml",
14+
"rabbitmq-service.yaml",
15+
"rabbitmq-statefulset.yaml",
16+
"redis-service.yaml",
17+
"redis-statefulset.yaml",
18+
"storage-blob-api-deployment.yaml",
19+
"storage-blob-api-service.yaml",
20+
"user-service-deployment.yaml",
21+
"user-service-service.yaml"
22+
)
23+
24+
# Loop through each file and apply it using kubectl
25+
foreach ($file in $files) {
26+
Write-Output "Applying $file..."
27+
kubectl apply -f $file
28+
}
29+
30+
Write-Output "All files applied."

peerprep/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# environment file
44
.env
5+
.dockerignore
56

67
# dependencies
78
/node_modules

peerprep/app/actions/server_actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export async function login(state: FormState, formData: FormData) {
5757
await createSession(json.data);
5858
redirect("/questions");
5959
} else {
60-
console.log(json.error);
60+
console.log("Get session login error: " + json.error + " : " + json.status);
6161
}
6262
}
6363

peerprep/app/actions/session.ts

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,42 @@ export enum CookieNames {
99

1010
export async function createSession(userDataAccessToken: UserDataAccessToken) {
1111
const expiresAt = new Date(Date.now() + 24 * 60 * 60 * 1000);
12-
cookies().set(
13-
CookieNames.SESSION.valueOf(),
14-
userDataAccessToken.accessToken,
15-
{
12+
try {
13+
console.log("Setting cookie...");
14+
15+
cookies().set(
16+
CookieNames.SESSION.valueOf(),
17+
userDataAccessToken.accessToken,
18+
{
19+
httpOnly: true,
20+
// TODO: set this to true
21+
secure: false,
22+
expires: expiresAt,
23+
sameSite: "lax",
24+
path: "/",
25+
},
26+
);
27+
28+
const userData: UserData = {
29+
email: userDataAccessToken.email,
30+
username: userDataAccessToken.username,
31+
id: userDataAccessToken.id,
32+
isAdmin: userDataAccessToken.isAdmin,
33+
createdAt: userDataAccessToken.createdAt,
34+
};
35+
36+
cookies().set(CookieNames.USER_DATA.valueOf(), JSON.stringify(userData), {
1637
httpOnly: true,
1738
secure: false,
1839
expires: expiresAt,
1940
sameSite: "lax",
2041
path: "/",
21-
},
22-
);
23-
24-
const userData: UserData = {
25-
email: userDataAccessToken.email,
26-
username: userDataAccessToken.username,
27-
id: userDataAccessToken.id,
28-
isAdmin: userDataAccessToken.isAdmin,
29-
createdAt: userDataAccessToken.createdAt,
30-
};
42+
});
3143

32-
cookies().set(CookieNames.USER_DATA.valueOf(), JSON.stringify(userData), {
33-
httpOnly: true,
34-
secure: false,
35-
expires: expiresAt,
36-
sameSite: "lax",
37-
path: "/",
38-
});
44+
console.log("Cookies set successfully.");
45+
} catch (error) {
46+
console.error("Error setting cookie:", error);
47+
}
3948
}
4049

4150
export async function expireSession() {

peerprep/app/api/internal/formatter/helper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ export async function callFormatter(
1414
});
1515

1616
if (!response.ok) {
17-
const errorData = await response.json();
18-
console.error("Formatter: ", errorData);
19-
throw new Error(`${errorData.detail}`);
17+
const errorData = (await response.json()) as StatusBody;
18+
console.error("FormatterHelper: ", errorData);
19+
throw new Error(`${errorData.error}`);
2020
}
2121

2222
const formattedCode = (await response.json()) as FormatResponse;
2323
console.log(formattedCode);
2424
return formattedCode;
2525
} catch (err: any) {
26-
throw new Error(`Failed to format code: ${err.message}`);
26+
throw new Error(`${err.message}`);
2727
}
2828
}

peerprep/app/api/internal/formatter/route.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,12 @@ export async function POST(req: NextRequest) {
3939
if (!response.ok) {
4040
const errorData = await response.json();
4141
console.log("Formatter: ", errorData);
42-
throw new Error(`Failed to format code: ${response.statusText}`);
42+
throw new Error(`Failed to format code: ${errorData.detail}`);
4343
}
4444

4545
const formattedCode = (await response.json()) as FormatResponse;
4646
return NextResponse.json(formattedCode);
4747
} catch (error: any) {
48-
return NextResponse.json(
49-
{ error: `Formatting failed: ${error.message}` },
50-
{ status: 500 },
51-
);
48+
return NextResponse.json({ error: `${error.message}` }, { status: 500 });
5249
}
5350
}

peerprep/components/questionpage/CollabEditor.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ export default function CollabEditor({
9393
async function formatCode(value: string, language: Language) {
9494
try {
9595
const res = await callFormatter(value, language);
96-
if ("detail" in res) {
97-
console.log(res.detail);
98-
}
9996
const formatResponse = res as FormatResponse;
10097
const formatted_code = formatResponse.formatted_code;
10198

@@ -113,8 +110,8 @@ export default function CollabEditor({
113110
};
114111
socket.send(JSON.stringify(msg));
115112
}
116-
} catch (e) {
117-
alert("Failed to format code. Check console.");
113+
} catch (e: any) {
114+
alert(e.message);
118115
}
119116
}
120117

peerprep/components/questionpage/Matchmaking.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
import ResettingStopwatch from "../shared/ResettingStopwatch";
1818
import PeerprepDropdown from "../shared/PeerprepDropdown";
1919

20-
const QUERY_INTERVAL_MILLISECONDS = 1000;
20+
const QUERY_INTERVAL_MILLISECONDS = 5000;
2121
const TIMEOUT_MILLISECONDS = 30000;
2222

2323
const getMatchRequestTime = (): string => {

0 commit comments

Comments
 (0)