refactor: Services nach Datenquelle getrennt – webservice/, database/ und utils/ Struktur eingeführt (v1.1.117)
This commit is contained in:
30
services/webservice/fetchGisStationsMeasurementsService.js
Normal file
30
services/webservice/fetchGisStationsMeasurementsService.js
Normal file
@@ -0,0 +1,30 @@
|
||||
// /services/api/fetchGisStationsMeasurementsService.js
|
||||
|
||||
export const fetchGisStationsMeasurementsService = 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}/GisStationsMeasurements?idMap=${idMap}&idUser=${idUser}`;
|
||||
console.log("📡 fetchGisStationsMeasurementsService 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?.Statis) {
|
||||
throw new Error("Antwortstruktur ungültig – 'Statis' fehlt");
|
||||
}
|
||||
|
||||
return jsonResponse.Statis;
|
||||
};
|
||||
36
services/webservice/fetchGisStationsStaticDistrictService.js
Normal file
36
services/webservice/fetchGisStationsStaticDistrictService.js
Normal file
@@ -0,0 +1,36 @@
|
||||
// /services/api/fetchGisStationsStaticDistrictService.js
|
||||
|
||||
/**
|
||||
* Holt statische GIS-Stationen-Daten für Bezirke.
|
||||
*
|
||||
* @returns {Promise<Array>} Liste mit Points[]
|
||||
* @throws {Error} bei Fehler oder ungültiger Antwortstruktur
|
||||
*/
|
||||
export const fetchGisStationsStaticDistrictService = 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}/GisStationsStaticDistrict?idMap=${idMap}&idUser=${idUser}`;
|
||||
console.log("📡 fetchGisStationsStaticDistrictService 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?.Points) {
|
||||
throw new Error("Antwortstruktur ungültig – 'Points' fehlt");
|
||||
}
|
||||
|
||||
return jsonResponse.Points;
|
||||
};
|
||||
36
services/webservice/fetchGisStationsStatusDistrictService.js
Normal file
36
services/webservice/fetchGisStationsStatusDistrictService.js
Normal file
@@ -0,0 +1,36 @@
|
||||
// /services/api/fetchGisStationsStatusDistrictService.js
|
||||
|
||||
/**
|
||||
* Holt Statusinformationen der GIS-Bezirksstationen.
|
||||
*
|
||||
* @returns {Promise<Array>} Liste mit Statis[]
|
||||
* @throws {Error} bei Fehler oder ungültiger Antwortstruktur
|
||||
*/
|
||||
export const fetchGisStationsStatusDistrictService = 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}/GisStationsStatusDistrict?idMap=${idMap}&idUser=${idUser}`;
|
||||
console.log("📡 fetchGisStationsStatusDistrictService 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?.Statis) {
|
||||
throw new Error("Antwortstruktur ungültig – 'Statis' fehlt");
|
||||
}
|
||||
|
||||
return jsonResponse.Statis;
|
||||
};
|
||||
27
services/webservice/fetchGisStatusStations.js
Normal file
27
services/webservice/fetchGisStatusStations.js
Normal file
@@ -0,0 +1,27 @@
|
||||
// /services/api/fetchGisStatusStations.js
|
||||
import fetchWithTimeout from "../utils/fetchWithTimeout";
|
||||
|
||||
export const fetchGisStatusStations = async (idMap, idUser) => {
|
||||
const mode = process.env.NEXT_PUBLIC_API_PORT_MODE;
|
||||
|
||||
const SERVER_URL = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80` : `${window.location.origin}`;
|
||||
|
||||
return fetchWithTimeout(
|
||||
`${SERVER_URL}/talas5/ClientData/WebServiceMap.asmx/GisStationsStatusDistrict?idMap=${idMap}&idUser=${idUser}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
Connection: "close",
|
||||
},
|
||||
},
|
||||
5000
|
||||
)
|
||||
.then((response) => {
|
||||
if (!response.ok) throw new Error(`Error: ${response.statusText}`);
|
||||
return response.json();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Fehler beim Abrufen der Daten in fetchGisStatusStations:", error);
|
||||
throw error;
|
||||
});
|
||||
};
|
||||
18
services/webservice/fetchGisSystemStatic.js
Normal file
18
services/webservice/fetchGisSystemStatic.js
Normal file
@@ -0,0 +1,18 @@
|
||||
// /services/api/fetchGisSystemStatic.js
|
||||
|
||||
export const fetchGisSystemStatic = 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([]);
|
||||
}
|
||||
};
|
||||
26
services/webservice/fetchUserRights.js
Normal file
26
services/webservice/fetchUserRights.js
Normal file
@@ -0,0 +1,26 @@
|
||||
// /services/api/fetchUserRights.js
|
||||
import * as config from "../../config/config";
|
||||
|
||||
export const fetchUserRights = async () => {
|
||||
if (config.USE_MOCK_API) {
|
||||
console.log("⚠️ Mock-API: Benutzerrechte geladen");
|
||||
return [56, 57, 58]; // Beispielrechte
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${config.serverURL}/talas5/ClientData/WebserviceMap.asmx/GisSystemStatic?idMap=${config.idMap}&idUser=${config.idUser}`, {
|
||||
method: "GET",
|
||||
headers: { Connection: "close" },
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
||||
|
||||
const data = await response.json();
|
||||
if (!data || !data.Rights || !Array.isArray(data.Rights)) throw new Error("Invalid response structure");
|
||||
|
||||
return data.Rights.map((right) => right.IdRight);
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Abrufen der Benutzerrechte:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user