diff options
| author | Arne Rief <riearn@proton.me> | 2025-12-22 21:20:39 +0100 |
|---|---|---|
| committer | Arne Rief <riearn@proton.me> | 2025-12-22 21:20:39 +0100 |
| commit | e836e7dd4ed5e9fa60e949d159100040b22a8f48 (patch) | |
| tree | a11954c06e55e8ef53fcb634fa5954dfcb42ffc3 /backend/src/controllers/moveRobot.ts | |
| parent | d1b64ddd78d8b8dc3eca76038a75071ab2a575d9 (diff) | |
Movement simulator for all and single robot, project v1 ready
Diffstat (limited to 'backend/src/controllers/moveRobot.ts')
| -rw-r--r-- | backend/src/controllers/moveRobot.ts | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/backend/src/controllers/moveRobot.ts b/backend/src/controllers/moveRobot.ts new file mode 100644 index 0000000..1b53f17 --- /dev/null +++ b/backend/src/controllers/moveRobot.ts @@ -0,0 +1,30 @@ +import { Request, Response } from "express"; +import { Server } from "socket.io"; +import { setRobotMoving } from "../simulation/robotMovementSimulator"; +import { ErrorResponse } from "../types/error"; +import { SimulationResponse } from "../types/robot"; + +async function moveRobot(req: Request, res: Response) { + const io: Server = req.app.get("io"); + + const robotId = Number(req.params.id); + + if (!robotId || Number.isNaN(robotId)) { + return res.status(400).json({ message: "Invalid robot ID." }); + } + + try { + const result: SimulationResponse = await setRobotMoving(io, robotId); + return res.status(200).json(result); + } catch (error) { + console.error(`Error on trying to start robot ID ${robotId}: `, error); + + const errorResponse: ErrorResponse = { + message: `Internal server error on trying to start robot ID ${robotId}.`, + error, + }; + return res.status(500).json(errorResponse); + } +} + +export default moveRobot; |
