diff --git a/backend/api.test/Client/AreaTests.cs b/backend/api.test/Client/AreaTests.cs index 4687c109c..190a86a9b 100644 --- a/backend/api.test/Client/AreaTests.cs +++ b/backend/api.test/Client/AreaTests.cs @@ -144,19 +144,18 @@ public async Task AreaTest() } [Fact] - public async Task MissionIsCreatedInArea() + public async Task MissionIsCreatedInInspectionArea() { // Arrange - Initialise area var installation = await _databaseUtilities.ReadOrNewInstallation(); var plant = await _databaseUtilities.ReadOrNewPlant(installation.InstallationCode); var deck = await _databaseUtilities.ReadOrNewDeck(installation.InstallationCode, plant.PlantCode); - var area = await _databaseUtilities.ReadOrNewArea(installation.InstallationCode, plant.PlantCode, deck.Name); // Arrange - Robot var robot = await _databaseUtilities.NewRobot(RobotStatus.Available, installation); string robotId = robot.Id; - string testMissionName = "testMissionInAreaTest"; + string testMissionName = "testMissionInInspectionAreaTest"; var inspection = new CustomInspectionQuery { @@ -198,12 +197,12 @@ public async Task MissionIsCreatedInArea() var mission = await missionResponse.Content.ReadFromJsonAsync(_serializerOptions); Assert.NotNull(mission); Assert.NotNull(mission.MissionId); - string areaUrl = "/areas"; - var areaMissionsResponse = await _client.GetAsync(areaUrl + $"/{area.Id}/mission-definitions"); + string inspectionAreaUrl = "/decks"; + var inspectionareaMissionsResponse = await _client.GetAsync(inspectionAreaUrl + $"/{deck.Id}/mission-definitions"); // Assert - Assert.True(areaMissionsResponse.IsSuccessStatusCode); - var missions = await areaMissionsResponse.Content.ReadFromJsonAsync>(_serializerOptions); + Assert.True(inspectionareaMissionsResponse.IsSuccessStatusCode); + var missions = await inspectionareaMissionsResponse.Content.ReadFromJsonAsync>(_serializerOptions); Assert.NotNull(missions); Assert.Single(missions.Where(m => m.Id.Equals(mission.MissionId, StringComparison.Ordinal))); } diff --git a/backend/api.test/Client/MissionTests.cs b/backend/api.test/Client/MissionTests.cs index e608c7b1b..7c669d1e0 100644 --- a/backend/api.test/Client/MissionTests.cs +++ b/backend/api.test/Client/MissionTests.cs @@ -51,9 +51,6 @@ public async Task ScheduleOneMissionTest() { // Arrange - Area var installation = await _databaseUtilities.ReadOrNewInstallation(); - var plant = await _databaseUtilities.ReadOrNewPlant(installation.InstallationCode); - var deck = await _databaseUtilities.ReadOrNewDeck(installation.InstallationCode, plant.PlantCode); - var area = await _databaseUtilities.ReadOrNewArea(installation.InstallationCode, plant.PlantCode, deck.Name); // Arrange - Robot var robot = await _databaseUtilities.NewRobot(RobotStatus.Busy, installation); @@ -67,7 +64,6 @@ public async Task ScheduleOneMissionTest() { RobotId = robotId, InstallationCode = installation.InstallationCode, - AreaName = area.Name, MissionSourceId = missionSourceId, DesiredStartTime = DateTime.UtcNow }; @@ -92,15 +88,11 @@ public async Task Schedule3MissionsTest() { // Arrange - Area var installation = await _databaseUtilities.ReadOrNewInstallation(); - var plant = await _databaseUtilities.ReadOrNewPlant(installation.InstallationCode); - var deck = await _databaseUtilities.ReadOrNewDeck(installation.InstallationCode, plant.PlantCode); - var area = await _databaseUtilities.ReadOrNewArea(installation.InstallationCode, plant.PlantCode, deck.Name); // Arrange - Robot var robot = await _databaseUtilities.NewRobot(RobotStatus.Busy, installation); string robotId = robot.Id; - string missionSourceId = "97"; // Act @@ -108,7 +100,6 @@ public async Task Schedule3MissionsTest() { RobotId = robotId, InstallationCode = installation.InstallationCode, - AreaName = area.Name, MissionSourceId = missionSourceId, DesiredStartTime = DateTime.UtcNow }; @@ -471,7 +462,6 @@ public async Task ScheduleDuplicatMissionDefinitions() { RobotId = robotId, InstallationCode = installation.InstallationCode, - AreaName = area.Name, MissionSourceId = missionSourceId, DesiredStartTime = DateTime.UtcNow }; diff --git a/backend/api.test/Client/RobotTests.cs b/backend/api.test/Client/RobotTests.cs index bf27e60df..3714e4b0c 100644 --- a/backend/api.test/Client/RobotTests.cs +++ b/backend/api.test/Client/RobotTests.cs @@ -91,7 +91,6 @@ public async Task RobotIsNotCreatedWithAreaNotInInstallation() var wrongInstallation = await _databaseUtilities.NewInstallation("wrongInstallation"); var wrongPlant = await _databaseUtilities.ReadOrNewPlant(wrongInstallation.InstallationCode); var wrongDeck = await _databaseUtilities.ReadOrNewDeck(wrongInstallation.InstallationCode, wrongPlant.PlantCode); - var wrongArea = await _databaseUtilities.ReadOrNewArea(wrongInstallation.InstallationCode, wrongPlant.PlantCode, wrongDeck.Name); // Arrange - Create robot var robotQuery = new CreateRobotQuery diff --git a/backend/api.test/Mocks/StidServiceMock.cs b/backend/api.test/Mocks/StidServiceMock.cs index d6beef1e7..802f8b2d3 100644 --- a/backend/api.test/Mocks/StidServiceMock.cs +++ b/backend/api.test/Mocks/StidServiceMock.cs @@ -16,7 +16,10 @@ public class MockStidService(FlotillaDbContext context) : IStidService await Task.CompletedTask; string testAreaName = "StidServiceMockArea"; - var area = context.Areas.Include(a => a.Deck).Include(d => d.Plant) + var area = context.Areas + .Include(a => a.Deck).ThenInclude(d => d.Installation) + .Include(a => a.Deck).ThenInclude(d => d.Plant).ThenInclude(p => p.Installation) + .Include(d => d.Plant) .Include(i => i.Installation).Include(d => d.DefaultLocalizationPose) .Where(area => area.Name.Contains(testAreaName)).ToList().FirstOrDefault(); if (area != null) { return area; } diff --git a/backend/api/Controllers/Models/ScheduledMissionQuery.cs b/backend/api/Controllers/Models/ScheduledMissionQuery.cs index 953560f98..170c21fb3 100644 --- a/backend/api/Controllers/Models/ScheduledMissionQuery.cs +++ b/backend/api/Controllers/Models/ScheduledMissionQuery.cs @@ -6,7 +6,6 @@ public struct ScheduledMissionQuery public string MissionSourceId { get; set; } public DateTime? DesiredStartTime { get; set; } public string InstallationCode { get; set; } - public string? AreaName { get; set; } public TimeSpan? InspectionFrequency { get; set; } } } diff --git a/backend/api/Services/AreaService.cs b/backend/api/Services/AreaService.cs index 83c81589c..20b2b5a14 100644 --- a/backend/api/Services/AreaService.cs +++ b/backend/api/Services/AreaService.cs @@ -169,12 +169,12 @@ private IQueryable GetAreas(bool readOnly = true) .Include(area => area.Deck) .ThenInclude(deck => deck != null ? deck.DefaultLocalizationPose : null) .Include(area => area.Deck) - .ThenInclude(deck => deck != null ? deck.Plant : null) - .ThenInclude(plant => plant != null ? plant.Installation : null) + .ThenInclude(deck => deck.Plant) + .ThenInclude(plant => plant.Installation) .Include(area => area.Deck) - .ThenInclude(deck => deck != null ? deck.Installation : null) + .ThenInclude(deck => deck.Installation) .Include(area => area.Plant) - .ThenInclude(plant => plant != null ? plant.Installation : null) + .ThenInclude(plant => plant.Installation) .Include(area => area.Installation) .Where((area) => accessibleInstallationCodes.Result.Contains(area.Installation.InstallationCode.ToUpper())); return readOnly ? query.AsNoTracking() : query.AsTracking(); diff --git a/backend/api/Services/DeckService.cs b/backend/api/Services/DeckService.cs index 037973214..b9c8e6e18 100644 --- a/backend/api/Services/DeckService.cs +++ b/backend/api/Services/DeckService.cs @@ -69,7 +69,7 @@ public async Task> ReadByInstallation(string installationCode, { if (deckName == null) { return null; } return await GetDecks(readOnly: readOnly).Where(a => - a.Installation != null && a.Installation.InstallationCode.Equals(installationCode) && a.Name.ToLower().Equals(deckName.ToLower()) + a.Installation != null && a.Installation.InstallationCode.ToLower().Equals(installationCode.ToLower()) && a.Name.ToLower().Equals(deckName.ToLower()) ).FirstOrDefaultAsync(); } @@ -147,7 +147,7 @@ public async Task Update(Deck deck) private IQueryable GetDecks(bool readOnly = true) { var accessibleInstallationCodes = accessRoleService.GetAllowedInstallationCodes(); - var query = context.Decks.Include(p => p.Plant).Include(i => i.Installation).Include(d => d.DefaultLocalizationPose) + var query = context.Decks.Include(p => p.Plant).ThenInclude(p => p.Installation).Include(i => i.Installation).Include(d => d.DefaultLocalizationPose) .Where((d) => accessibleInstallationCodes.Result.Contains(d.Installation.InstallationCode.ToUpper())); return readOnly ? query.AsNoTracking() : query.AsTracking(); } diff --git a/backend/api/Services/MissionDefinitionService.cs b/backend/api/Services/MissionDefinitionService.cs index d7b1a07d4..26a7c8a05 100644 --- a/backend/api/Services/MissionDefinitionService.cs +++ b/backend/api/Services/MissionDefinitionService.cs @@ -169,8 +169,7 @@ private IQueryable GetMissionDefinitionsWithSubModels(bool re .ThenInclude(deck => deck.Plant) .ThenInclude(plant => plant.Installation) .Include(missionDefinition => missionDefinition.InspectionArea) - .Include(missionDefinition => missionDefinition.InspectionArea) - .ThenInclude(area => area != null ? area.Installation : null) + .ThenInclude(area => area.Installation) .Include(missionDefinition => missionDefinition.Source) .Include(missionDefinition => missionDefinition.LastSuccessfulRun) .ThenInclude(missionRun => missionRun != null ? missionRun.Tasks : null)! diff --git a/frontend/src/api/ApiCaller.tsx b/frontend/src/api/ApiCaller.tsx index 18f6bc047..5f29efad8 100644 --- a/frontend/src/api/ApiCaller.tsx +++ b/frontend/src/api/ApiCaller.tsx @@ -290,7 +290,6 @@ export class BackendAPICaller { robotId: desiredRobot[0].id, missionSourceId: missionSourceId, installationCode: installationCode, - areaName: '', } const result = await BackendAPICaller.POST(path, body).catch( BackendAPICaller.handleError('POST', path)