missions and filter

This commit is contained in:
Виталий Лавшонок
2025-11-08 06:58:56 +03:00
parent 69655dda82
commit b12a3acf1d
26 changed files with 694 additions and 158 deletions

View File

@@ -20,6 +20,8 @@ export interface Mission {
tags: string[];
createdAt: string;
updatedAt: string;
timeLimit: number;
memoryLimit: number;
statements?: Statement[];
}
@@ -31,6 +33,7 @@ interface MissionsState {
fetchList: Status;
fetchById: Status;
upload: Status;
fetchMy: Status;
};
error: string | null;
}
@@ -45,6 +48,7 @@ const initialState: MissionsState = {
fetchList: 'idle',
fetchById: 'idle',
upload: 'idle',
fetchMy: 'idle',
},
error: null,
};
@@ -90,6 +94,22 @@ export const fetchMissionById = createAsyncThunk(
},
);
// ✅ GET /missions/my
export const fetchMyMissions = createAsyncThunk(
'missions/fetchMyMissions',
async (_, { rejectWithValue }) => {
try {
const response = await axios.get('/missions/my');
return response.data as Mission[]; // массив миссий пользователя
} catch (err: any) {
return rejectWithValue(
err.response?.data?.message ||
'Ошибка при получении моих миссий',
);
}
},
);
// POST /missions/upload
export const uploadMission = createAsyncThunk(
'missions/uploadMission',
@@ -189,6 +209,26 @@ const missionsSlice = createSlice({
},
);
// ✅ FETCH MY MISSIONS ───
builder.addCase(fetchMyMissions.pending, (state) => {
state.statuses.fetchMy = 'loading';
state.error = null;
});
builder.addCase(
fetchMyMissions.fulfilled,
(state, action: PayloadAction<Mission[]>) => {
state.statuses.fetchMy = 'successful';
state.missions = action.payload;
},
);
builder.addCase(
fetchMyMissions.rejected,
(state, action: PayloadAction<any>) => {
state.statuses.fetchMy = 'failed';
state.error = action.payload;
},
);
// ─── UPLOAD MISSION ───
builder.addCase(uploadMission.pending, (state) => {
state.statuses.upload = 'loading';