From 716ed532f1162250ff94297e4cbf4af597727924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zieli=C5=84ski?= Date: Mon, 18 Sep 2023 11:29:25 +0200 Subject: [PATCH] WIP: copy process --- WebAPI/AppDbContext.cs | 6 + WebAPI/Controllers/LayersController.cs | 20 +- .../20230917110252_Layer.parent.Designer.cs | 302 ++++++++++++++++ .../Migrations/20230917110252_Layer.parent.cs | 49 +++ .../20230918090621_ProcessSource.Designer.cs | 330 ++++++++++++++++++ .../20230918090621_ProcessSource.cs | 45 +++ .../Migrations/AppDbContextModelSnapshot.cs | 39 +++ WebAPI/Models/Layer.cs | 5 +- WebAPI/Models/ProcessSource.cs | 15 + WebAPI/dataProcessors/copy.processor.cs | 55 +-- .../dataProcessors/deaggregation.processor.cs | 4 +- 11 files changed, 809 insertions(+), 61 deletions(-) create mode 100644 WebAPI/Migrations/20230917110252_Layer.parent.Designer.cs create mode 100644 WebAPI/Migrations/20230917110252_Layer.parent.cs create mode 100644 WebAPI/Migrations/20230918090621_ProcessSource.Designer.cs create mode 100644 WebAPI/Migrations/20230918090621_ProcessSource.cs create mode 100644 WebAPI/Models/ProcessSource.cs diff --git a/WebAPI/AppDbContext.cs b/WebAPI/AppDbContext.cs index 72d32df..4c9b8de 100644 --- a/WebAPI/AppDbContext.cs +++ b/WebAPI/AppDbContext.cs @@ -9,6 +9,7 @@ namespace WebAPI public DbSet Users { get; set; } public DbSet Layers { get; set; } public DbSet Records { get; set; } + public DbSet ProcessSources { get; set; } public AppDbContext(DbContextOptions options) : base(options) { @@ -16,6 +17,11 @@ namespace WebAPI protected override void OnModelCreating(ModelBuilder modelBuilder) { + modelBuilder.Entity().HasKey(x => new + { + x.LayerId, + x.SourceId + }); } public static readonly Microsoft.Extensions.Logging.LoggerFactory _myLoggerFactory = diff --git a/WebAPI/Controllers/LayersController.cs b/WebAPI/Controllers/LayersController.cs index 4f99400..f651c8a 100644 --- a/WebAPI/Controllers/LayersController.cs +++ b/WebAPI/Controllers/LayersController.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using WebAPI.dataParsers; +using WebAPI.dataProcessors; using WebAPI.Exports; using WebAPI.Models; @@ -211,7 +212,8 @@ namespace WebAPI.Controllers return BadRequest(); } else { - Layer sourceLayer = db.Layers.Single(x => x.Name == sourceName); + Layer sourceLayer = db.Layers.Include(x => x.Records) + .Single(x => x.Name == sourceName); if (sourceLayer == null) { logsController.AddEntry(new LogEntry @@ -245,9 +247,12 @@ namespace WebAPI.Controllers return BadRequest(); } else { + Layer processedLayer; switch (processType) { case "Copy": + CopyProcessor processor = new CopyProcessor(db); + processedLayer = processor.process(sourceLayer); break; case "Deaggregate": break; @@ -256,16 +261,6 @@ namespace WebAPI.Controllers } } } - //Layer sourceLayer = db.Layers.Single(x => x.Name == layer.Records.Single(y => y.Code == "Source").Desc1); - - // string startDate = layer.Records!.Where(x => x.Code == "StartDate").First().Desc1!; - /// string endDate = layer.Records!.Where(x => x.Code == "EndDate").First().Desc1!; - // var startDateParsed = DateTime.ParseExact(startDate, "yyyy.MM.dd", null); - // var endDateParsed = DateTime.ParseExact(endDate, "yyyy.MM.dd", null); - // if (startDateParsed.Date <= DateTime.UtcNow.Date && endDateParsed.Date >= DateTime.UtcNow.Date) - // { - // processImportWorker(layer); - // } } } @@ -355,7 +350,8 @@ namespace WebAPI.Controllers Layer layer = new Layer { Source = "GoogleSheet", - Number = db.Layers.Count() + 1 + Number = db.Layers.Count() + 1, + ParentId = importWorker.Id }; layer.Name = $"L{layer.Number}-I-{name}-{year}/{month}-{DateTime.Now.ToString("yyyyMMddHHmm")}"; layer.Type = LayerType.import; diff --git a/WebAPI/Migrations/20230917110252_Layer.parent.Designer.cs b/WebAPI/Migrations/20230917110252_Layer.parent.Designer.cs new file mode 100644 index 0000000..6f37a40 --- /dev/null +++ b/WebAPI/Migrations/20230917110252_Layer.parent.Designer.cs @@ -0,0 +1,302 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using WebAPI; + +#nullable disable + +namespace WebAPI.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20230917110252_Layer.parent")] + partial class Layerparent + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("WebAPI.Models.Layer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedById") + .HasColumnType("uniqueidentifier"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Number") + .HasColumnType("int"); + + b.Property("Source") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Type") + .HasColumnType("int"); + + b.Property("parentId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("CreatedById"); + + b.HasIndex("ModifiedById"); + + b.HasIndex("parentId"); + + b.ToTable("Layers"); + }); + + modelBuilder.Entity("WebAPI.Models.Record", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Code") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Desc1") + .HasColumnType("nvarchar(max)"); + + b.Property("Desc2") + .HasColumnType("nvarchar(max)"); + + b.Property("Desc3") + .HasColumnType("nvarchar(max)"); + + b.Property("Desc4") + .HasColumnType("nvarchar(max)"); + + b.Property("Desc5") + .HasColumnType("nvarchar(max)"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LayerId") + .HasColumnType("uniqueidentifier"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Value1") + .HasColumnType("real"); + + b.Property("Value10") + .HasColumnType("real"); + + b.Property("Value11") + .HasColumnType("real"); + + b.Property("Value12") + .HasColumnType("real"); + + b.Property("Value13") + .HasColumnType("real"); + + b.Property("Value14") + .HasColumnType("real"); + + b.Property("Value15") + .HasColumnType("real"); + + b.Property("Value16") + .HasColumnType("real"); + + b.Property("Value17") + .HasColumnType("real"); + + b.Property("Value18") + .HasColumnType("real"); + + b.Property("Value19") + .HasColumnType("real"); + + b.Property("Value2") + .HasColumnType("real"); + + b.Property("Value20") + .HasColumnType("real"); + + b.Property("Value21") + .HasColumnType("real"); + + b.Property("Value22") + .HasColumnType("real"); + + b.Property("Value23") + .HasColumnType("real"); + + b.Property("Value24") + .HasColumnType("real"); + + b.Property("Value25") + .HasColumnType("real"); + + b.Property("Value26") + .HasColumnType("real"); + + b.Property("Value27") + .HasColumnType("real"); + + b.Property("Value28") + .HasColumnType("real"); + + b.Property("Value29") + .HasColumnType("real"); + + b.Property("Value3") + .HasColumnType("real"); + + b.Property("Value30") + .HasColumnType("real"); + + b.Property("Value31") + .HasColumnType("real"); + + b.Property("Value4") + .HasColumnType("real"); + + b.Property("Value5") + .HasColumnType("real"); + + b.Property("Value6") + .HasColumnType("real"); + + b.Property("Value7") + .HasColumnType("real"); + + b.Property("Value8") + .HasColumnType("real"); + + b.Property("Value9") + .HasColumnType("real"); + + b.HasKey("Id"); + + b.HasIndex("CreatedById"); + + b.HasIndex("LayerId"); + + b.HasIndex("ModifiedById"); + + b.ToTable("Records"); + }); + + modelBuilder.Entity("WebAPI.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("Email") + .HasColumnType("nvarchar(max)"); + + b.Property("UserName") + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("WebAPI.Models.Layer", b => + { + b.HasOne("WebAPI.Models.User", "CreatedBy") + .WithMany() + .HasForeignKey("CreatedById") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("WebAPI.Models.User", "ModifiedBy") + .WithMany() + .HasForeignKey("ModifiedById") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("WebAPI.Models.Layer", "parent") + .WithMany() + .HasForeignKey("parentId"); + + b.Navigation("CreatedBy"); + + b.Navigation("ModifiedBy"); + + b.Navigation("parent"); + }); + + modelBuilder.Entity("WebAPI.Models.Record", b => + { + b.HasOne("WebAPI.Models.User", "CreatedBy") + .WithMany() + .HasForeignKey("CreatedById") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("WebAPI.Models.Layer", null) + .WithMany("Records") + .HasForeignKey("LayerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("WebAPI.Models.User", "ModifiedBy") + .WithMany() + .HasForeignKey("ModifiedById") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CreatedBy"); + + b.Navigation("ModifiedBy"); + }); + + modelBuilder.Entity("WebAPI.Models.Layer", b => + { + b.Navigation("Records"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WebAPI/Migrations/20230917110252_Layer.parent.cs b/WebAPI/Migrations/20230917110252_Layer.parent.cs new file mode 100644 index 0000000..f3a9003 --- /dev/null +++ b/WebAPI/Migrations/20230917110252_Layer.parent.cs @@ -0,0 +1,49 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace WebAPI.Migrations +{ + /// + public partial class Layerparent : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "parentId", + table: "Layers", + type: "uniqueidentifier", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_Layers_parentId", + table: "Layers", + column: "parentId"); + + migrationBuilder.AddForeignKey( + name: "FK_Layers_Layers_parentId", + table: "Layers", + column: "parentId", + principalTable: "Layers", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Layers_Layers_parentId", + table: "Layers"); + + migrationBuilder.DropIndex( + name: "IX_Layers_parentId", + table: "Layers"); + + migrationBuilder.DropColumn( + name: "parentId", + table: "Layers"); + } + } +} diff --git a/WebAPI/Migrations/20230918090621_ProcessSource.Designer.cs b/WebAPI/Migrations/20230918090621_ProcessSource.Designer.cs new file mode 100644 index 0000000..0d79921 --- /dev/null +++ b/WebAPI/Migrations/20230918090621_ProcessSource.Designer.cs @@ -0,0 +1,330 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using WebAPI; + +#nullable disable + +namespace WebAPI.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20230918090621_ProcessSource")] + partial class ProcessSource + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("WebAPI.Models.Layer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedById") + .HasColumnType("uniqueidentifier"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Number") + .HasColumnType("int"); + + b.Property("Source") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Type") + .HasColumnType("int"); + + b.Property("parentId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("CreatedById"); + + b.HasIndex("ModifiedById"); + + b.HasIndex("parentId"); + + b.ToTable("Layers"); + }); + + modelBuilder.Entity("WebAPI.Models.ProcessSource", b => + { + b.Property("LayerId") + .HasColumnType("uniqueidentifier"); + + b.Property("SourceId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("LayerId", "SourceId"); + + b.HasIndex("SourceId"); + + b.ToTable("ProcessSources"); + }); + + modelBuilder.Entity("WebAPI.Models.Record", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Code") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Desc1") + .HasColumnType("nvarchar(max)"); + + b.Property("Desc2") + .HasColumnType("nvarchar(max)"); + + b.Property("Desc3") + .HasColumnType("nvarchar(max)"); + + b.Property("Desc4") + .HasColumnType("nvarchar(max)"); + + b.Property("Desc5") + .HasColumnType("nvarchar(max)"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LayerId") + .HasColumnType("uniqueidentifier"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Value1") + .HasColumnType("real"); + + b.Property("Value10") + .HasColumnType("real"); + + b.Property("Value11") + .HasColumnType("real"); + + b.Property("Value12") + .HasColumnType("real"); + + b.Property("Value13") + .HasColumnType("real"); + + b.Property("Value14") + .HasColumnType("real"); + + b.Property("Value15") + .HasColumnType("real"); + + b.Property("Value16") + .HasColumnType("real"); + + b.Property("Value17") + .HasColumnType("real"); + + b.Property("Value18") + .HasColumnType("real"); + + b.Property("Value19") + .HasColumnType("real"); + + b.Property("Value2") + .HasColumnType("real"); + + b.Property("Value20") + .HasColumnType("real"); + + b.Property("Value21") + .HasColumnType("real"); + + b.Property("Value22") + .HasColumnType("real"); + + b.Property("Value23") + .HasColumnType("real"); + + b.Property("Value24") + .HasColumnType("real"); + + b.Property("Value25") + .HasColumnType("real"); + + b.Property("Value26") + .HasColumnType("real"); + + b.Property("Value27") + .HasColumnType("real"); + + b.Property("Value28") + .HasColumnType("real"); + + b.Property("Value29") + .HasColumnType("real"); + + b.Property("Value3") + .HasColumnType("real"); + + b.Property("Value30") + .HasColumnType("real"); + + b.Property("Value31") + .HasColumnType("real"); + + b.Property("Value4") + .HasColumnType("real"); + + b.Property("Value5") + .HasColumnType("real"); + + b.Property("Value6") + .HasColumnType("real"); + + b.Property("Value7") + .HasColumnType("real"); + + b.Property("Value8") + .HasColumnType("real"); + + b.Property("Value9") + .HasColumnType("real"); + + b.HasKey("Id"); + + b.HasIndex("CreatedById"); + + b.HasIndex("LayerId"); + + b.HasIndex("ModifiedById"); + + b.ToTable("Records"); + }); + + modelBuilder.Entity("WebAPI.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("Email") + .HasColumnType("nvarchar(max)"); + + b.Property("UserName") + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("WebAPI.Models.Layer", b => + { + b.HasOne("WebAPI.Models.User", "CreatedBy") + .WithMany() + .HasForeignKey("CreatedById") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("WebAPI.Models.User", "ModifiedBy") + .WithMany() + .HasForeignKey("ModifiedById") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("WebAPI.Models.Layer", "parent") + .WithMany() + .HasForeignKey("parentId"); + + b.Navigation("CreatedBy"); + + b.Navigation("ModifiedBy"); + + b.Navigation("parent"); + }); + + modelBuilder.Entity("WebAPI.Models.ProcessSource", b => + { + b.HasOne("WebAPI.Models.Layer", "Source") + .WithMany("Sources") + .HasForeignKey("SourceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Source"); + }); + + modelBuilder.Entity("WebAPI.Models.Record", b => + { + b.HasOne("WebAPI.Models.User", "CreatedBy") + .WithMany() + .HasForeignKey("CreatedById") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("WebAPI.Models.Layer", null) + .WithMany("Records") + .HasForeignKey("LayerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("WebAPI.Models.User", "ModifiedBy") + .WithMany() + .HasForeignKey("ModifiedById") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CreatedBy"); + + b.Navigation("ModifiedBy"); + }); + + modelBuilder.Entity("WebAPI.Models.Layer", b => + { + b.Navigation("Records"); + + b.Navigation("Sources"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WebAPI/Migrations/20230918090621_ProcessSource.cs b/WebAPI/Migrations/20230918090621_ProcessSource.cs new file mode 100644 index 0000000..60cb778 --- /dev/null +++ b/WebAPI/Migrations/20230918090621_ProcessSource.cs @@ -0,0 +1,45 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace WebAPI.Migrations +{ + /// + public partial class ProcessSource : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "ProcessSources", + columns: table => new + { + LayerId = table.Column(type: "uniqueidentifier", nullable: false), + SourceId = table.Column(type: "uniqueidentifier", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ProcessSources", x => new { x.LayerId, x.SourceId }); + table.ForeignKey( + name: "FK_ProcessSources_Layers_SourceId", + column: x => x.SourceId, + principalTable: "Layers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ProcessSources_SourceId", + table: "ProcessSources", + column: "SourceId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ProcessSources"); + } + } +} diff --git a/WebAPI/Migrations/AppDbContextModelSnapshot.cs b/WebAPI/Migrations/AppDbContextModelSnapshot.cs index e19a51d..5c5f110 100644 --- a/WebAPI/Migrations/AppDbContextModelSnapshot.cs +++ b/WebAPI/Migrations/AppDbContextModelSnapshot.cs @@ -57,15 +57,35 @@ namespace WebAPI.Migrations b.Property("Type") .HasColumnType("int"); + b.Property("parentId") + .HasColumnType("uniqueidentifier"); + b.HasKey("Id"); b.HasIndex("CreatedById"); b.HasIndex("ModifiedById"); + b.HasIndex("parentId"); + b.ToTable("Layers"); }); + modelBuilder.Entity("WebAPI.Models.ProcessSource", b => + { + b.Property("LayerId") + .HasColumnType("uniqueidentifier"); + + b.Property("SourceId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("LayerId", "SourceId"); + + b.HasIndex("SourceId"); + + b.ToTable("ProcessSources"); + }); + modelBuilder.Entity("WebAPI.Models.Record", b => { b.Property("Id") @@ -248,9 +268,26 @@ namespace WebAPI.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("WebAPI.Models.Layer", "parent") + .WithMany() + .HasForeignKey("parentId"); + b.Navigation("CreatedBy"); b.Navigation("ModifiedBy"); + + b.Navigation("parent"); + }); + + modelBuilder.Entity("WebAPI.Models.ProcessSource", b => + { + b.HasOne("WebAPI.Models.Layer", "Source") + .WithMany("Sources") + .HasForeignKey("SourceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Source"); }); modelBuilder.Entity("WebAPI.Models.Record", b => @@ -281,6 +318,8 @@ namespace WebAPI.Migrations modelBuilder.Entity("WebAPI.Models.Layer", b => { b.Navigation("Records"); + + b.Navigation("Sources"); }); #pragma warning restore 612, 618 } diff --git a/WebAPI/Models/Layer.cs b/WebAPI/Models/Layer.cs index bbd404f..cce55b9 100644 --- a/WebAPI/Models/Layer.cs +++ b/WebAPI/Models/Layer.cs @@ -30,14 +30,15 @@ namespace WebAPI.Models #endregion #region Relations public ICollection? Records { get; set; } + public ICollection? Sources { get; set; } [Required] public Guid CreatedById { get; set; } public User? CreatedBy { get; set; } [Required] public Guid ModifiedById { get; set; } public User? ModifiedBy { get; set; } - public Guid? parentId { get; set; } - public Layer? parent { get; set; } + public Guid? ParentId { get; set; } + public Layer? Parent { get; set; } #endregion } } diff --git a/WebAPI/Models/ProcessSource.cs b/WebAPI/Models/ProcessSource.cs new file mode 100644 index 0000000..cd4589c --- /dev/null +++ b/WebAPI/Models/ProcessSource.cs @@ -0,0 +1,15 @@ +using System.ComponentModel.DataAnnotations; + +namespace WebAPI.Models +{ + public class ProcessSource + { + #region Relations + [Required] + public Guid LayerId { get; set; } + [Required] + public Guid SourceId { get; set; } + public Layer? Source { get; set; } + #endregion + } +} diff --git a/WebAPI/dataProcessors/copy.processor.cs b/WebAPI/dataProcessors/copy.processor.cs index 2304ad1..db5a7da 100644 --- a/WebAPI/dataProcessors/copy.processor.cs +++ b/WebAPI/dataProcessors/copy.processor.cs @@ -2,61 +2,26 @@ using System.Globalization; using WebAPI.Models; -namespace WebAPI.dataParsers +namespace WebAPI.dataProcessors { - public class morskaK5Parser + public class CopyProcessor { - private SpreadsheetsResource.ValuesResource googleSheetValues; private AppDbContext db; - public morskaK5Parser( - SpreadsheetsResource.ValuesResource _googleSheetValues, + public CopyProcessor( AppDbContext _db) { - googleSheetValues = _googleSheetValues; db = _db; } - public Layer parse() + public Layer process(Layer sourceLayer) { - Layer layer = new Layer(); - layer.Source = "GoogleSheet"; - - string sheetId = "1ZzndU8HjYqz5VKCcrVHBOFW8fqpYfwquclznX9q39Yk"; - - var range = "Sierpien_2023!B3:AR5"; - - var request = googleSheetValues.Get(sheetId, range); - var response = request.Execute(); - var data = response.Values; - - layer.Source = "GoogleSheet"; - layer.Number = db.Layers.Count() + 1; - layer.Name = $"L{layer.Number}-I-{data[0][1]}-{data[0][2]}/{data[0][3]}-{DateTime.Now.ToString("yyyyMMddHHmm")}"; - layer.Type = LayerType.import; - - List records = new List(); - - for (int i = 1; i < data[1].Count; i++) - { - float value; - - if ( - data[1][i].ToString()?.Length > 0 && - float.TryParse(data[2][i].ToString(), CultureInfo.GetCultureInfo("pl-PL"), out value)) - { - Record record = new Record(); - record.Id = Guid.NewGuid(); - record.Code = data[1][i].ToString(); - record.Value1 = value; - record.CreatedAt = DateTime.UtcNow; - record.ModifiedAt = DateTime.UtcNow; - records.Add(record); - }; - - } - layer.Records = records; - return layer; + Layer dataSource = this.db.Layers + .Where(x => x.ParentId == sourceLayer.Id) + .OrderByDescending(x => x.CreatedAt) + .First(); + + return null; } } } diff --git a/WebAPI/dataProcessors/deaggregation.processor.cs b/WebAPI/dataProcessors/deaggregation.processor.cs index 0632de0..c217f5f 100644 --- a/WebAPI/dataProcessors/deaggregation.processor.cs +++ b/WebAPI/dataProcessors/deaggregation.processor.cs @@ -4,11 +4,11 @@ using WebAPI.Models; namespace WebAPI.dataProcessors { - public class copyProcessor + public class deaggregationProcessor { private AppDbContext db; - public copyProcessor( + public deaggregationProcessor( AppDbContext _db) { db = _db;