diff --git a/backend/api/Controllers/MissionSchedulingController.cs b/backend/api/Controllers/MissionSchedulingController.cs index 6977fd99b..80add502b 100644 --- a/backend/api/Controllers/MissionSchedulingController.cs +++ b/backend/api/Controllers/MissionSchedulingController.cs @@ -47,11 +47,11 @@ [FromBody] ScheduleMissionQuery scheduledMissionQuery ) { Robot robot; - try { robot = await robotService.GetRobotWithPreCheck(scheduledMissionQuery.RobotId); } + try { robot = await robotService.GetRobotWithPreCheck(scheduledMissionQuery.RobotId, readOnly: true); } catch (Exception e) when (e is RobotNotFoundException) { return NotFound(e.Message); } catch (Exception e) when (e is RobotPreCheckFailedException) { return BadRequest(e.Message); } - var missionRun = await missionRunService.ReadById(missionRunId); + var missionRun = await missionRunService.ReadByIdAsReadOnly(missionRunId); if (missionRun == null) return NotFound("Mission run not found"); var missionTasks = missionRun.Tasks.Where((t) => t.Status != Database.Models.TaskStatus.Successful && t.Status != Database.Models.TaskStatus.PartiallySuccessful).Select((t) => new MissionTask(t, Database.Models.TaskStatus.NotStarted)).ToList(); diff --git a/backend/api/Services/MissionRunService.cs b/backend/api/Services/MissionRunService.cs index 300f94e83..0d33a30db 100644 --- a/backend/api/Services/MissionRunService.cs +++ b/backend/api/Services/MissionRunService.cs @@ -18,6 +18,8 @@ public interface IMissionRunService public Task ReadById(string id); + public Task ReadByIdAsReadOnly(string id); + public Task ReadByIsarMissionId(string isarMissionId); public Task> ReadMissionRunQueue(string robotId); @@ -133,6 +135,12 @@ public async Task> ReadAll(MissionRunQueryStringParameters .FirstOrDefaultAsync(missionRun => missionRun.Id.Equals(id)); } + public async Task ReadByIdAsReadOnly(string id) + { + return await GetMissionRunsWithSubModels().AsNoTracking() + .FirstOrDefaultAsync(missionRun => missionRun.Id.Equals(id)); + } + public async Task> ReadMissionRunQueue(string robotId) { return await GetMissionRunsWithSubModels() @@ -321,6 +329,9 @@ private IQueryable GetMissionRunsWithSubModels() .ThenInclude(deck => deck != null ? deck.Plant : null) .ThenInclude(plant => plant != null ? plant.Installation : null) .Include(missionRun => missionRun.Area) + .ThenInclude(area => area != null ? area.Plant : null) + .ThenInclude(plant => plant != null ? plant.Installation : null) + .Include(missionRun => missionRun.Area) .ThenInclude(area => area != null ? area.Installation : null) .Include(missionRun => missionRun.Area) .ThenInclude(area => area != null ? area.Deck : null) diff --git a/backend/api/Services/RobotService.cs b/backend/api/Services/RobotService.cs index 0f29b88b3..1ba690898 100644 --- a/backend/api/Services/RobotService.cs +++ b/backend/api/Services/RobotService.cs @@ -12,7 +12,7 @@ public interface IRobotService public Task Create(Robot newRobot); public Task CreateFromQuery(CreateRobotQuery robotQuery); - public Task GetRobotWithPreCheck(string robotId); + public Task GetRobotWithPreCheck(string robotId, bool readOnly = false); public Task> ReadAll(); public Task> ReadAllActivePlants(); public Task ReadById(string id); @@ -97,9 +97,9 @@ public async Task CreateFromQuery(CreateRobotQuery robotQuery) throw new DbUpdateException("Could not create new robot in database as robot model does not exist"); } - public async Task GetRobotWithPreCheck(string robotId) + public async Task GetRobotWithPreCheck(string robotId, bool readOnly = false) { - var robot = await ReadById(robotId); + var robot = readOnly ? await ReadByIdAsReadOnly(robotId) : await ReadById(robotId); if (robot is null) { @@ -287,6 +287,8 @@ public async Task UpdateFlotillaStatus(string robotId, RobotFlotillaStatu public async Task ReadById(string id) { return await GetRobotsWithSubModels().FirstOrDefaultAsync(robot => robot.Id.Equals(id)); } + public async Task ReadByIdAsReadOnly(string id) { return await GetRobotsWithSubModels().AsNoTracking().FirstOrDefaultAsync(robot => robot.Id.Equals(id)); } + public async Task ReadByIsarId(string isarId) { return await GetRobotsWithSubModels()