summaryrefslogtreecommitdiff
path: root/backend/src/controllers/stopRobot.ts
diff options
context:
space:
mode:
Diffstat (limited to 'backend/src/controllers/stopRobot.ts')
-rw-r--r--backend/src/controllers/stopRobot.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/backend/src/controllers/stopRobot.ts b/backend/src/controllers/stopRobot.ts
new file mode 100644
index 0000000..d0d7c4f
--- /dev/null
+++ b/backend/src/controllers/stopRobot.ts
@@ -0,0 +1,27 @@
+import { Request, Response } from "express";
+import { setRobotIdle } from "../simulation/robotMovementSimulator";
+import { ErrorResponse } from "../types/error";
+import { SimulationResponse } from "../types/robot";
+
+async function stopRobot(req: Request, res: Response) {
+ const robotId = Number(req.params.id);
+
+ if (!robotId || Number.isNaN(robotId)) {
+ return res.status(400).json({ message: "Ungültige Roboter ID." });
+ }
+
+ try {
+ const result: SimulationResponse = await setRobotIdle(robotId);
+ return res.status(200).json(result);
+ } catch (error) {
+ console.error(`Error on trying to stop robot ID ${robotId}: `, error);
+
+ const errorResponse: ErrorResponse = {
+ message: `Internal server error on trying to stop robot ID ${robotId}.`,
+ error,
+ };
+ return res.status(500).json(errorResponse);
+ }
+}
+
+export default stopRobot;