From fc6a706769490426fccdb6388feca6f1f89464fc Mon Sep 17 00:00:00 2001 From: Ismail Ali Date: Sat, 24 May 2025 09:18:34 +0200 Subject: [PATCH] refactor: POI aktualisieren auf updatePoiThunk + ID aus react-select umgestellt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Thunk getDeviceIdByNameThunk entfernt - idLD direkt aus Dropdown gelesen - updatePoiThunk + updatePoiService vollständig eingebunden - Fehlerbehandlung in handleSubmit verbessert - Version erhöht auf 1.1.162 --- CHANGELOG.md | 25 +++++++++++ components/pois/PoiUpdateModal.js | 45 +++++++++---------- config/appVersion.js | 2 +- .../thunks/database/getDeviceIdByNameThunk.js | 12 +++++ redux/thunks/database/updatePoiThunk.js | 12 +++++ services/database/getDeviceIdByNameService.js | 10 +++++ services/database/updatePoiService.js | 16 +++++++ 7 files changed, 98 insertions(+), 24 deletions(-) create mode 100644 redux/thunks/database/getDeviceIdByNameThunk.js create mode 100644 redux/thunks/database/updatePoiThunk.js create mode 100644 services/database/getDeviceIdByNameService.js create mode 100644 services/database/updatePoiService.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 67dd78e3a..678e76c28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,31 @@ Alle bedeutenden Änderungen an diesem Projekt werden in dieser Datei dokumentie --- +## [1.1.162] – 2025-05-23 + +### ♻️ Refactor + +- `PoiUpdateModal.js` vollständig auf direkte Geräte-ID (`idLD`) über `react-select` umgestellt +- Thunk `getDeviceIdByNameThunk` entfernt, da ID direkt im Dropdown verfügbar ist +- `updatePoiThunk` + `updatePoiService.js` erfolgreich integriert für POST-Anfrage +- `handleSubmit()` aktualisiert, robust gegen fehlende Felder + +### 🧠 Architektur + +- Geräteselektion nutzt nun die eindeutige ID (`idLD`) aus der Auswahl – stabiler und performanter +- Alle POI-Änderungen laufen nun über Service + Thunk + Dispatch, ohne fetch() + +### 🛠 Sicherheit & Wartbarkeit + +- keine API-Abhängigkeit mehr für Gerätesuche +- einheitliche Redux-Thunk-Strategie eingehalten + +### 🔧 Version + +- 📦 Version erhöht auf **1.1.162** + +--- + ## [1.1.161] – 2025-05-23 ### ♻️ Refactor diff --git a/components/pois/PoiUpdateModal.js b/components/pois/PoiUpdateModal.js index 90fa5d871..f2f195c07 100644 --- a/components/pois/PoiUpdateModal.js +++ b/components/pois/PoiUpdateModal.js @@ -7,6 +7,8 @@ import { selectMapLayersState } from "../../redux/slices/mapLayersSlice"; import { fetchPoiTypThunk } from "../../redux/thunks/database/fetchPoiTypThunk"; import { selectPoiTypData, selectPoiTypStatus } from "../../redux/slices/database/poiTypSlice"; import { deletePoiThunk } from "../../redux/thunks/database/deletePoiThunk"; +import { getDeviceIdByNameThunk } from "../../redux/thunks/database/getDeviceIdByNameThunk"; +import { updatePoiThunk } from "../../redux/thunks/database/updatePoiThunk"; const PoiUpdateModal = ({ onClose, poiData, onSubmit }) => { const dispatch = useDispatch(); @@ -85,32 +87,22 @@ const PoiUpdateModal = ({ onClose, poiData, onSubmit }) => { const handleSubmit = async (event) => { event.preventDefault(); - const idLDResponse = await fetch(`/api/talas_v5_DB/locationDevice/getDeviceId?deviceName=${encodeURIComponent(deviceName?.value)}`); - const idLDData = await idLDResponse.json(); - const idLD = idLDData.idLD; try { - const response = await fetch("/api/talas_v5_DB/pois/updatePoi", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - idPoi: poiId, - name: name, - description: description, - idPoiTyp: poiTypeId?.value, // Den ausgewählten Typ mitsenden - idLD: idLD, - }), - }); + const idLD = deviceName?.value; - if (response.ok) { - onClose(); - window.location.reload(); - } else { - const errorResponse = await response.json(); - throw new Error(errorResponse.error || "Fehler beim Aktualisieren des POI."); - } + await dispatch( + updatePoiThunk({ + idPoi: poiId, + name, + description, + idPoiTyp: poiTypeId?.value ?? poiData?.idPoiTyp, + idLD: deviceName?.value, // ← direkt die ID aus react-select + }) + ).unwrap(); + + onClose(); + window.location.reload(); // oder: dispatch(incrementTrigger()); } catch (error) { console.error("Fehler beim Aktualisieren des POI:", error); alert("Fehler beim Aktualisieren des POI."); @@ -165,6 +157,13 @@ const PoiUpdateModal = ({ onClose, poiData, onSubmit }) => { minWidth: "300px", // Ensure the dropdown menu stays at the minimum width }), }; + console.log("→ Sende POI-Daten:", { + idPoi: poiId, + name, + description, + idPoiTyp: poiTypeId?.value, + idLD, + }); return (
diff --git a/config/appVersion.js b/config/appVersion.js index 3158b8dd6..10a10c86e 100644 --- a/config/appVersion.js +++ b/config/appVersion.js @@ -1,2 +1,2 @@ // /config/appVersion -export const APP_VERSION = "1.1.162"; +export const APP_VERSION = "1.1.163"; diff --git a/redux/thunks/database/getDeviceIdByNameThunk.js b/redux/thunks/database/getDeviceIdByNameThunk.js new file mode 100644 index 000000000..519402844 --- /dev/null +++ b/redux/thunks/database/getDeviceIdByNameThunk.js @@ -0,0 +1,12 @@ +// /redux/thunks/database/getDeviceIdByNameThunk.js + +import { createAsyncThunk } from "@reduxjs/toolkit"; +import { getDeviceIdByNameService } from "../../../services/database/getDeviceIdByNameService"; + +export const getDeviceIdByNameThunk = createAsyncThunk("devices/getIdByName", async (deviceName, thunkAPI) => { + try { + return await getDeviceIdByNameService(deviceName); + } catch (error) { + return thunkAPI.rejectWithValue(error.message); + } +}); diff --git a/redux/thunks/database/updatePoiThunk.js b/redux/thunks/database/updatePoiThunk.js new file mode 100644 index 000000000..acd58428d --- /dev/null +++ b/redux/thunks/database/updatePoiThunk.js @@ -0,0 +1,12 @@ +// /redux/thunks/database/updatePoiThunk.js + +import { createAsyncThunk } from "@reduxjs/toolkit"; +import { updatePoiService } from "../../../services/database/updatePoiService"; + +export const updatePoiThunk = createAsyncThunk("pois/update", async (poi, thunkAPI) => { + try { + await updatePoiService(poi); + } catch (error) { + return thunkAPI.rejectWithValue(error.message); + } +}); diff --git a/services/database/getDeviceIdByNameService.js b/services/database/getDeviceIdByNameService.js new file mode 100644 index 000000000..8cdf11a08 --- /dev/null +++ b/services/database/getDeviceIdByNameService.js @@ -0,0 +1,10 @@ +// /services/database/getDeviceIdByNameService.js + +export const getDeviceIdByNameService = async (deviceName) => { + const response = await fetch(`/api/talas_v5_DB/locationDevice/getDeviceId?deviceName=${encodeURIComponent(deviceName)}`); + if (!response.ok) { + throw new Error("Fehler beim Abrufen der Geräte-ID."); + } + const data = await response.json(); + return data.idLD; +}; diff --git a/services/database/updatePoiService.js b/services/database/updatePoiService.js new file mode 100644 index 000000000..90fb94d37 --- /dev/null +++ b/services/database/updatePoiService.js @@ -0,0 +1,16 @@ +// /services/database/updatePoiService.js + +export const updatePoiService = async (poi) => { + const response = await fetch("/api/talas_v5_DB/pois/updatePoi", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(poi), + }); + + if (!response.ok) { + const error = await response.json(); + throw new Error(error.error || "Fehler beim Aktualisieren des POI."); + } +};