feat: API für Systemspannung +5V erfolgreich implementiert
- API-Handler `getSystemspannung5VplusHandler.ts` erstellt - JSON-Daten werden aus dem Verzeichnis `mocks/device-cgi-simulator/chartsData/systemspannung5Vplus/` geladen - unterstützt die Parameter DIA0, DIA1, DIA2 für unterschiedliche Datenfrequenzen - Fehlerbehandlung bei ungültigen Typen und fehlenden Dateien eingebaut - API getestet unter `/api/cpl/getSystemspannung5VplusHandler?typ=DIA0`
This commit is contained in:
48
redux/slices/systemspannung5VplusSlice.ts
Normal file
48
redux/slices/systemspannung5VplusSlice.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
// redux/slices/systemspannung5VplusSlice.ts
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { getSystemspannung5VplusThunk } from "../thunks/getSystemspannung5VplusThunk";
|
||||
|
||||
type StateType = {
|
||||
DIA0: any[]; // alle Werte
|
||||
DIA1: any[]; // stündlich
|
||||
DIA2: any[]; // täglich
|
||||
isLoading: boolean;
|
||||
error: string | null;
|
||||
};
|
||||
|
||||
const initialState: StateType = {
|
||||
DIA0: [],
|
||||
DIA1: [],
|
||||
DIA2: [],
|
||||
isLoading: false,
|
||||
error: null,
|
||||
};
|
||||
|
||||
export const systemspannung5VplusSlice = createSlice({
|
||||
name: "systemspannung5Vplus",
|
||||
initialState,
|
||||
reducers: {},
|
||||
extraReducers: (builder) => {
|
||||
builder
|
||||
.addCase(getSystemspannung5VplusThunk.pending, (state) => {
|
||||
state.isLoading = true;
|
||||
state.error = null;
|
||||
})
|
||||
.addCase(
|
||||
getSystemspannung5VplusThunk.fulfilled,
|
||||
(
|
||||
state,
|
||||
action: PayloadAction<{ typ: "DIA0" | "DIA1" | "DIA2"; data: any[] }>
|
||||
) => {
|
||||
state.isLoading = false;
|
||||
state[action.payload.typ] = action.payload.data;
|
||||
}
|
||||
)
|
||||
.addCase(getSystemspannung5VplusThunk.rejected, (state, action) => {
|
||||
state.isLoading = false;
|
||||
state.error = action.payload as string;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default systemspannung5VplusSlice.reducer;
|
||||
Reference in New Issue
Block a user