Skip to content

Commit d538973

Browse files
Merge pull request #2 from Advik-Gupta/main
Refactored to use current backend and made submissions page
2 parents e7a6002 + 37c31b7 commit d538973

32 files changed

+2166
-571
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"axios": "^1.7.7",
3232
"class-variance-authority": "^0.7.0",
3333
"clsx": "^2.1.1",
34+
"firebase": "^12.3.0",
3435
"geist": "^1.3.0",
3536
"lucide-react": "^0.437.0",
3637
"next": "^14.2.4",

pnpm-lock.yaml

Lines changed: 777 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api/adminDashboard.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { handleAPIError } from "@/lib/error";
22
import api from ".";
3-
// import { generateSampleLeaderboard as generateSampleLeaderBoard } from "./sampleData";
4-
53
export interface RoundParams {
64
round_id: number;
75
}
@@ -21,20 +19,3 @@ export async function RoundEnable(data: RoundParams) {
2119
throw handleAPIError(e);
2220
}
2321
}
24-
25-
export async function GetLeaderBoard() {
26-
try {
27-
const response = await api.get<LeaderBoardUser[]>("/leaderboard");
28-
return response.data
29-
.filter((user) => user.Score !== null) // Exclude users with null scores
30-
.sort((a, b) => b.Score! - a.Score!) // Sort by score in descending order
31-
.slice(0, 10); // Take the top 10
32-
33-
// return generateSampleLeaderBoard()
34-
// .filter((user) => user.Score !== null)
35-
// .sort((a, b) => b.Score! - a.Score!)
36-
// .slice(0, 10);
37-
} catch (e) {
38-
throw handleAPIError(e);
39-
}
40-
}

src/api/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface CustomAxiosRequestConfig extends InternalAxiosRequestConfig {
88

99
const api = axios.create({
1010
baseURL: process.env.NEXT_PUBLIC_BASEURL,
11+
withCredentials: true,
1112
});
1213

1314
// Add a request interceptor
@@ -34,13 +35,11 @@ api.interceptors.response.use(
3435

3536
try {
3637
await api.post<ApiResponse>(
37-
`${process.env.NEXT_PUBLIC_BASEURL}/token/refresh`,
38+
"/refreshToken",
3839
{},
39-
{
40-
withCredentials: true,
41-
},
40+
{ withCredentials: true },
4241
);
43-
return api(originalRequest); // Use the api instance to retry the request
42+
return api(originalRequest);
4443
} catch {
4544
// Handle refresh token error or redirect to login
4645
toast.error("Session expired. Please login again.");

src/api/login.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import api from ".";
66

77
export async function login(body: z.infer<typeof loginFormSchema>) {
88
try {
9-
const { data } = await api.post<ApiResponse>(`/login/user`, body);
9+
const { data } = await api.post<ApiResponse>(`/login`, body);
1010
return data.message;
1111
} catch (e) {
1212
throw handleAPIError(e);

src/api/questions.ts

Lines changed: 50 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,44 @@
11
import { handleAPIError } from "@/lib/error";
22
import api from ".";
3-
// import { generateSampleData } from "./sampleData";
3+
4+
export interface CreateQuestionParams {
5+
ID?: string;
6+
Description: string;
7+
Title: string;
8+
Qtype: string;
9+
Isbountyactive?: boolean;
10+
InputFormat: string[];
11+
Points: number;
12+
Round: number;
13+
Constraints: string[];
14+
OutputFormat: string[];
15+
SampleTestInput: string[];
16+
SampleTestOutput: string[];
17+
Explanation: string[];
18+
}
419

520
export interface UpdateQuestionParams {
6-
id: string;
7-
description: string;
8-
title: string;
9-
input_format: string[];
10-
points: number;
11-
round: number;
12-
constraints: string[];
13-
output_format: string[];
14-
sample_test_input: string[];
15-
sample_test_output: string[];
16-
sample_explanation: string[];
21+
ID: string;
22+
Description: string;
23+
Title: string;
24+
Qtype: string;
25+
Isbountyactive: boolean;
26+
InputFormat: string[];
27+
Points: number;
28+
Round: number;
29+
Constraints: string[];
30+
OutputFormat: string[];
31+
SampleTestInput: string[];
32+
SampleTestOutput: string[];
33+
Explanation: string[];
1734
}
1835

1936
export interface QuestionResponse {
2037
ID: string;
2138
Description: string;
2239
Title: string;
40+
Qtype: string;
41+
Isbountyactive: boolean;
2342
InputFormat: string[];
2443
Points: number;
2544
Round: number;
@@ -30,47 +49,41 @@ export interface QuestionResponse {
3049
Explanation: string[];
3150
}
3251

33-
export interface CreateQuestionParams {
34-
description: string;
35-
title: string;
36-
input_format: string[];
37-
points: number;
38-
round: number;
39-
constraints: string[];
40-
output_format: string[];
41-
sample_test_input: string[];
42-
sample_test_output: string[];
43-
sample_explanation: string[];
52+
export interface QuestionsIdApiResponse {
53+
question: QuestionResponse[];
54+
status: string;
55+
}
56+
57+
export interface QuestionsApiResponse {
58+
questions: QuestionResponse[];
59+
status: string;
4460
}
4561

46-
interface DeleteQuestionResponse {
62+
export interface DeleteQuestionResponse {
63+
status: string;
4764
message: string;
4865
}
49-
// GET REQUEST
66+
5067
export async function GetAllQuestions() {
5168
try {
52-
const response = await api.get<QuestionResponse[]>("/questions");
53-
return response.data;
54-
// return generateSampleData()
69+
const response = await api.get<QuestionsApiResponse>("/question");
70+
return response.data.questions;
5571
} catch (e) {
5672
console.log(e);
5773
return [];
5874
}
5975
}
6076

61-
// POST REQUEST
6277
export async function CreateQuestion(data: CreateQuestionParams) {
6378
try {
64-
console.log(data);
65-
const response = await api.post<QuestionResponse>("/question/create", data);
79+
const response = await api.post<QuestionResponse>("/question", data);
6680
return response.data;
6781
} catch (e) {
6882
console.log(e);
6983
throw handleAPIError(e);
7084
}
7185
}
7286

73-
// DELETE REQUEST
7487
export async function DeleteQuestion(id: string) {
7588
try {
7689
const response = await api.delete<DeleteQuestionResponse>(
@@ -83,14 +96,16 @@ export async function DeleteQuestion(id: string) {
8396
}
8497

8598
export async function GetQuestionById(id: string) {
86-
const response = await api.get<QuestionResponse>(`/question/${id}`);
99+
const response = await api.get<QuestionsIdApiResponse>(`/question/${id}`);
87100
return response.data;
88101
}
89102

90-
// PATCH REQUEST
91103
export async function UpdateQuestion(data: UpdateQuestionParams) {
92104
try {
93-
const response = await api.patch<QuestionResponse>("/question", data);
105+
const response = await api.put<QuestionResponse>(
106+
`/question/${data.ID}`,
107+
data,
108+
);
94109
return response.data;
95110
} catch (e) {
96111
throw handleAPIError(e);

src/api/submissions.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { handleAPIError } from "@/lib/error";
2+
import api from ".";
3+
4+
export interface User {
5+
ID: string;
6+
Email: string;
7+
RegNo: string;
8+
Role: string;
9+
RoundQualified: number;
10+
Score: number;
11+
Name: string;
12+
IsBanned: boolean;
13+
}
14+
15+
export interface Submission {
16+
ID: string;
17+
QuestionID: string;
18+
TestcasesPassed?: number;
19+
TestcasesFailed?: number;
20+
Runtime?: number;
21+
SubmissionTime: string;
22+
SourceCode: string;
23+
LanguageID: number;
24+
Description?: string;
25+
Memory?: number;
26+
UserID?: string;
27+
Status?: string;
28+
}
29+
30+
export interface SubmissionResult {
31+
ID: string;
32+
TestcaseID?: string;
33+
SubmissionID: string;
34+
Runtime?: number;
35+
Memory?: number;
36+
PointsAwarded: number;
37+
Status: string;
38+
Description?: string;
39+
}
40+
41+
export interface Testcase {
42+
ID: string;
43+
Input: string;
44+
ExpectedOutput: string;
45+
Hidden: boolean;
46+
}
47+
48+
export type SubmissionWithResultsAndTestcases = {
49+
submission: Submission;
50+
results: (SubmissionResult & { testcase?: Testcase })[];
51+
};
52+
53+
export type UserWithSubmissions = {
54+
user: User;
55+
submissions: SubmissionWithResultsAndTestcases[];
56+
};
57+
58+
export async function getUserSubmissions(
59+
userID: string,
60+
): Promise<UserWithSubmissions> {
61+
try {
62+
const response = await api.get<UserWithSubmissions>(
63+
`/admin/users/${userID}/submissions`,
64+
);
65+
return response.data;
66+
} catch (error) {
67+
throw handleAPIError(error);
68+
}
69+
}

0 commit comments

Comments
 (0)