From e836e7dd4ed5e9fa60e949d159100040b22a8f48 Mon Sep 17 00:00:00 2001 From: Arne Rief Date: Mon, 22 Dec 2025 21:20:39 +0100 Subject: Movement simulator for all and single robot, project v1 ready --- backend/src/controllers/getRobots.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'backend/src/controllers/getRobots.ts') diff --git a/backend/src/controllers/getRobots.ts b/backend/src/controllers/getRobots.ts index b634306..80b430f 100644 --- a/backend/src/controllers/getRobots.ts +++ b/backend/src/controllers/getRobots.ts @@ -17,9 +17,14 @@ async function getRobots(_req: Request, res: Response) { console.log("Data served from Redis cache."); const robots: Robot[] = JSON.parse(cachedData); + const simulationRunning = robots?.every( + (robot) => robot.status === "moving" + ); + const response: RobotsResponse = { source: "cache", - data: robots, + robots, + simulationRunning, }; return res.status(200).json(response); @@ -31,6 +36,10 @@ async function getRobots(_req: Request, res: Response) { ); const robots = robotsQuery.rows; + const simulationRunning = robots?.every( + (robot) => robot.status === "moving" + ); + await redisClient.set(ROBOTS_CACHE_KEY, JSON.stringify(robots), { EX: CACHE_TTL, }); @@ -38,7 +47,8 @@ async function getRobots(_req: Request, res: Response) { console.log("Cache miss: data queried from PostgreSQL."); const response: RobotsResponse = { source: "database", - data: robots, + robots, + simulationRunning, }; return res.status(200).json(response); -- cgit v1.2.3