missions and filter
This commit is contained in:
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user