refactor: alle Services strukturiert und vereinheitlicht (v1.1.120) – Webservice/Database getrennt, Postfix 'Service' eingeführt

This commit is contained in:
ISA
2025-05-20 15:03:05 +02:00
parent 6f9a50ef5c
commit 4c94ba82ae
7 changed files with 72 additions and 95 deletions

View File

@@ -1,4 +1,4 @@
// services/utils/fetchWithTimeout.js
// /services/utils/fetchWithTimeout.js
const fetchWithTimeout = (url, options, timeout = 5000) => {
const controller = new AbortController();

View File

@@ -1,18 +1,36 @@
// /services/webservice/fetchGisSystemStaticService.js
export const fetchGisSystemStaticService = async (url, setGisSystemStatic, setGisSystemStaticLoaded) => {
try {
const response = await fetch(url);
const jsonResponse = await response.json();
if (jsonResponse && jsonResponse.Systems) {
setGisSystemStatic(jsonResponse.Systems);
setGisSystemStaticLoaded(true);
} else {
console.error('Erwartete Daten im "Systems"-Array nicht gefunden', jsonResponse);
setGisSystemStatic([]);
}
} catch (error) {
console.error("Fehler beim Laden der Daten: ", error);
setGisSystemStatic([]);
/**
* Holt GIS-Systemdaten (Systemübersicht) vom TALAS WebService.
*
* @returns {Promise<Array>} Liste mit Systems[]
* @throws {Error} bei Fehler oder ungültiger Antwortstruktur
*/
export const fetchGisSystemStaticService = async () => {
const mode = process.env.NEXT_PUBLIC_API_PORT_MODE;
const apiBaseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80/talas5/ClientData/WebServiceMap.asmx` : `${window.location.origin}/talas5/ClientData/WebServiceMap.asmx`;
const params = new URLSearchParams(window.location.search);
const idMap = params.get("m");
const idUser = params.get("u");
const url = `${apiBaseUrl}/GisSystemStatic?idMap=${idMap}&idUser=${idUser}`;
console.log("📡 fetchGisSystemStaticService von service URL:", url);
const response = await fetch(url);
if (!response.ok) {
const message = `❌ Fehler: ${response.status} ${response.statusText}`;
console.error(message);
throw new Error(message);
}
const jsonResponse = await response.json();
if (!jsonResponse?.Systems) {
throw new Error("Antwortstruktur ungültig 'Systems' fehlt");
}
return jsonResponse.Systems;
};