feat(mock): implementierte Mock-Daten für 6 Webservice-Endpunkte + Umschaltung via .env
- Hinzugefügt: __mocks__/webservice/ - gisLinesStatus.js - gisStationsMeasurements.js - gisStationsStaticDistrict.js - gisStationsStatusDistrict.js - gisSystemStatic.js - userRights.js - In allen fetch*Service-Dateien Umschaltung implementiert (über NEXT_PUBLIC_USE_MOCKS) - Fallback auf Mock-Daten bei Entwicklung oder Offline-Modus - Unterstützt schnelles UI-Testing und isolierte Feature-Entwicklung ohne Backend
This commit is contained in:
@@ -1,31 +1,45 @@
|
||||
// /services/webservice/fetchGisStationsMeasurementsService.js
|
||||
|
||||
export const fetchGisStationsMeasurementsService = async () => {
|
||||
const useMocks = process.env.NEXT_PUBLIC_USE_MOCKS === "true";
|
||||
const mode = process.env.NEXT_PUBLIC_API_PORT_MODE;
|
||||
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
||||
|
||||
const baseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx` : `${window.location.origin}${basePath}/ClientData/WebServiceMap.asmx`;
|
||||
if (useMocks) {
|
||||
console.log("🧪 Mock-Modus aktiviert: fetchGisStationsMeasurementsService");
|
||||
const { mockGisStationsMeasurements } = await import("../../__mocks__/webservice/gisStationsMeasurements.js");
|
||||
return mockGisStationsMeasurements.Statis;
|
||||
} else {
|
||||
const baseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx` : `${window.location.origin}${basePath}/ClientData/WebServiceMap.asmx`;
|
||||
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const idMap = params.get("m");
|
||||
const idUser = params.get("u");
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const idMap = params.get("m");
|
||||
const idUser = params.get("u");
|
||||
|
||||
const url = `${baseUrl}/GisStationsMeasurements?idMap=${idMap}&idUser=${idUser}`;
|
||||
console.log("📡 fetchGisStationsMeasurementsService URL:", url);
|
||||
const url = `${baseUrl}/GisStationsMeasurements?idMap=${idMap}&idUser=${idUser}`;
|
||||
console.log("📡 fetchGisStationsMeasurementsService URL:", url);
|
||||
|
||||
const response = await fetch(url);
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
const message = `❌ Fehler: ${response.status} ${response.statusText}`;
|
||||
console.error(message);
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
const message = `❌ Fehler: ${response.status} ${response.statusText}`;
|
||||
console.error(message);
|
||||
throw new Error(message);
|
||||
const text = await response.text();
|
||||
|
||||
let jsonResponse;
|
||||
try {
|
||||
jsonResponse = JSON.parse(text);
|
||||
} catch (e) {
|
||||
console.error("❌ Fehler beim JSON-Parsing der Antwort:", text);
|
||||
throw new Error("Antwort ist kein gültiges JSON");
|
||||
}
|
||||
|
||||
if (!jsonResponse?.Statis) {
|
||||
throw new Error("Antwortstruktur ungültig – 'Statis' fehlt");
|
||||
}
|
||||
|
||||
return jsonResponse.Statis;
|
||||
}
|
||||
|
||||
const jsonResponse = await response.json();
|
||||
|
||||
if (!jsonResponse?.Statis) {
|
||||
throw new Error("Antwortstruktur ungültig – 'Statis' fehlt");
|
||||
}
|
||||
|
||||
return jsonResponse.Statis;
|
||||
};
|
||||
|
||||
@@ -2,35 +2,42 @@
|
||||
|
||||
/**
|
||||
* Holt statische GIS-Stationen-Daten für Bezirke.
|
||||
* Wechselt automatisch zwischen echten Daten und Mock-Daten via .env.local
|
||||
*
|
||||
* @returns {Promise<Array>} Liste mit Points[]
|
||||
* @throws {Error} bei Fehler oder ungültiger Antwortstruktur
|
||||
*/
|
||||
export const fetchGisStationsStaticDistrictService = async () => {
|
||||
const useMocks = process.env.NEXT_PUBLIC_USE_MOCKS === "true";
|
||||
const mode = process.env.NEXT_PUBLIC_API_PORT_MODE;
|
||||
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
||||
const baseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx` : `${window.location.origin}${basePath}/ClientData/WebServiceMap.asmx`;
|
||||
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const idMap = params.get("m");
|
||||
const idUser = params.get("u");
|
||||
if (useMocks) {
|
||||
console.log("🧪 Mock-Modus aktiviert: fetchGisStationsStaticDistrictService");
|
||||
const { mockGisStationsStaticDistrict } = await import("../../__mocks__/webservice/gisStationsStaticDistrict.js");
|
||||
return mockGisStationsStaticDistrict.Points;
|
||||
} else {
|
||||
const baseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx` : `${window.location.origin}${basePath}/ClientData/WebServiceMap.asmx`;
|
||||
|
||||
const url = `${baseUrl}/GisStationsStaticDistrict?idMap=${idMap}&idUser=${idUser}`;
|
||||
console.log("📡 fetchGisStationsStaticDistrictService URL:", url);
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const idMap = params.get("m");
|
||||
const idUser = params.get("u");
|
||||
|
||||
const response = await fetch(url);
|
||||
const url = `${baseUrl}/GisStationsStaticDistrict?idMap=${idMap}&idUser=${idUser}`;
|
||||
console.log("📡 fetchGisStationsStaticDistrictService URL:", url);
|
||||
|
||||
if (!response.ok) {
|
||||
const message = `❌ Fehler: ${response.status} ${response.statusText}`;
|
||||
console.error(message);
|
||||
throw new Error(message);
|
||||
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?.Points) {
|
||||
throw new Error("Antwortstruktur ungültig – 'Points' fehlt");
|
||||
}
|
||||
|
||||
return jsonResponse.Points;
|
||||
}
|
||||
|
||||
const jsonResponse = await response.json();
|
||||
|
||||
if (!jsonResponse?.Points) {
|
||||
throw new Error("Antwortstruktur ungültig – 'Points' fehlt");
|
||||
}
|
||||
|
||||
return jsonResponse.Points;
|
||||
};
|
||||
|
||||
@@ -2,36 +2,44 @@
|
||||
|
||||
/**
|
||||
* Holt Statusinformationen der GIS-Bezirksstationen.
|
||||
* Unterstützt dynamische Umschaltung zwischen echten und Mock-Daten.
|
||||
*
|
||||
* @returns {Promise<Array>} Liste mit Statis[]
|
||||
* @throws {Error} bei Fehler oder ungültiger Antwortstruktur
|
||||
*/
|
||||
export const fetchGisStationsStatusDistrictService = async () => {
|
||||
const useMocks = process.env.NEXT_PUBLIC_USE_MOCKS === "true";
|
||||
const mode = process.env.NEXT_PUBLIC_API_PORT_MODE;
|
||||
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
||||
|
||||
const baseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx` : `${window.location.origin}${basePath}/ClientData/WebServiceMap.asmx`;
|
||||
if (useMocks) {
|
||||
console.log("🧪 Mock-Modus aktiviert: fetchGisStationsStatusDistrictService");
|
||||
const { mockGisStationsStatusDistrict } = await import("../../__mocks__/webservice/gisStationsStatusDistrict.js");
|
||||
return mockGisStationsStatusDistrict.Statis;
|
||||
} else {
|
||||
const baseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx` : `${window.location.origin}${basePath}/ClientData/WebServiceMap.asmx`;
|
||||
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const idMap = params.get("m");
|
||||
const idUser = params.get("u");
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const idMap = params.get("m");
|
||||
const idUser = params.get("u");
|
||||
|
||||
const url = `${baseUrl}/GisStationsStatusDistrict?idMap=${idMap}&idUser=${idUser}`;
|
||||
console.log("📡 fetchGisStationsStatusDistrictService URL:", url);
|
||||
const url = `${baseUrl}/GisStationsStatusDistrict?idMap=${idMap}&idUser=${idUser}`;
|
||||
console.log("📡 fetchGisStationsStatusDistrictService URL:", url);
|
||||
|
||||
const response = await fetch(url);
|
||||
const response = await fetch(url);
|
||||
|
||||
if (!response.ok) {
|
||||
const message = `❌ Fehler: ${response.status} ${response.statusText}`;
|
||||
console.error(message);
|
||||
throw new Error(message);
|
||||
if (!response.ok) {
|
||||
const message = `❌ Fehler: ${response.status} ${response.statusText}`;
|
||||
console.error(message);
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
const jsonResponse = await response.json();
|
||||
|
||||
if (!jsonResponse?.Statis) {
|
||||
throw new Error("Antwortstruktur ungültig – 'Statis' fehlt");
|
||||
}
|
||||
|
||||
return jsonResponse.Statis;
|
||||
}
|
||||
|
||||
const jsonResponse = await response.json();
|
||||
|
||||
if (!jsonResponse?.Statis) {
|
||||
throw new Error("Antwortstruktur ungültig – 'Statis' fehlt");
|
||||
}
|
||||
|
||||
return jsonResponse.Statis;
|
||||
};
|
||||
|
||||
@@ -1,37 +1,43 @@
|
||||
// /services/webservice/fetchGisSystemStaticService.js
|
||||
|
||||
/**
|
||||
* Holt GIS-Systemdaten (Systemübersicht) vom TALAS WebService.
|
||||
* Holt GIS-Systemdaten (Systemübersicht) vom TALAS WebService oder aus Mocks.
|
||||
*
|
||||
* @returns {Promise<Array>} Liste mit Systems[]
|
||||
* @throws {Error} bei Fehler oder ungültiger Antwortstruktur
|
||||
*/
|
||||
export const fetchGisSystemStaticService = async () => {
|
||||
const useMocks = process.env.NEXT_PUBLIC_USE_MOCKS === "true";
|
||||
const mode = process.env.NEXT_PUBLIC_API_PORT_MODE;
|
||||
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
||||
|
||||
const baseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx` : `${window.location.origin}${basePath}/ClientData/WebServiceMap.asmx`;
|
||||
if (useMocks) {
|
||||
console.log("🧪 Mock-Modus aktiviert: fetchGisSystemStaticService");
|
||||
const { mockGisSystemStatic } = await import("../../__mocks__/webservice/gisSystemStatic.js");
|
||||
return mockGisSystemStatic.Systems;
|
||||
} else {
|
||||
const baseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx` : `${window.location.origin}${basePath}/ClientData/WebServiceMap.asmx`;
|
||||
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const idMap = params.get("m");
|
||||
const idUser = params.get("u");
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const idMap = params.get("m");
|
||||
const idUser = params.get("u");
|
||||
|
||||
const url = `${baseUrl}/GisSystemStatic?idMap=${idMap}&idUser=${idUser}`;
|
||||
console.log("📡 fetchGisSystemStaticService von service URL:", url);
|
||||
const url = `${baseUrl}/GisSystemStatic?idMap=${idMap}&idUser=${idUser}`;
|
||||
console.log("📡 fetchGisSystemStaticService von service URL:", url);
|
||||
|
||||
const response = await fetch(url);
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
const message = `❌ Fehler: ${response.status} ${response.statusText}`;
|
||||
console.error(message);
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
const message = `❌ Fehler: ${response.status} ${response.statusText}`;
|
||||
console.error(message);
|
||||
throw new Error(message);
|
||||
const jsonResponse = await response.json();
|
||||
|
||||
if (!Array.isArray(jsonResponse?.Systems)) {
|
||||
throw new Error("Antwortstruktur ungültig – 'Systems' fehlt oder ist kein Array");
|
||||
}
|
||||
|
||||
return jsonResponse.Systems;
|
||||
}
|
||||
|
||||
const jsonResponse = await response.json();
|
||||
|
||||
if (!jsonResponse?.Systems) {
|
||||
throw new Error("Antwortstruktur ungültig – 'Systems' fehlt");
|
||||
}
|
||||
|
||||
return jsonResponse.Systems;
|
||||
};
|
||||
|
||||
@@ -1,28 +1,44 @@
|
||||
// /services/webservice/fetchUserRightsService.js
|
||||
|
||||
/**
|
||||
* Holt Benutzerrechte aus TALAS-Webservice oder aus Mocks.
|
||||
*
|
||||
* @returns {Promise<Array>} Rechte-Array
|
||||
* @throws {Error} bei Lade- oder Strukturfehler
|
||||
*/
|
||||
export const fetchUserRightsService = async () => {
|
||||
const useMocks = process.env.NEXT_PUBLIC_USE_MOCKS === "true";
|
||||
const mode = process.env.NEXT_PUBLIC_API_PORT_MODE;
|
||||
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
||||
const baseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx` : `${window.location.origin}${basePath}/ClientData/WebServiceMap.asmx`;
|
||||
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const idMap = params.get("m");
|
||||
const idUser = params.get("u");
|
||||
if (useMocks) {
|
||||
console.log("🧪 Mock-Modus aktiviert: fetchUserRightsService");
|
||||
const { mockUserRights } = await import("../../__mocks__/webservice/userRights.js");
|
||||
return mockUserRights.Rights || [];
|
||||
} else {
|
||||
const baseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx` : `${window.location.origin}${basePath}/ClientData/WebServiceMap.asmx`;
|
||||
|
||||
const url = `${baseUrl}/GisSystemStatic?idMap=${idMap}&idUser=${idUser}`;
|
||||
console.log("🔍 Rechte-Fetch URL:", url);
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const idMap = params.get("m");
|
||||
const idUser = params.get("u");
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Connection: "close",
|
||||
},
|
||||
});
|
||||
const url = `${baseUrl}/GisSystemStatic?idMap=${idMap}&idUser=${idUser}`;
|
||||
console.log("🔍 Rechte-Fetch URL:", url);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Fehler beim Abrufen der Benutzerrechte");
|
||||
const response = await fetch(url, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Connection: "close",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Fehler beim Abrufen der Benutzerrechte");
|
||||
}
|
||||
|
||||
const json = await response.json();
|
||||
console.log("👤 Rechte-Response JSON:", json);
|
||||
|
||||
return json.Rights || [];
|
||||
}
|
||||
|
||||
const json = await response.json();
|
||||
console.log("👤 Rechte-Response JSON:", json);
|
||||
return json.Rights || [];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user