contest submisssions
This commit is contained in:
@@ -5,6 +5,36 @@ import axios from '../../axios';
|
||||
// Типы
|
||||
// =====================
|
||||
|
||||
// =====================
|
||||
// Типы для посылок
|
||||
// =====================
|
||||
|
||||
export interface Solution {
|
||||
id: number;
|
||||
missionId: number;
|
||||
language: string;
|
||||
languageVersion: string;
|
||||
sourceCode: string;
|
||||
status: string;
|
||||
time: string;
|
||||
testerState: string;
|
||||
testerErrorCode: string;
|
||||
testerMessage: string;
|
||||
currentTest: number;
|
||||
amountOfTests: number;
|
||||
}
|
||||
|
||||
export interface Submission {
|
||||
id: number;
|
||||
userId: number;
|
||||
solution: Solution;
|
||||
contestId: number;
|
||||
contestName: string;
|
||||
sourceType: string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export interface Mission {
|
||||
id: number;
|
||||
authorId: number;
|
||||
@@ -38,7 +68,8 @@ export interface Contest {
|
||||
attemptDurationMinutes?: number;
|
||||
maxAttempts?: number;
|
||||
allowEarlyFinish?: boolean;
|
||||
groups?: Group[];
|
||||
groupId?: number;
|
||||
groupName?: string;
|
||||
missions?: Mission[];
|
||||
articles?: any[];
|
||||
members?: Member[];
|
||||
@@ -59,7 +90,8 @@ export interface CreateContestBody {
|
||||
attemptDurationMinutes?: number;
|
||||
maxAttempts?: number;
|
||||
allowEarlyFinish?: boolean;
|
||||
groupIds?: number[];
|
||||
groupId?: number;
|
||||
groupName?: string;
|
||||
missionIds?: number[];
|
||||
articleIds?: number[];
|
||||
}
|
||||
@@ -87,6 +119,12 @@ interface ContestsState {
|
||||
status: Status;
|
||||
error?: string;
|
||||
};
|
||||
fetchMySubmissions: {
|
||||
submissions: Submission[];
|
||||
status: Status;
|
||||
error?: string;
|
||||
};
|
||||
|
||||
// 🆕 Добавляем updateContest и deleteContest
|
||||
updateContest: {
|
||||
contest: Contest;
|
||||
@@ -129,7 +167,8 @@ const initialState: ContestsState = {
|
||||
attemptDurationMinutes: 0,
|
||||
maxAttempts: 0,
|
||||
allowEarlyFinish: false,
|
||||
groups: [],
|
||||
groupId: undefined,
|
||||
groupName: undefined,
|
||||
missions: [],
|
||||
articles: [],
|
||||
members: [],
|
||||
@@ -137,6 +176,12 @@ const initialState: ContestsState = {
|
||||
status: 'idle',
|
||||
error: undefined,
|
||||
},
|
||||
fetchMySubmissions: {
|
||||
submissions: [],
|
||||
status: 'idle',
|
||||
error: undefined,
|
||||
},
|
||||
|
||||
createContest: {
|
||||
contest: {
|
||||
id: 0,
|
||||
@@ -149,7 +194,8 @@ const initialState: ContestsState = {
|
||||
attemptDurationMinutes: 0,
|
||||
maxAttempts: 0,
|
||||
allowEarlyFinish: false,
|
||||
groups: [],
|
||||
groupId: undefined,
|
||||
groupName: undefined,
|
||||
missions: [],
|
||||
articles: [],
|
||||
members: [],
|
||||
@@ -169,7 +215,8 @@ const initialState: ContestsState = {
|
||||
attemptDurationMinutes: 0,
|
||||
maxAttempts: 0,
|
||||
allowEarlyFinish: false,
|
||||
groups: [],
|
||||
groupId: undefined,
|
||||
groupName: undefined,
|
||||
missions: [],
|
||||
articles: [],
|
||||
members: [],
|
||||
@@ -198,6 +245,24 @@ const initialState: ContestsState = {
|
||||
// Async Thunks
|
||||
// =====================
|
||||
|
||||
// Мои посылки в контесте
|
||||
export const fetchMySubmissions = createAsyncThunk(
|
||||
'contests/fetchMySubmissions',
|
||||
async (contestId: number, { rejectWithValue }) => {
|
||||
try {
|
||||
const response = await axios.get<Submission[]>(
|
||||
`/contests/${contestId}/submissions/my`,
|
||||
);
|
||||
return response.data;
|
||||
} catch (err: any) {
|
||||
return rejectWithValue(
|
||||
err.response?.data?.message || 'Failed to fetch my submissions',
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
// Все контесты
|
||||
export const fetchContests = createAsyncThunk(
|
||||
'contests/fetchAll',
|
||||
@@ -353,6 +418,25 @@ const contestsSlice = createSlice({
|
||||
},
|
||||
},
|
||||
extraReducers: (builder) => {
|
||||
// 🆕 fetchMySubmissions
|
||||
builder.addCase(fetchMySubmissions.pending, (state) => {
|
||||
state.fetchMySubmissions.status = 'loading';
|
||||
state.fetchMySubmissions.error = undefined;
|
||||
});
|
||||
builder.addCase(
|
||||
fetchMySubmissions.fulfilled,
|
||||
(state, action: PayloadAction<Submission[]>) => {
|
||||
state.fetchMySubmissions.status = 'successful';
|
||||
state.fetchMySubmissions.submissions = action.payload;
|
||||
},
|
||||
);
|
||||
builder.addCase(fetchMySubmissions.rejected, (state, action: any) => {
|
||||
state.fetchMySubmissions.status = 'failed';
|
||||
state.fetchMySubmissions.error = action.payload;
|
||||
});
|
||||
|
||||
|
||||
|
||||
// fetchContests
|
||||
builder.addCase(fetchContests.pending, (state) => {
|
||||
state.fetchContests.status = 'loading';
|
||||
|
||||
@@ -56,6 +56,7 @@ const initialState: SubmitState = {
|
||||
export const submitMission = createAsyncThunk(
|
||||
'submit/submitMission',
|
||||
async (submitData: Submit, { rejectWithValue }) => {
|
||||
console.log(submitData);
|
||||
try {
|
||||
const response = await axios.post('/submits', submitData);
|
||||
return response.data;
|
||||
|
||||
Reference in New Issue
Block a user