contests update

This commit is contained in:
Виталий Лавшонок
2025-11-06 18:27:28 +03:00
parent 1b39b8c77f
commit 6c92c789d0
5 changed files with 136 additions and 108 deletions

View File

@@ -11,8 +11,6 @@ export interface Mission {
name: string;
difficulty: number;
tags: string[];
createdAt: string;
updatedAt: string;
timeLimitMilliseconds: number;
memoryLimitBytes: number;
statements: string;
@@ -32,17 +30,18 @@ export interface Group {
export interface Contest {
id: number;
name: string;
description: string;
description?: string;
scheduleType: 'AlwaysOpen' | 'FixedWindow' | 'RollingWindow';
startsAt: string;
endsAt: string;
attemptDurationMinutes: number;
maxAttempts: number;
allowEarlyFinish: boolean;
groups: Group[];
missions: Mission[];
articles: any[];
members: Member[];
visibility: 'Public' | 'GroupPrivate';
startsAt?: string;
endsAt?: string;
attemptDurationMinutes?: number;
maxAttempts?: number;
allowEarlyFinish?: boolean;
groups?: Group[];
missions?: Mission[];
articles?: any[];
members?: Member[];
}
interface ContestsResponse {
@@ -52,17 +51,17 @@ interface ContestsResponse {
export interface CreateContestBody {
name: string;
description: string;
description?: string;
scheduleType: 'AlwaysOpen' | 'FixedWindow' | 'RollingWindow';
visibility: 'Public' | 'GroupPrivate';
startsAt: string;
endsAt: string;
attemptDurationMinutes: number;
maxAttempts: number;
allowEarlyFinish: boolean;
groupId: number;
missionIds: number[];
articleIds: number[];
startsAt?: string;
endsAt?: string;
attemptDurationMinutes?: number;
maxAttempts?: number;
allowEarlyFinish?: boolean;
groupIds?: number[];
missionIds?: number[];
articleIds?: number[];
}
// =====================
@@ -76,38 +75,38 @@ interface ContestsState {
contests: Contest[];
hasNextPage: boolean;
status: Status;
error: string | null;
error?: string;
};
fetchContestById: {
contest: Contest;
status: Status;
error: string | null;
error?: string;
};
createContest: {
contest: Contest;
status: Status;
error: string | null;
error?: string;
};
// 🆕 Добавляем updateContest и deleteContest
updateContest: {
contest: Contest;
status: Status;
error: string | null;
error?: string;
};
deleteContest: {
status: Status;
error: string | null;
error?: string;
};
fetchMyContests: {
contests: Contest[];
status: Status;
error: string | null;
error?: string;
};
fetchRegisteredContests: {
contests: Contest[];
hasNextPage: boolean;
status: Status;
error: string | null;
error?: string;
};
}
@@ -116,7 +115,7 @@ const initialState: ContestsState = {
contests: [],
hasNextPage: false,
status: 'idle',
error: null,
error: undefined,
},
fetchContestById: {
contest: {
@@ -124,6 +123,7 @@ const initialState: ContestsState = {
name: '',
description: '',
scheduleType: 'AlwaysOpen',
visibility: 'Public',
startsAt: '',
endsAt: '',
attemptDurationMinutes: 0,
@@ -135,7 +135,7 @@ const initialState: ContestsState = {
members: [],
},
status: 'idle',
error: null,
error: undefined,
},
createContest: {
contest: {
@@ -143,6 +143,7 @@ const initialState: ContestsState = {
name: '',
description: '',
scheduleType: 'AlwaysOpen',
visibility: 'Public',
startsAt: '',
endsAt: '',
attemptDurationMinutes: 0,
@@ -154,7 +155,7 @@ const initialState: ContestsState = {
members: [],
},
status: 'idle',
error: null,
error: undefined,
},
updateContest: {
contest: {
@@ -162,6 +163,7 @@ const initialState: ContestsState = {
name: '',
description: '',
scheduleType: 'AlwaysOpen',
visibility: 'Public',
startsAt: '',
endsAt: '',
attemptDurationMinutes: 0,
@@ -173,22 +175,22 @@ const initialState: ContestsState = {
members: [],
},
status: 'idle',
error: null,
error: undefined,
},
deleteContest: {
status: 'idle',
error: null,
error: undefined,
},
fetchMyContests: {
contests: [],
status: 'idle',
error: null,
error: undefined,
},
fetchRegisteredContests: {
contests: [],
hasNextPage: false,
status: 'idle',
error: null,
error: undefined,
},
};
@@ -265,7 +267,7 @@ export const updateContest = createAsyncThunk(
{ rejectWithValue },
) => {
try {
const response = await axios.patch<Contest>(
const response = await axios.put<Contest>(
`/contests/${contestId}`,
contestData,
);
@@ -354,7 +356,7 @@ const contestsSlice = createSlice({
// fetchContests
builder.addCase(fetchContests.pending, (state) => {
state.fetchContests.status = 'loading';
state.fetchContests.error = null;
state.fetchContests.error = undefined;
});
builder.addCase(
fetchContests.fulfilled,
@@ -372,7 +374,7 @@ const contestsSlice = createSlice({
// fetchContestById
builder.addCase(fetchContestById.pending, (state) => {
state.fetchContestById.status = 'loading';
state.fetchContestById.error = null;
state.fetchContestById.error = undefined;
});
builder.addCase(
fetchContestById.fulfilled,
@@ -389,7 +391,7 @@ const contestsSlice = createSlice({
// createContest
builder.addCase(createContest.pending, (state) => {
state.createContest.status = 'loading';
state.createContest.error = null;
state.createContest.error = undefined;
});
builder.addCase(
createContest.fulfilled,
@@ -406,7 +408,7 @@ const contestsSlice = createSlice({
// 🆕 updateContest
builder.addCase(updateContest.pending, (state) => {
state.updateContest.status = 'loading';
state.updateContest.error = null;
state.updateContest.error = undefined;
});
builder.addCase(
updateContest.fulfilled,
@@ -423,7 +425,7 @@ const contestsSlice = createSlice({
// 🆕 deleteContest
builder.addCase(deleteContest.pending, (state) => {
state.deleteContest.status = 'loading';
state.deleteContest.error = null;
state.deleteContest.error = undefined;
});
builder.addCase(
deleteContest.fulfilled,
@@ -448,7 +450,7 @@ const contestsSlice = createSlice({
// fetchMyContests
builder.addCase(fetchMyContests.pending, (state) => {
state.fetchMyContests.status = 'loading';
state.fetchMyContests.error = null;
state.fetchMyContests.error = undefined;
});
builder.addCase(
fetchMyContests.fulfilled,
@@ -465,7 +467,7 @@ const contestsSlice = createSlice({
// fetchRegisteredContests
builder.addCase(fetchRegisteredContests.pending, (state) => {
state.fetchRegisteredContests.status = 'loading';
state.fetchRegisteredContests.error = null;
state.fetchRegisteredContests.error = undefined;
});
builder.addCase(
fetchRegisteredContests.fulfilled,