Skip to content

Commit

Permalink
Standardise updating robot telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
andchiind committed Sep 2, 2024
1 parent d0271df commit f18f7e2
Showing 1 changed file with 2 additions and 24 deletions.
26 changes: 2 additions & 24 deletions backend/api/Services/RobotService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,37 +158,15 @@ public async Task<Robot> UpdateRobotStatus(string robotId, RobotStatus status)

public async Task<Robot> UpdateRobotBatteryLevel(string robotId, float batteryLevel)
{
var robotQuery = context.Robots.Where(robot => robot.Id == robotId).Include(robot => robot.CurrentInstallation).AsTracking();
var robot = await robotQuery.FirstOrDefaultAsync();
var robot = await UpdateRobotProperty(robotId, "BatteryLevel", batteryLevel);
ThrowIfRobotIsNull(robot, robotId);

await VerifyThatUserIsAuthorizedToUpdateDataForInstallation(robot!.CurrentInstallation);

await robotQuery.ExecuteUpdateAsync(robots => robots.SetProperty(r => r.BatteryLevel, batteryLevel));

robot = await robotQuery.FirstOrDefaultAsync();
ThrowIfRobotIsNull(robot, robotId);
NotifySignalROfUpdatedRobot(robot!, robot!.CurrentInstallation!);
DetachTracking(robot);

return robot;
}

public async Task<Robot> UpdateRobotPressureLevel(string robotId, float? pressureLevel)
{
var robotQuery = context.Robots.Where(robot => robot.Id == robotId).Include(robot => robot.CurrentInstallation);
var robot = await robotQuery.FirstOrDefaultAsync();
ThrowIfRobotIsNull(robot, robotId);

await VerifyThatUserIsAuthorizedToUpdateDataForInstallation(robot!.CurrentInstallation);

await robotQuery.ExecuteUpdateAsync(robots => robots.SetProperty(r => r.PressureLevel, pressureLevel));

robot = await robotQuery.FirstOrDefaultAsync();
var robot = await UpdateRobotProperty(robotId, "PressureLevel", pressureLevel);
ThrowIfRobotIsNull(robot, robotId);
NotifySignalROfUpdatedRobot(robot!, robot!.CurrentInstallation!);
DetachTracking(robot);

return robot;
}

Expand Down

0 comments on commit f18f7e2

Please sign in to comment.