refactor: API-Dateien konsequent auf *APIHandler.ts umbenannt und MockData-Handling optimiert

- Einheitliches Naming für API-Routen: *APIHandler.ts
- Mock-Daten aus /apiMockData/SERVICE/ werden über API bereitgestellt
- API-Endpoints sofort erkennbar und verständlich
- Projektstruktur deutlich klarer und wartungsfreundlicher
This commit is contained in:
Ismail Ali
2025-04-15 08:35:44 +02:00
parent 9e931eed0f
commit fb87e7b3ae
20 changed files with 95 additions and 58 deletions

View File

@@ -1,3 +1,4 @@
// /apiMockData/SERVICE/SystemMockData.js
var win_appVersion = "0.02"; var win_appVersion = "0.02";
var win_deviceName = "CPLV4_Maschen"; var win_deviceName = "CPLV4_Maschen";
var win_mac1 = "0 48 86 81 46 143"; var win_mac1 = "0 48 86 81 46 143";

View File

@@ -1,4 +1,4 @@
// public/CPLmockData/SERVICE/ae.js // /apiMockData/SERVICE/analogeEingaengeMockData.js
var win_analogeEingaenge1 = [1, 0, "Sensor2", 1, 1, 0, 1]; // Eingang 1 var win_analogeEingaenge1 = [1, 0, "Sensor2", 1, 1, 0, 1]; // Eingang 1
var win_analogeEingaenge2 = [2, 22.91, "Feuchtigkeit", 1, 1, 1, 0]; // Eingang 2 var win_analogeEingaenge2 = [2, 22.91, "Feuchtigkeit", 1, 1, 1, 0]; // Eingang 2
var win_analogeEingaenge3 = [3, 0, "Test", 1, 1, 0, 1]; // Eingang 3 var win_analogeEingaenge3 = [3, 0, "Test", 1, 1, 0, 1]; // Eingang 3

View File

@@ -1,3 +1,3 @@
// public/CPLmockData/SERVICE/da.js // /apiMockData/SERVICE/digitaleAusgaengeMockData.js
win_da_state = [1, 0, 1, 0]; win_da_state = [1, 0, 1, 0];
win_da_bezeichnung = ["Ausgang1", "Ausgang2", "Ausgang3", "Ausgang4"]; win_da_bezeichnung = ["Ausgang1", "Ausgang2", "Ausgang3", "Ausgang4"];

View File

@@ -1,4 +1,4 @@
// apiMockData/SERVICE/de.js // apiMockData/SERVICE/digitaleEingaengeMockData.js
// Zustand -> DESxx xx =Nr Eingang 1-32 80-83 = BGT 1 bis 4 // Zustand -> DESxx xx =Nr Eingang 1-32 80-83 = BGT 1 bis 4
var win_de_state = [ var win_de_state = [

View File

@@ -1,4 +1,4 @@
// /public/CPLmockData/SERVICE/kueData.js // /apiMockData/SERVICE/kabelueberwachungMockData.js
//Modul vorhanden 1 = vorhanden, 0 = nicht vorhanden //Modul vorhanden 1 = vorhanden, 0 = nicht vorhanden
var win_kueOnline = [ var win_kueOnline = [
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,

View File

@@ -1,4 +1,4 @@
// /apiMockData/SERVICE/last20Messages.js // /apiMockData/SERVICE/last20MessagesMockData.js
var win_last20Messages = ` var win_last20Messages = `
<tr><td>16750</td><td>03501</td><td>2024-10-23 15:08:58:000</td><td>Modul 26 Isofehler kommend</td><td>1</td></tr> <tr><td>16750</td><td>03501</td><td>2024-10-23 15:08:58:000</td><td>Modul 26 Isofehler kommend</td><td>1</td></tr>
<tr><td>16749</td><td>03201</td><td>2024-10-23 15:07:24:000</td><td>Modul 23 Isofehler gehend</td><td>0</td></tr> <tr><td>16749</td><td>03201</td><td>2024-10-23 15:07:24:000</td><td>Modul 23 Isofehler gehend</td><td>0</td></tr>

View File

@@ -1,4 +1,4 @@
// public/CPL/SERVICE/opcua.js // /apiMockData/SERVICE/opcuaMockData.js
//-------OPCUA Information Lesen---------------- //-------OPCUA Information Lesen----------------
var win_opcUaZustand = "1"; var win_opcUaZustand = "1";
var win_opcUaActiveClientCount = "0"; var win_opcUaActiveClientCount = "0";

View File

@@ -6,5 +6,5 @@
2: Patch oder Hotfix (Bugfixes oder kleine Änderungen). 2: Patch oder Hotfix (Bugfixes oder kleine Änderungen).
*/ */
const webVersion = "1.6.221"; const webVersion = "1.6.222";
export default webVersion; export default webVersion;

View File

@@ -0,0 +1,26 @@
// /pages/api/cpl/analogeEingaengeAPIHandler.ts
import { NextApiRequest, NextApiResponse } from "next";
import path from "path";
import fs from "fs/promises";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const filePath = path.join(
process.cwd(),
"apiMockData",
"SERVICE",
"analogeEingaengeMockData.js"
);
try {
const data = await fs.readFile(filePath, "utf-8");
res.setHeader("Content-Type", "text/javascript");
res.status(200).send(data);
} catch (error) {
res.status(404).json({ error: "File not found" });
}
}

View File

@@ -1,19 +0,0 @@
// /pages/api/cpl/digitalOutputs.ts
import { NextApiRequest, NextApiResponse } from "next";
import path from "path";
import fs from "fs/promises";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const filePath = path.join(process.cwd(), "apiMockData", "SERVICE", "da.js");
try {
const data = await fs.readFile(filePath, "utf-8");
res.status(200).send(data);
} catch (error) {
res.status(404).json({ error: "File not found" });
}
}

View File

@@ -1,4 +1,4 @@
// /pages/api/cpl/kueData.ts // /pages/api/cpl/digitalOutputsAPIHandler.ts
import { NextApiRequest, NextApiResponse } from "next"; import { NextApiRequest, NextApiResponse } from "next";
import path from "path"; import path from "path";
@@ -12,7 +12,7 @@ export default async function handler(
process.cwd(), process.cwd(),
"apiMockData", "apiMockData",
"SERVICE", "SERVICE",
"kueData.js" "digitaleAusgaengeMockData.js"
); );
try { try {

View File

@@ -1,21 +0,0 @@
// /pages/api/cpl/digitaleEingaenge.ts
import { NextApiRequest, NextApiResponse } from "next";
import path from "path";
import fs from "fs/promises";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const filePath = path.join(process.cwd(), "apiMockData", "SERVICE", "de.js");
try {
const data = await fs.readFile(filePath, "utf-8");
res.setHeader("Content-Type", "text/javascript"); // wichtig!
res.status(200).send(data);
} catch (error) {
res.status(404).json({ error: "File not found" });
}
}

View File

@@ -0,0 +1,26 @@
// /pages/api/cpl/digitaleEingaengeAPIHandler.ts
import { NextApiRequest, NextApiResponse } from "next";
import path from "path";
import fs from "fs/promises";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const filePath = path.join(
process.cwd(),
"apiMockData",
"SERVICE",
"digitaleEingaengeMockData.js"
);
try {
const data = await fs.readFile(filePath, "utf-8");
res.setHeader("Content-Type", "text/javascript"); // wichtig!
res.status(200).send(data);
} catch (error) {
res.status(404).json({ error: "File not found" });
}
}

View File

@@ -0,0 +1,24 @@
// /pages/api/cpl/kabelueberwachungAPIHandler.ts
import { NextApiRequest, NextApiResponse } from "next";
import path from "path";
import fs from "fs/promises";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const filePath = path.join(
process.cwd(),
"apiMockData",
"SERVICE",
"kabelueberwachungMockData.js"
);
try {
const data = await fs.readFile(filePath, "utf-8");
res.status(200).send(data);
} catch (error) {
res.status(404).json({ error: "File not found" });
}
}

View File

@@ -1,4 +1,4 @@
// /pages/api/cpl/last20Messages.ts // /pages/api/cpl/last20MessagesAPIHandler.ts
import { NextApiRequest, NextApiResponse } from "next"; import { NextApiRequest, NextApiResponse } from "next";
import path from "path"; import path from "path";
import fs from "fs/promises"; import fs from "fs/promises";
@@ -11,7 +11,7 @@ export default async function handler(
process.cwd(), process.cwd(),
"apiMockData", "apiMockData",
"SERVICE", "SERVICE",
"last20Messages.js" "last20MessagesMockData.js"
); );
try { try {

View File

@@ -1,4 +1,4 @@
// /pages/api/cpl/systemSettings.ts // /pages/api/cpl/opcuaSettingsAPIHandler.ts
import { NextApiRequest, NextApiResponse } from "next"; import { NextApiRequest, NextApiResponse } from "next";
import path from "path"; import path from "path";
@@ -12,7 +12,7 @@ export default async function handler(
process.cwd(), process.cwd(),
"apiMockData", "apiMockData",
"SERVICE", "SERVICE",
"system.js" "opcuaMockData.js"
); );
try { try {

View File

@@ -1,4 +1,4 @@
// /pages/api/cpl/slotData.ts // /pages/api/cpl/slotDataAPIHandler.ts
import { NextApiRequest, NextApiResponse } from "next"; import { NextApiRequest, NextApiResponse } from "next";
import path from "path"; import path from "path";
import fs from "fs/promises"; import fs from "fs/promises";

View File

@@ -1,4 +1,4 @@
// /pages/api/cpl/opcuaSettings.ts // /pages/api/cpl/systemSettingsAPIHandler.ts
import { NextApiRequest, NextApiResponse } from "next"; import { NextApiRequest, NextApiResponse } from "next";
import path from "path"; import path from "path";
@@ -12,7 +12,7 @@ export default async function handler(
process.cwd(), process.cwd(),
"apiMockData", "apiMockData",
"SERVICE", "SERVICE",
"opcua.js" "systemMockData.js"
); );
try { try {

View File

@@ -1,4 +1,4 @@
// /pages/api/cpl/tdmData.ts // /pages/api/cpl/tdmDataAPIHandler.ts
import { NextApiRequest, NextApiResponse } from "next"; import { NextApiRequest, NextApiResponse } from "next";
import path from "path"; import path from "path";

View File

@@ -1,4 +1,4 @@
// /pages/api/cpl/tdrData.ts // /pages/api/cpl/tdrDataAPIHandler.ts
import { NextApiRequest, NextApiResponse } from "next"; import { NextApiRequest, NextApiResponse } from "next";
import path from "path"; import path from "path";