Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
oysand committed Dec 21, 2023
1 parent df5cf11 commit 22c5609
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
1 change: 0 additions & 1 deletion backend/api/Controllers/MissionRunController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,3 @@ public async Task<ActionResult<MissionRunResponse>> DeleteMissionRun([FromRoute]
}
}
}

6 changes: 5 additions & 1 deletion backend/api/Services/MissionRunService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,14 @@ public async Task<MissionRun> Update(MissionRun missionRun)
{
context.Entry(missionRun.Robot).State = EntityState.Unchanged;
if (missionRun.Area is not null) { context.Entry(missionRun.Area).State = EntityState.Unchanged; }

logger.LogError("Mission run robot status: '{status}'", missionRun.Robot.Status);
var entry = context.Update(missionRun);
await ApplyDatabaseUpdate(missionRun.Area?.Installation);
_ = signalRService.SendMessageAsync("Mission run updated", missionRun?.Area?.Installation, missionRun != null ? new MissionRunResponse(missionRun) : null);

var robot = await context.Robots.Where(r => r.Id == missionRun.Robot.Id).FirstOrDefaultAsync();

Check warning on line 156 in backend/api/Services/MissionRunService.cs

View workflow job for this annotation

GitHub Actions / build_backend

Dereference of a possibly null reference.

Check warning on line 156 in backend/api/Services/MissionRunService.cs

View workflow job for this annotation

GitHub Actions / build_backend

Dereference of a possibly null reference.

Check failure on line 156 in backend/api/Services/MissionRunService.cs

View workflow job for this annotation

GitHub Actions / test_backend

Dereference of a possibly null reference.

Check failure on line 156 in backend/api/Services/MissionRunService.cs

View workflow job for this annotation

GitHub Actions / test_backend

Dereference of a possibly null reference.

logger.LogError("The robot status after saving the mission run save was: '{status}'", robot.Status);

Check warning on line 158 in backend/api/Services/MissionRunService.cs

View workflow job for this annotation

GitHub Actions / build_backend

Dereference of a possibly null reference.

Check warning on line 158 in backend/api/Services/MissionRunService.cs

View workflow job for this annotation

GitHub Actions / build_backend

Dereference of a possibly null reference.

Check failure on line 158 in backend/api/Services/MissionRunService.cs

View workflow job for this annotation

GitHub Actions / test_backend

Dereference of a possibly null reference.

Check failure on line 158 in backend/api/Services/MissionRunService.cs

View workflow job for this annotation

GitHub Actions / test_backend

Dereference of a possibly null reference.
return entry.Entity;
}

Expand Down
22 changes: 19 additions & 3 deletions backend/api/Services/RobotService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,18 @@ public async Task<Robot> CreateFromQuery(CreateRobotQuery robotQuery)

public async Task<Robot> UpdateRobotStatus(string robotId, RobotStatus status)
{
logger.LogInformation("Updating robot {robotId} status to {status}", robotId, status);
return await UpdateRobotProperty(robotId, "Status", status);
var robot = await ReadById(robotId);
if (robot == null) { logger.LogError("Shit..."); return null; }

Check warning on line 102 in backend/api/Services/RobotService.cs

View workflow job for this annotation

GitHub Actions / build_backend

Possible null reference return.

Check warning on line 102 in backend/api/Services/RobotService.cs

View workflow job for this annotation

GitHub Actions / build_backend

Possible null reference return.

Check failure on line 102 in backend/api/Services/RobotService.cs

View workflow job for this annotation

GitHub Actions / test_backend

Possible null reference return.

Check failure on line 102 in backend/api/Services/RobotService.cs

View workflow job for this annotation

GitHub Actions / test_backend

Possible null reference return.


logger.LogError("Updating robot {robotId} status from {oldStatus} to {newStatus}", robotId, robot.Status, status);
var updatedRobot = await UpdateRobotProperty(robotId, "Status", status);
logger.LogError("This was the new robot status: '{status}'", updatedRobot.Status);
var doubleCheckRobot = await ReadById(robotId);
if (doubleCheckRobot == null) { logger.LogError("Shit..."); return null; }

Check warning on line 109 in backend/api/Services/RobotService.cs

View workflow job for this annotation

GitHub Actions / build_backend

Possible null reference return.

Check warning on line 109 in backend/api/Services/RobotService.cs

View workflow job for this annotation

GitHub Actions / build_backend

Possible null reference return.

Check failure on line 109 in backend/api/Services/RobotService.cs

View workflow job for this annotation

GitHub Actions / test_backend

Possible null reference return.

Check failure on line 109 in backend/api/Services/RobotService.cs

View workflow job for this annotation

GitHub Actions / test_backend

Possible null reference return.

logger.LogError("This was found in the database: '{status}'", doubleCheckRobot.Status);
return updatedRobot;
}
public async Task<Robot> UpdateRobotBatteryLevel(string robotId, float batteryLevel) { return await UpdateRobotProperty(robotId, "BatteryLevel", batteryLevel); }
public async Task<Robot> UpdateRobotPressureLevel(string robotId, float? pressureLevel) { return await UpdateRobotProperty(robotId, "PressureLevel", pressureLevel); }
Expand Down Expand Up @@ -179,7 +189,13 @@ private async Task<Robot> UpdateRobotProperty(string robotId, string propertyNam
{
if (property.Name == propertyName)
{
logger.LogInformation("Setting {robotName} field {propertyName} from {oldValue} to {NewValue}", robot.Name, propertyName, property.GetValue(robot), value);
if (propertyName == "Status")
{
if (value.ToString() == "Available")

Check warning on line 194 in backend/api/Services/RobotService.cs

View workflow job for this annotation

GitHub Actions / build_backend

Dereference of a possibly null reference.

Check warning on line 194 in backend/api/Services/RobotService.cs

View workflow job for this annotation

GitHub Actions / build_backend

Dereference of a possibly null reference.

Check failure on line 194 in backend/api/Services/RobotService.cs

View workflow job for this annotation

GitHub Actions / test_backend

Dereference of a possibly null reference.

Check failure on line 194 in backend/api/Services/RobotService.cs

View workflow job for this annotation

GitHub Actions / test_backend

Dereference of a possibly null reference.
{
logger.LogInformation("Setting {robotName} field {propertyName} from {oldValue} to {NewValue}", robot.Name, propertyName, property.GetValue(robot), value);
}
}
property.SetValue(robot, value);
}
}
Expand Down

0 comments on commit 22c5609

Please sign in to comment.