Files
nodeMap/docs/frontend/redux/api/fromDB/fetchLocationDevices.md

1.5 KiB
Raw Blame History

🌐 fetchLocationDevices

Diese Funktion lädt alle Geräte für einen bestimmten Standort aus der Datenbank via API-Endpunkt.


📍 Pfad

/redux/api/fromDB/fetchLocationDevices.js

📥 Funktion

export const fetchLocationDevices = async () => {
  const response = await fetch("/api/talas_v5_DB/locationDevice/locationDevices");
  if (!response.ok) {
    throw new Error("Geräteliste konnte nicht geladen werden");
  }
  return await response.json();
};

📡 API-Endpunkt

GET /api/talas_v5_DB/locationDevice/locationDevices

Dieser Endpunkt liefert eine JSON-Liste aller Geräte eines Standorts (z.B. für Map-Rendering, POI-Anzeige, Standortübersicht etc.).


🧪 Fehlerbehandlung

Falls der Request fehlschlägt (z.B. Statuscode ≠ 2xx), wird folgender Fehler ausgelöst:

"Geräteliste konnte nicht geladen werden"

Dies kann im Redux-Slice über den .rejected-Case ausgewertet werden.


🧩 Verwendung

import { fetchLocationDevices } from "@/redux/api/fromDB/fetchLocationDevices";

const result = await fetchLocationDevices();
console.log(result); // Erwartet: Array von Geräteobjekten

Diese Funktion wird typischerweise im Redux-Thunk fetchLocationDevicesFromDB verwendet:

const data = await fetchLocationDevices();

🔄 Zusammenhang