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:
ISA
2025-07-03 10:23:04 +02:00
parent 4245d7a991
commit cee3ee0581
15 changed files with 451 additions and 168 deletions

View 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;

View File

@@ -29,6 +29,7 @@ import messagesReducer from "./slices/messagesSlice";
import firmwareUpdateReducer from "@/redux/slices/firmwareUpdateSlice";
import confirmModalReducer from "./slices/confirmModalSlice";
import firmwareProgressReducer from "./slices/firmwareProgressSlice";
import systemspannung5VplusReducer from "./slices/systemspannung5VplusSlice";
const store = configureStore({
reducer: {
@@ -60,6 +61,7 @@ const store = configureStore({
firmwareUpdate: firmwareUpdateReducer,
confirmModal: confirmModalReducer,
firmwareProgress: firmwareProgressReducer,
systemspannung5Vplus: systemspannung5VplusReducer,
},
});

View File

@@ -0,0 +1,16 @@
// redux/thunks/getSystemspannung5VplusThunk.ts
import { createAsyncThunk } from "@reduxjs/toolkit";
import { fetchSystemspannung5VplusService } from "@/services/fetchSystemspannung5VplusService";
export const getSystemspannung5VplusThunk = createAsyncThunk(
"systemspannung5Vplus/fetch",
async (typ: "DIA0" | "DIA1" | "DIA2", thunkAPI) => {
try {
const data = await fetchSystemspannung5VplusService(typ);
return { typ, data };
} catch (error) {
console.error("Fehler in getSystemspannung5VplusThunk:", error);
return thunkAPI.rejectWithValue("Fehler beim Laden der 5V-Daten");
}
}
);