diff --git a/backend/api/Controllers/DeckController.cs b/backend/api/Controllers/DeckController.cs index 596f79a32..126f312ba 100644 --- a/backend/api/Controllers/DeckController.cs +++ b/backend/api/Controllers/DeckController.cs @@ -15,12 +15,14 @@ public class DeckController : ControllerBase private readonly IPlantService _plantService; private readonly IMapService _mapService; + private readonly IAreaService _areaService; private readonly ILogger _logger; public DeckController( ILogger logger, IMapService mapService, + IAreaService areaService, IDeckService deckService, IInstallationService installationService, IPlantService plantService @@ -28,6 +30,7 @@ IPlantService plantService { _logger = logger; _mapService = mapService; + _areaService = areaService; _deckService = deckService; _installationService = installationService; _plantService = plantService; @@ -141,6 +144,53 @@ public async Task> Create([FromBody] CreateDeckQuery deck) } } + /// + /// Set default localization area for a deck + /// + /// + /// This query sets the default localization area for a deck + /// + [HttpPost] + [Authorize(Roles = Role.Admin)] + [Route("{deckId}/{areaId}/set-default-localization-area")] + [ProducesResponseType(typeof(AreaResponse), StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> SetDefaultLocalizationArea( + [FromRoute] string deckId, + [FromRoute] string areaId + ) + { + _logger.LogInformation(@"Setting default localization area {AreaId} to deck {DeckId}", areaId, deckId); + var deck = await _deckService.ReadById(deckId); + if (deck == null) + return NotFound($"Could not find deck with id {deckId}"); + + var area = await _areaService.ReadById(areaId); + if (area == null) + return NotFound($"Could not find area with id {areaId}"); + + if (area.Deck == null) + return NotFound($"Area {areaId} is not linked to any deck"); + + if (area.Deck.Id != deckId) + return NotFound($"Area {areaId} is not linked to deck {deckId}"); + + try + { + deck.DefaultLocalizationArea = area; + var updatedDeck = await _deckService.Update(deck); + return Ok(updatedDeck); + } + catch (Exception e) + { + _logger.LogError(e, "Error while setting a default localization area"); + return StatusCode(StatusCodes.Status500InternalServerError); + } + } + /// /// Deletes the deck with the specified id from the database. /// diff --git a/backend/api/Database/Context/FlotillaDbContext.cs b/backend/api/Database/Context/FlotillaDbContext.cs index a49930231..66cd278c2 100644 --- a/backend/api/Database/Context/FlotillaDbContext.cs +++ b/backend/api/Database/Context/FlotillaDbContext.cs @@ -69,11 +69,13 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) poseBuilder.OwnsOne(pose => pose.Position); poseBuilder.OwnsOne(pose => pose.Orientation); }); - modelBuilder.Entity().HasOne(a => a.Deck).WithMany(); + modelBuilder.Entity().HasOne(a => a.Deck); modelBuilder.Entity().HasOne(a => a.Installation).WithMany(); modelBuilder.Entity().HasOne(a => a.Plant).WithMany(); modelBuilder.Entity().HasOne(d => d.Plant).WithMany(); + modelBuilder.Entity().HasOne(d => d.Installation).WithMany(); + modelBuilder.Entity().HasOne(d => d.DefaultLocalizationArea).WithOne(a => a.Deck); modelBuilder.Entity().HasOne(a => a.Installation).WithMany(); modelBuilder.Entity().OwnsOne(s => s.Pose, poseBuilder => @@ -89,11 +91,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity().HasIndex(a => new { a.InstallationCode }).IsUnique(); modelBuilder.Entity().HasIndex(a => new { a.PlantCode }).IsUnique(); - modelBuilder.Entity().HasOne(a => a.Deck).WithMany().OnDelete(DeleteBehavior.Restrict); + modelBuilder.Entity().HasOne(a => a.Deck).WithOne().OnDelete(DeleteBehavior.Restrict); modelBuilder.Entity().HasOne(a => a.Plant).WithMany().OnDelete(DeleteBehavior.Restrict); modelBuilder.Entity().HasOne(a => a.Installation).WithMany().OnDelete(DeleteBehavior.Restrict); modelBuilder.Entity().HasOne(d => d.Plant).WithMany().OnDelete(DeleteBehavior.Restrict); modelBuilder.Entity().HasOne(d => d.Installation).WithMany().OnDelete(DeleteBehavior.Restrict); + modelBuilder.Entity().HasOne(d => d.DefaultLocalizationArea).WithOne().OnDelete(DeleteBehavior.Restrict); modelBuilder.Entity().HasOne(p => p.Installation).WithMany().OnDelete(DeleteBehavior.Restrict); } diff --git a/backend/api/Database/Models/Deck.cs b/backend/api/Database/Models/Deck.cs index 054d0d553..67e1b10f9 100644 --- a/backend/api/Database/Models/Deck.cs +++ b/backend/api/Database/Models/Deck.cs @@ -14,6 +14,11 @@ public class Deck public virtual Installation Installation { get; set; } + public string? DefaultLocalizationAreaId { get; set; } + + [ForeignKey("DefaultLocalizationAreaId")] + public virtual Area? DefaultLocalizationArea { get; set; } + [Required] [MaxLength(200)] public string Name { get; set; } diff --git a/backend/api/Migrations/20230908083418_AddDefaultLocalizationAreaToDeck.Designer.cs b/backend/api/Migrations/20230908083418_AddDefaultLocalizationAreaToDeck.Designer.cs new file mode 100644 index 000000000..a83c4956f --- /dev/null +++ b/backend/api/Migrations/20230908083418_AddDefaultLocalizationAreaToDeck.Designer.cs @@ -0,0 +1,1133 @@ +// +using System; +using Api.Database.Context; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Api.Migrations +{ + [DbContext(typeof(FlotillaDbContext))] + [Migration("20230908083418_AddDefaultLocalizationAreaToDeck")] + partial class AddDefaultLocalizationAreaToDeck + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Api.Database.Models.Area", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("InstallationId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("PlantId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("InstallationId"); + + b.HasIndex("PlantId"); + + b.ToTable("Areas"); + }); + + modelBuilder.Entity("Api.Database.Models.Deck", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("AreaId") + .HasColumnType("nvarchar(450)"); + + b.Property("DefaultLocalizationAreaId") + .HasColumnType("nvarchar(450)"); + + b.Property("InstallationId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("PlantId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("AreaId") + .IsUnique() + .HasFilter("[AreaId] IS NOT NULL"); + + b.HasIndex("DefaultLocalizationAreaId") + .IsUnique() + .HasFilter("[DefaultLocalizationAreaId] IS NOT NULL"); + + b.HasIndex("InstallationId"); + + b.HasIndex("PlantId"); + + b.ToTable("Decks"); + }); + + modelBuilder.Entity("Api.Database.Models.Installation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("InstallationCode") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.HasKey("Id"); + + b.HasIndex("InstallationCode") + .IsUnique(); + + b.ToTable("Installations"); + }); + + modelBuilder.Entity("Api.Database.Models.MissionDefinition", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("AreaId") + .HasColumnType("nvarchar(450)"); + + b.Property("Comment") + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("InspectionFrequency") + .HasColumnType("time"); + + b.Property("InstallationCode") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IsDeprecated") + .HasColumnType("bit"); + + b.Property("LastRunId") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("SourceId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("AreaId"); + + b.HasIndex("LastRunId"); + + b.HasIndex("SourceId"); + + b.ToTable("MissionDefinitions"); + }); + + modelBuilder.Entity("Api.Database.Models.MissionRun", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("AreaId") + .HasColumnType("nvarchar(450)"); + + b.Property("Comment") + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("Description") + .HasMaxLength(450) + .HasColumnType("nvarchar(450)"); + + b.Property("DesiredStartTime") + .HasColumnType("datetimeoffset"); + + b.Property("EndTime") + .HasColumnType("datetimeoffset"); + + b.Property("EstimatedDuration") + .HasColumnType("bigint"); + + b.Property("InstallationCode") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("IsarMissionId") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("MissionId") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("RobotId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("StartTime") + .HasColumnType("datetimeoffset"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("StatusReason") + .HasMaxLength(450) + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("AreaId"); + + b.HasIndex("RobotId"); + + b.ToTable("MissionRuns"); + }); + + modelBuilder.Entity("Api.Database.Models.Plant", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("InstallationId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("PlantCode") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.HasKey("Id"); + + b.HasIndex("InstallationId"); + + b.HasIndex("PlantCode") + .IsUnique(); + + b.ToTable("Plants"); + }); + + modelBuilder.Entity("Api.Database.Models.Robot", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("BatteryLevel") + .HasColumnType("real"); + + b.Property("CurrentAreaId") + .HasColumnType("nvarchar(450)"); + + b.Property("CurrentInstallation") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CurrentMissionId") + .HasColumnType("nvarchar(max)"); + + b.Property("Enabled") + .HasColumnType("bit"); + + b.Property("Host") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("IsarId") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("ModelId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Port") + .HasColumnType("int"); + + b.Property("PressureLevel") + .HasColumnType("real"); + + b.Property("SerialNumber") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Status") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CurrentAreaId"); + + b.HasIndex("ModelId"); + + b.ToTable("Robots"); + }); + + modelBuilder.Entity("Api.Database.Models.RobotModel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("AverageDurationPerTag") + .HasColumnType("real"); + + b.Property("BatteryWarningThreshold") + .HasColumnType("real"); + + b.Property("LowerPressureWarningThreshold") + .HasColumnType("real"); + + b.Property("Type") + .IsRequired() + .HasColumnType("nvarchar(56)"); + + b.Property("UpperPressureWarningThreshold") + .HasColumnType("real"); + + b.HasKey("Id"); + + b.HasIndex("Type") + .IsUnique(); + + b.ToTable("RobotModels"); + }); + + modelBuilder.Entity("Api.Database.Models.SafePosition", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("AreaId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("AreaId"); + + b.ToTable("SafePositions"); + }); + + modelBuilder.Entity("Api.Database.Models.Source", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b.Property("SourceId") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Sources"); + }); + + modelBuilder.Entity("Api.Database.Models.Area", b => + { + b.HasOne("Api.Database.Models.Installation", "Installation") + .WithMany() + .HasForeignKey("InstallationId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Api.Database.Models.Plant", "Plant") + .WithMany() + .HasForeignKey("PlantId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.OwnsOne("Api.Database.Models.Pose", "DefaultLocalizationPose", b1 => + { + b1.Property("AreaId") + .HasColumnType("nvarchar(450)"); + + b1.HasKey("AreaId"); + + b1.ToTable("Areas"); + + b1.WithOwner() + .HasForeignKey("AreaId"); + + b1.OwnsOne("Api.Database.Models.Orientation", "Orientation", b2 => + { + b2.Property("PoseAreaId") + .HasColumnType("nvarchar(450)"); + + b2.Property("W") + .HasColumnType("real"); + + b2.Property("X") + .HasColumnType("real"); + + b2.Property("Y") + .HasColumnType("real"); + + b2.Property("Z") + .HasColumnType("real"); + + b2.HasKey("PoseAreaId"); + + b2.ToTable("Areas"); + + b2.WithOwner() + .HasForeignKey("PoseAreaId"); + }); + + b1.OwnsOne("Api.Database.Models.Position", "Position", b2 => + { + b2.Property("PoseAreaId") + .HasColumnType("nvarchar(450)"); + + b2.Property("X") + .HasColumnType("real"); + + b2.Property("Y") + .HasColumnType("real"); + + b2.Property("Z") + .HasColumnType("real"); + + b2.HasKey("PoseAreaId"); + + b2.ToTable("Areas"); + + b2.WithOwner() + .HasForeignKey("PoseAreaId"); + }); + + b1.Navigation("Orientation") + .IsRequired(); + + b1.Navigation("Position") + .IsRequired(); + }); + + b.OwnsOne("Api.Database.Models.MapMetadata", "MapMetadata", b1 => + { + b1.Property("AreaId") + .HasColumnType("nvarchar(450)"); + + b1.Property("MapName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b1.HasKey("AreaId"); + + b1.ToTable("Areas"); + + b1.WithOwner() + .HasForeignKey("AreaId"); + + b1.OwnsOne("Api.Database.Models.Boundary", "Boundary", b2 => + { + b2.Property("MapMetadataAreaId") + .HasColumnType("nvarchar(450)"); + + b2.Property("X1") + .HasColumnType("float"); + + b2.Property("X2") + .HasColumnType("float"); + + b2.Property("Y1") + .HasColumnType("float"); + + b2.Property("Y2") + .HasColumnType("float"); + + b2.Property("Z1") + .HasColumnType("float"); + + b2.Property("Z2") + .HasColumnType("float"); + + b2.HasKey("MapMetadataAreaId"); + + b2.ToTable("Areas"); + + b2.WithOwner() + .HasForeignKey("MapMetadataAreaId"); + }); + + b1.OwnsOne("Api.Database.Models.TransformationMatrices", "TransformationMatrices", b2 => + { + b2.Property("MapMetadataAreaId") + .HasColumnType("nvarchar(450)"); + + b2.Property("C1") + .HasColumnType("float"); + + b2.Property("C2") + .HasColumnType("float"); + + b2.Property("D1") + .HasColumnType("float"); + + b2.Property("D2") + .HasColumnType("float"); + + b2.HasKey("MapMetadataAreaId"); + + b2.ToTable("Areas"); + + b2.WithOwner() + .HasForeignKey("MapMetadataAreaId"); + }); + + b1.Navigation("Boundary") + .IsRequired(); + + b1.Navigation("TransformationMatrices") + .IsRequired(); + }); + + b.Navigation("DefaultLocalizationPose") + .IsRequired(); + + b.Navigation("Installation"); + + b.Navigation("MapMetadata") + .IsRequired(); + + b.Navigation("Plant"); + }); + + modelBuilder.Entity("Api.Database.Models.Deck", b => + { + b.HasOne("Api.Database.Models.Area", null) + .WithOne("Deck") + .HasForeignKey("Api.Database.Models.Deck", "AreaId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("Api.Database.Models.Area", "DefaultLocalizationArea") + .WithOne() + .HasForeignKey("Api.Database.Models.Deck", "DefaultLocalizationAreaId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("Api.Database.Models.Installation", "Installation") + .WithMany() + .HasForeignKey("InstallationId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Api.Database.Models.Plant", "Plant") + .WithMany() + .HasForeignKey("PlantId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("DefaultLocalizationArea"); + + b.Navigation("Installation"); + + b.Navigation("Plant"); + }); + + modelBuilder.Entity("Api.Database.Models.MissionDefinition", b => + { + b.HasOne("Api.Database.Models.Area", "Area") + .WithMany() + .HasForeignKey("AreaId"); + + b.HasOne("Api.Database.Models.MissionRun", "LastRun") + .WithMany() + .HasForeignKey("LastRunId"); + + b.HasOne("Api.Database.Models.Source", "Source") + .WithMany() + .HasForeignKey("SourceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Area"); + + b.Navigation("LastRun"); + + b.Navigation("Source"); + }); + + modelBuilder.Entity("Api.Database.Models.MissionRun", b => + { + b.HasOne("Api.Database.Models.Area", "Area") + .WithMany() + .HasForeignKey("AreaId"); + + b.HasOne("Api.Database.Models.Robot", "Robot") + .WithMany() + .HasForeignKey("RobotId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsOne("Api.Database.Models.MapMetadata", "Map", b1 => + { + b1.Property("MissionRunId") + .HasColumnType("nvarchar(450)"); + + b1.Property("MapName") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b1.HasKey("MissionRunId"); + + b1.ToTable("MissionRuns"); + + b1.WithOwner() + .HasForeignKey("MissionRunId"); + + b1.OwnsOne("Api.Database.Models.Boundary", "Boundary", b2 => + { + b2.Property("MapMetadataMissionRunId") + .HasColumnType("nvarchar(450)"); + + b2.Property("X1") + .HasColumnType("float"); + + b2.Property("X2") + .HasColumnType("float"); + + b2.Property("Y1") + .HasColumnType("float"); + + b2.Property("Y2") + .HasColumnType("float"); + + b2.Property("Z1") + .HasColumnType("float"); + + b2.Property("Z2") + .HasColumnType("float"); + + b2.HasKey("MapMetadataMissionRunId"); + + b2.ToTable("MissionRuns"); + + b2.WithOwner() + .HasForeignKey("MapMetadataMissionRunId"); + }); + + b1.OwnsOne("Api.Database.Models.TransformationMatrices", "TransformationMatrices", b2 => + { + b2.Property("MapMetadataMissionRunId") + .HasColumnType("nvarchar(450)"); + + b2.Property("C1") + .HasColumnType("float"); + + b2.Property("C2") + .HasColumnType("float"); + + b2.Property("D1") + .HasColumnType("float"); + + b2.Property("D2") + .HasColumnType("float"); + + b2.HasKey("MapMetadataMissionRunId"); + + b2.ToTable("MissionRuns"); + + b2.WithOwner() + .HasForeignKey("MapMetadataMissionRunId"); + }); + + b1.Navigation("Boundary") + .IsRequired(); + + b1.Navigation("TransformationMatrices") + .IsRequired(); + }); + + b.OwnsMany("Api.Database.Models.MissionTask", "Tasks", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b1.Property("Description") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b1.Property("EchoPoseId") + .HasColumnType("int"); + + b1.Property("EchoTagLink") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b1.Property("EndTime") + .HasColumnType("datetimeoffset"); + + b1.Property("IsarTaskId") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b1.Property("MissionRunId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b1.Property("StartTime") + .HasColumnType("datetimeoffset"); + + b1.Property("Status") + .HasColumnType("int"); + + b1.Property("TagId") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b1.Property("TaskOrder") + .HasColumnType("int"); + + b1.HasKey("Id"); + + b1.HasIndex("MissionRunId"); + + b1.ToTable("MissionTask"); + + b1.WithOwner() + .HasForeignKey("MissionRunId"); + + b1.OwnsMany("Api.Database.Models.Inspection", "Inspections", b2 => + { + b2.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b2.Property("AnalysisType") + .HasColumnType("int"); + + b2.Property("EndTime") + .HasColumnType("datetimeoffset"); + + b2.Property("InspectionType") + .HasColumnType("int"); + + b2.Property("InspectionUrl") + .HasMaxLength(250) + .HasColumnType("nvarchar(250)"); + + b2.Property("IsarStepId") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b2.Property("MissionTaskId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b2.Property("StartTime") + .HasColumnType("datetimeoffset"); + + b2.Property("Status") + .HasColumnType("int"); + + b2.Property("VideoDuration") + .HasColumnType("real"); + + b2.HasKey("Id"); + + b2.HasIndex("MissionTaskId"); + + b2.ToTable("Inspection"); + + b2.WithOwner() + .HasForeignKey("MissionTaskId"); + }); + + b1.OwnsOne("Api.Database.Models.Position", "InspectionTarget", b2 => + { + b2.Property("MissionTaskId") + .HasColumnType("nvarchar(450)"); + + b2.Property("X") + .HasColumnType("real"); + + b2.Property("Y") + .HasColumnType("real"); + + b2.Property("Z") + .HasColumnType("real"); + + b2.HasKey("MissionTaskId"); + + b2.ToTable("MissionTask"); + + b2.WithOwner() + .HasForeignKey("MissionTaskId"); + }); + + b1.OwnsOne("Api.Database.Models.Pose", "RobotPose", b2 => + { + b2.Property("MissionTaskId") + .HasColumnType("nvarchar(450)"); + + b2.HasKey("MissionTaskId"); + + b2.ToTable("MissionTask"); + + b2.WithOwner() + .HasForeignKey("MissionTaskId"); + + b2.OwnsOne("Api.Database.Models.Orientation", "Orientation", b3 => + { + b3.Property("PoseMissionTaskId") + .HasColumnType("nvarchar(450)"); + + b3.Property("W") + .HasColumnType("real"); + + b3.Property("X") + .HasColumnType("real"); + + b3.Property("Y") + .HasColumnType("real"); + + b3.Property("Z") + .HasColumnType("real"); + + b3.HasKey("PoseMissionTaskId"); + + b3.ToTable("MissionTask"); + + b3.WithOwner() + .HasForeignKey("PoseMissionTaskId"); + }); + + b2.OwnsOne("Api.Database.Models.Position", "Position", b3 => + { + b3.Property("PoseMissionTaskId") + .HasColumnType("nvarchar(450)"); + + b3.Property("X") + .HasColumnType("real"); + + b3.Property("Y") + .HasColumnType("real"); + + b3.Property("Z") + .HasColumnType("real"); + + b3.HasKey("PoseMissionTaskId"); + + b3.ToTable("MissionTask"); + + b3.WithOwner() + .HasForeignKey("PoseMissionTaskId"); + }); + + b2.Navigation("Orientation") + .IsRequired(); + + b2.Navigation("Position") + .IsRequired(); + }); + + b1.Navigation("InspectionTarget") + .IsRequired(); + + b1.Navigation("Inspections"); + + b1.Navigation("RobotPose") + .IsRequired(); + }); + + b.Navigation("Area"); + + b.Navigation("Map"); + + b.Navigation("Robot"); + + b.Navigation("Tasks"); + }); + + modelBuilder.Entity("Api.Database.Models.Plant", b => + { + b.HasOne("Api.Database.Models.Installation", "Installation") + .WithMany() + .HasForeignKey("InstallationId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Installation"); + }); + + modelBuilder.Entity("Api.Database.Models.Robot", b => + { + b.HasOne("Api.Database.Models.Area", "CurrentArea") + .WithMany() + .HasForeignKey("CurrentAreaId"); + + b.HasOne("Api.Database.Models.RobotModel", "Model") + .WithMany() + .HasForeignKey("ModelId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsOne("Api.Database.Models.Pose", "Pose", b1 => + { + b1.Property("RobotId") + .HasColumnType("nvarchar(450)"); + + b1.HasKey("RobotId"); + + b1.ToTable("Robots"); + + b1.WithOwner() + .HasForeignKey("RobotId"); + + b1.OwnsOne("Api.Database.Models.Orientation", "Orientation", b2 => + { + b2.Property("PoseRobotId") + .HasColumnType("nvarchar(450)"); + + b2.Property("W") + .HasColumnType("real"); + + b2.Property("X") + .HasColumnType("real"); + + b2.Property("Y") + .HasColumnType("real"); + + b2.Property("Z") + .HasColumnType("real"); + + b2.HasKey("PoseRobotId"); + + b2.ToTable("Robots"); + + b2.WithOwner() + .HasForeignKey("PoseRobotId"); + }); + + b1.OwnsOne("Api.Database.Models.Position", "Position", b2 => + { + b2.Property("PoseRobotId") + .HasColumnType("nvarchar(450)"); + + b2.Property("X") + .HasColumnType("real"); + + b2.Property("Y") + .HasColumnType("real"); + + b2.Property("Z") + .HasColumnType("real"); + + b2.HasKey("PoseRobotId"); + + b2.ToTable("Robots"); + + b2.WithOwner() + .HasForeignKey("PoseRobotId"); + }); + + b1.Navigation("Orientation") + .IsRequired(); + + b1.Navigation("Position") + .IsRequired(); + }); + + b.OwnsMany("Api.Database.Models.VideoStream", "VideoStreams", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(450)"); + + b1.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b1.Property("RobotId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b1.Property("ShouldRotate270Clockwise") + .HasColumnType("bit"); + + b1.Property("Type") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b1.Property("Url") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b1.HasKey("Id"); + + b1.HasIndex("RobotId"); + + b1.ToTable("VideoStream"); + + b1.WithOwner() + .HasForeignKey("RobotId"); + }); + + b.Navigation("CurrentArea"); + + b.Navigation("Model"); + + b.Navigation("Pose") + .IsRequired(); + + b.Navigation("VideoStreams"); + }); + + modelBuilder.Entity("Api.Database.Models.SafePosition", b => + { + b.HasOne("Api.Database.Models.Area", null) + .WithMany("SafePositions") + .HasForeignKey("AreaId"); + + b.OwnsOne("Api.Database.Models.Pose", "Pose", b1 => + { + b1.Property("SafePositionId") + .HasColumnType("nvarchar(450)"); + + b1.HasKey("SafePositionId"); + + b1.ToTable("SafePositions"); + + b1.WithOwner() + .HasForeignKey("SafePositionId"); + + b1.OwnsOne("Api.Database.Models.Orientation", "Orientation", b2 => + { + b2.Property("PoseSafePositionId") + .HasColumnType("nvarchar(450)"); + + b2.Property("W") + .HasColumnType("real"); + + b2.Property("X") + .HasColumnType("real"); + + b2.Property("Y") + .HasColumnType("real"); + + b2.Property("Z") + .HasColumnType("real"); + + b2.HasKey("PoseSafePositionId"); + + b2.ToTable("SafePositions"); + + b2.WithOwner() + .HasForeignKey("PoseSafePositionId"); + }); + + b1.OwnsOne("Api.Database.Models.Position", "Position", b2 => + { + b2.Property("PoseSafePositionId") + .HasColumnType("nvarchar(450)"); + + b2.Property("X") + .HasColumnType("real"); + + b2.Property("Y") + .HasColumnType("real"); + + b2.Property("Z") + .HasColumnType("real"); + + b2.HasKey("PoseSafePositionId"); + + b2.ToTable("SafePositions"); + + b2.WithOwner() + .HasForeignKey("PoseSafePositionId"); + }); + + b1.Navigation("Orientation") + .IsRequired(); + + b1.Navigation("Position") + .IsRequired(); + }); + + b.Navigation("Pose") + .IsRequired(); + }); + + modelBuilder.Entity("Api.Database.Models.Area", b => + { + b.Navigation("Deck"); + + b.Navigation("SafePositions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/backend/api/Migrations/20230908083418_AddDefaultLocalizationAreaToDeck.cs b/backend/api/Migrations/20230908083418_AddDefaultLocalizationAreaToDeck.cs new file mode 100644 index 000000000..df9501993 --- /dev/null +++ b/backend/api/Migrations/20230908083418_AddDefaultLocalizationAreaToDeck.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Api.Migrations +{ + /// + public partial class AddDefaultLocalizationAreaToDeck : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/backend/api/Migrations/FlotillaDbContextModelSnapshot.cs b/backend/api/Migrations/FlotillaDbContextModelSnapshot.cs index fb7f0fedc..c6c2f5cca 100644 --- a/backend/api/Migrations/FlotillaDbContextModelSnapshot.cs +++ b/backend/api/Migrations/FlotillaDbContextModelSnapshot.cs @@ -28,9 +28,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasColumnType("nvarchar(450)"); - b.Property("DeckId") - .HasColumnType("nvarchar(450)"); - b.Property("InstallationId") .IsRequired() .HasColumnType("nvarchar(450)"); @@ -46,8 +43,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("DeckId"); - b.HasIndex("InstallationId"); b.HasIndex("PlantId"); @@ -61,6 +56,12 @@ protected override void BuildModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasColumnType("nvarchar(450)"); + b.Property("AreaId") + .HasColumnType("nvarchar(450)"); + + b.Property("DefaultLocalizationAreaId") + .HasColumnType("nvarchar(450)"); + b.Property("InstallationId") .IsRequired() .HasColumnType("nvarchar(450)"); @@ -76,6 +77,14 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); + b.HasIndex("AreaId") + .IsUnique() + .HasFilter("[AreaId] IS NOT NULL"); + + b.HasIndex("DefaultLocalizationAreaId") + .IsUnique() + .HasFilter("[DefaultLocalizationAreaId] IS NOT NULL"); + b.HasIndex("InstallationId"); b.HasIndex("PlantId"); @@ -379,11 +388,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("Api.Database.Models.Area", b => { - b.HasOne("Api.Database.Models.Deck", "Deck") - .WithMany() - .HasForeignKey("DeckId") - .OnDelete(DeleteBehavior.Restrict); - b.HasOne("Api.Database.Models.Installation", "Installation") .WithMany() .HasForeignKey("InstallationId") @@ -542,8 +546,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired(); }); - b.Navigation("Deck"); - b.Navigation("DefaultLocalizationPose") .IsRequired(); @@ -557,6 +559,16 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("Api.Database.Models.Deck", b => { + b.HasOne("Api.Database.Models.Area", null) + .WithOne("Deck") + .HasForeignKey("Api.Database.Models.Deck", "AreaId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("Api.Database.Models.Area", "DefaultLocalizationArea") + .WithOne() + .HasForeignKey("Api.Database.Models.Deck", "DefaultLocalizationAreaId") + .OnDelete(DeleteBehavior.Restrict); + b.HasOne("Api.Database.Models.Installation", "Installation") .WithMany() .HasForeignKey("InstallationId") @@ -569,6 +581,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) .OnDelete(DeleteBehavior.Restrict) .IsRequired(); + b.Navigation("DefaultLocalizationArea"); + b.Navigation("Installation"); b.Navigation("Plant"); @@ -1106,6 +1120,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("Api.Database.Models.Area", b => { + b.Navigation("Deck"); + b.Navigation("SafePositions"); }); #pragma warning restore 612, 618 diff --git a/backend/api/Services/DeckService.cs b/backend/api/Services/DeckService.cs index 55e1eaaf1..beca409e8 100644 --- a/backend/api/Services/DeckService.cs +++ b/backend/api/Services/DeckService.cs @@ -56,7 +56,7 @@ public async Task> ReadAll() private IQueryable GetDecks() { - return _context.Decks.Include(p => p.Plant).Include(i => i.Installation); + return _context.Decks.Include(p => p.Plant).Include(i => i.Installation).Include(d => d.DefaultLocalizationArea); } public async Task ReadById(string id)