refactor: Move API-Endpoint-Functions to /api/talas_v5_DB/ folder for better organization

This commit is contained in:
ISA
2024-06-14 14:06:32 +02:00
parent c8ac4ebdb7
commit d220d0baae
18 changed files with 117 additions and 96 deletions

View File

@@ -1,4 +1,5 @@
import mysql from 'mysql';
// /pages/api/talas_v5_DB/gisLines/readGisLines.js
import mysql from "mysql";
const dbConfig = {
host: process.env.DB_HOST,
@@ -11,26 +12,28 @@ const dbConfig = {
const connection = mysql.createConnection(dbConfig);
connection.connect((err) => {
if (err) {
console.error('Fehler beim Verbinden:', err.stack);
console.error("Fehler beim Verbinden:", err.stack);
return;
}
console.log('Database connected successfully.');
console.log("Database connected successfully.");
});
export default function handler(req, res) {
if (req.method !== 'GET') {
return res.status(405).json({ error: 'Nur GET Methode erlaubt' });
if (req.method !== "GET") {
return res.status(405).json({ error: "Nur GET Methode erlaubt" });
}
const query = 'SELECT * FROM talas_v5.gis_lines;';
const query = "SELECT * FROM talas_v5.gis_lines;";
connection.query(query, (error, results) => {
if (error) {
console.error('Fehler beim Abrufen der gis_lines:', error);
return res.status(500).json({ error: 'Fehler beim Abrufen der gis_lines' });
console.error("Fehler beim Abrufen der gis_lines:", error);
return res
.status(500)
.json({ error: "Fehler beim Abrufen der gis_lines" });
}
if (results.length > 0) {
res.json(results);
} else {
res.status(404).json({ error: 'Gerät nicht gefunden' });
res.status(404).json({ error: "Gerät nicht gefunden" });
}
});
}

View File

@@ -1,4 +1,4 @@
// API in /api/getDeviceId.js
// API in /api/talas_v5_DB/locationDevice/getDeviceId.js
import mysql from "mysql";
const dbConfig = {

View File

@@ -1,7 +1,6 @@
// API in /api/locationDeviceNameById.js
// API in /api/talas_v5_DB/locationDevice/locationDeviceNameById.js
import mysql from "mysql";
const dbConfig = {
host: process.env.DB_HOST,
user: process.env.DB_USER,
@@ -28,7 +27,9 @@ export default function handler(req, res) {
connection.query(query, [idLD], (error, results) => {
if (error) {
console.error("Fehler beim Abrufen des Gerätenamens:", error);
return res.status(500).json({ error: "Fehler beim Abrufen des Gerätenamens" });
return res
.status(500)
.json({ error: "Fehler beim Abrufen des Gerätenamens" });
}
if (results.length > 0) {
res.json({ name: results[0].name });

View File

@@ -1,5 +1,5 @@
// API in /api/locationDevices.js
import mysql from 'mysql';
// API in /api/talas_v5_DB/locationDevice/locationDevices.js
import mysql from "mysql";
const dbConfig = {
host: process.env.DB_HOST,
@@ -26,7 +26,9 @@ export default function handler(req, res) {
connection.query(query, (error, results) => {
if (error) {
console.error("Fehler beim Abrufen der Geräteinformationen:", error);
return res.status(500).json({ error: "Fehler beim Abrufen der Geräteinformationen" });
return res
.status(500)
.json({ error: "Fehler beim Abrufen der Geräteinformationen" });
}
res.json(results);
});

View File

@@ -1,4 +1,4 @@
// pages/api/readPoiTyp.js
// pages/api/talas_v5_DB/poiTyp/readPoiTyp.js
import mysql from "mysql";
const pool = mysql.createPool({

View File

@@ -1,4 +1,4 @@
// pages/api/addLocation.js
// pages/api/talas_v5_DB/pois/addLocation.js
import mysql from "mysql";
const dbConfig = {
@@ -26,12 +26,10 @@ export default function handler(req, res) {
console.error("Fehler beim Einfügen des Standorts:", error);
return res.status(500).json({ error: "Ein Fehler ist aufgetreten" });
}
res
.status(200)
.json({
id: results.insertId,
message: "Standort erfolgreich hinzugefügt",
});
res.status(200).json({
id: results.insertId,
message: "Standort erfolgreich hinzugefügt",
});
});
} else {
res.setHeader("Allow", ["POST"]);

View File

@@ -1,4 +1,4 @@
// pages/api/deletePoi.js
// pages/api/talas_v5_DB/pois/deletePoi.js
import mysql from "mysql";
// Datenbankkonfiguration

View File

@@ -1,4 +1,4 @@
// pages/api/getPoiById.js
// pages/api/talas_v5_DB/pois/getPoiById.js
import mysql from "mysql";
const dbConfig = {

View File

@@ -1,4 +1,4 @@
// pages/api/poi-icons.js
// pages/api/talas_v5_DB/pois/poi-icons.js
import mysql from "mysql";
const dbConfig = {

View File

@@ -1,4 +1,4 @@
// pages/api/readLocations.js
// pages/api/talas_v5_DB/pois/readLocations.js
import mysql from "mysql";
const dbConfig = {

View File

@@ -1,4 +1,4 @@
// pages/api/updateLocation.js
// pages/api/talas_v5_DB/pois/updateLocation.js
import mysql from "mysql";
import util from "util";

View File

@@ -1,4 +1,4 @@
// pages/api/updatePoi.js
// pages/api/talas_v5_DB/pois/updatePoi.js
import mysql from "mysql";
const dbConfig = {

View File

@@ -18,7 +18,7 @@ export default function Home() {
const loadData = async () => {
try {
const response = await fetch("/api/readLocations");
const response = await fetch("/api/talas_v5_DB/pois/readLocations");
if (!response.ok) {
throw new Error("Fehler beim Laden der Standortdaten");
}
@@ -47,7 +47,7 @@ export default function Home() {
const handleAddLocation = async (name, type, lat, lng) => {
try {
const response = await fetch("/api/addLocation", {
const response = await fetch("/api/talas_v5_DB/pois/addLocation", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name, type, latitude: lat, longitude: lng }),