From 9d1adef62918d56d1d3a022ef0b9c30d1e919734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zieli=C5=84ski?= Date: Sat, 31 May 2025 19:26:02 +0200 Subject: [PATCH] Add new Backend structure with proper .NET 8 projects --- src/Backend/DiunaBI.Core/Models/DataInbox.cs | 19 + src/Backend/DiunaBI.Core/Models/Layer.cs | 46 + src/Backend/DiunaBI.Core/Models/LogEntry.cs | 34 + .../DiunaBI.Core/Models/ProcessSource.cs | 15 + src/Backend/DiunaBI.Core/Models/QueueJob.cs | 29 + src/Backend/DiunaBI.Core/Models/Record.cs | 62 ++ src/Backend/DiunaBI.Core/Models/User.cs | 17 + .../Services/Calculations/BaseCalc.cs | 146 +++ .../Services/GoogleDriveHelper.cs | 37 + .../Services/GoogleSheetsHelper.cs | 36 + .../DiunaBI.Core/Services/ProcessHelper.cs | 213 +++++ .../DiunaBI.Database/Context/AppDbContext.cs | 34 + .../Context/DesignTimeDbContextFactory.cs | 31 + .../20221205190148_Initial.Designer.cs | 52 ++ .../Migrations/20221205190148_Initial.cs | 36 + ...1211210507_DataSetsAndDataRows.Designer.cs | 193 ++++ .../20221211210507_DataSetsAndDataRows.cs | 121 +++ .../20221219163620_RenameFields.Designer.cs | 198 ++++ .../Migrations/20221219163620_RenameFields.cs | 73 ++ ...21221165749_DataSetIdOnDataRow.Designer.cs | 200 ++++ .../20221221165749_DataSetIdOnDataRow.cs | 60 ++ .../20230106095427_RenameModels.Designer.cs | 200 ++++ .../Migrations/20230106095427_RenameModels.cs | 227 +++++ .../20230626171614_LayerType.Designer.cs | 202 +++++ .../Migrations/20230626171614_LayerType.cs | 29 + .../20230821105757_Record.Values.Designer.cs | 292 ++++++ .../20230821105757_Record.Values.cs | 339 +++++++ .../20230917110252_Layer.parent.Designer.cs | 303 +++++++ .../Migrations/20230917110252_Layer.parent.cs | 49 + .../20230918090621_ProcessSource.Designer.cs | 331 +++++++ .../20230918090621_ProcessSource.cs | 45 + .../20230918093055_TypeO.Designer.cs | 332 +++++++ .../Migrations/20230918093055_TypeO.cs | 60 ++ .../20231030142419_Record.Value32.Designer.cs | 334 +++++++ .../20231030142419_Record.Value32.cs | 28 + ...75645_Change record value type.Designer.cs | 334 +++++++ ...20240309075645_Change record value type.cs | 594 ++++++++++++ ...240703171630_AfterCodeRefactor.Designer.cs | 320 +++++++ .../20240703171630_AfterCodeRefactor.cs | 135 +++ .../20240703173337_DataInboxModel.Designer.cs | 349 +++++++ .../20240703173337_DataInboxModel.cs | 37 + .../20240825144443_QueueJobs.Designer.cs | 382 ++++++++ .../Migrations/20240825144443_QueueJobs.cs | 40 + .../20250317114722_LongerDesc1.Designer.cs | 382 ++++++++ .../Migrations/20250317114722_LongerDesc1.cs | 40 + ...250529093632_LayersIsCancelled.Designer.cs | 385 ++++++++ .../20250529093632_LayersIsCancelled.cs | 29 + .../Migrations/AppDbContextModelSnapshot.cs | 382 ++++++++ .../Exporters/googleSheet.export.cs | 123 +++ .../Importers/morska.d1.importer.cs | 108 +++ .../Importers/morska.d3.importer.cs | 75 ++ .../Importers/morska.fk2.importer.cs | 92 ++ .../Importers/morska.importer.cs | 81 ++ .../Processors/t1.r1.processor.cs | 287 ++++++ .../Processors/t1.r3.processor.cs | 192 ++++ ....MultiSourceCopySelectedCodes.processor.cs | 98 ++ ...eCopySelectedCodesYearSummary.processor.cs | 100 ++ .../t3.MultiSourceSummary.processor.cs | 178 ++++ .../t3.MultiSourceYearSummary.processor.cs | 198 ++++ .../Processors/t3.SingleSource.processor.cs | 141 +++ .../t3.SourceYearSummary.processor.cs | 102 +++ .../Processors/t4.SingleSource.processor.cs | 95 ++ .../Processors/t4.r2.processor.cs | 362 ++++++++ .../Processors/t5.LastValues.processor.cs | 95 ++ .../Controllers/AdminController.cs | 28 + .../Controllers/AuthController.cs | 60 ++ .../Controllers/DataInboxController.cs | 168 ++++ .../Controllers/LayersController.cs | 857 ++++++++++++++++++ .../Controllers/LogsController.cs | 46 + .../Controllers/PingController.cs | 25 + src/Backend/DiunaBI.WebAPI/Program.cs | 100 ++ .../Properties/launchSettings.json | 23 + .../client_secrets.Development.json | 12 + .../DiunaBI.WebAPI/client_secrets.json | 12 + .../diunabi-admin-firebase.json | 13 + 75 files changed, 11503 insertions(+) create mode 100644 src/Backend/DiunaBI.Core/Models/DataInbox.cs create mode 100644 src/Backend/DiunaBI.Core/Models/Layer.cs create mode 100644 src/Backend/DiunaBI.Core/Models/LogEntry.cs create mode 100644 src/Backend/DiunaBI.Core/Models/ProcessSource.cs create mode 100644 src/Backend/DiunaBI.Core/Models/QueueJob.cs create mode 100644 src/Backend/DiunaBI.Core/Models/Record.cs create mode 100644 src/Backend/DiunaBI.Core/Models/User.cs create mode 100644 src/Backend/DiunaBI.Core/Services/Calculations/BaseCalc.cs create mode 100644 src/Backend/DiunaBI.Core/Services/GoogleDriveHelper.cs create mode 100644 src/Backend/DiunaBI.Core/Services/GoogleSheetsHelper.cs create mode 100644 src/Backend/DiunaBI.Core/Services/ProcessHelper.cs create mode 100644 src/Backend/DiunaBI.Database/Context/AppDbContext.cs create mode 100644 src/Backend/DiunaBI.Database/Context/DesignTimeDbContextFactory.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20221205190148_Initial.Designer.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20221205190148_Initial.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20221211210507_DataSetsAndDataRows.Designer.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20221211210507_DataSetsAndDataRows.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20221219163620_RenameFields.Designer.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20221219163620_RenameFields.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20221221165749_DataSetIdOnDataRow.Designer.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20221221165749_DataSetIdOnDataRow.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20230106095427_RenameModels.Designer.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20230106095427_RenameModels.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20230626171614_LayerType.Designer.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20230626171614_LayerType.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20230821105757_Record.Values.Designer.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20230821105757_Record.Values.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20230917110252_Layer.parent.Designer.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20230917110252_Layer.parent.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20230918090621_ProcessSource.Designer.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20230918090621_ProcessSource.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20230918093055_TypeO.Designer.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20230918093055_TypeO.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20231030142419_Record.Value32.Designer.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20231030142419_Record.Value32.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20240309075645_Change record value type.Designer.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20240309075645_Change record value type.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20240703171630_AfterCodeRefactor.Designer.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20240703171630_AfterCodeRefactor.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20240703173337_DataInboxModel.Designer.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20240703173337_DataInboxModel.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20240825144443_QueueJobs.Designer.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20240825144443_QueueJobs.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20250317114722_LongerDesc1.Designer.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20250317114722_LongerDesc1.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20250529093632_LayersIsCancelled.Designer.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/20250529093632_LayersIsCancelled.cs create mode 100644 src/Backend/DiunaBI.Database/Migrations/AppDbContextModelSnapshot.cs create mode 100644 src/Backend/DiunaBI.Plugins.Morska/Exporters/googleSheet.export.cs create mode 100644 src/Backend/DiunaBI.Plugins.Morska/Importers/morska.d1.importer.cs create mode 100644 src/Backend/DiunaBI.Plugins.Morska/Importers/morska.d3.importer.cs create mode 100644 src/Backend/DiunaBI.Plugins.Morska/Importers/morska.fk2.importer.cs create mode 100644 src/Backend/DiunaBI.Plugins.Morska/Importers/morska.importer.cs create mode 100644 src/Backend/DiunaBI.Plugins.Morska/Processors/t1.r1.processor.cs create mode 100644 src/Backend/DiunaBI.Plugins.Morska/Processors/t1.r3.processor.cs create mode 100644 src/Backend/DiunaBI.Plugins.Morska/Processors/t3.MultiSourceCopySelectedCodes.processor.cs create mode 100644 src/Backend/DiunaBI.Plugins.Morska/Processors/t3.MultiSourceCopySelectedCodesYearSummary.processor.cs create mode 100644 src/Backend/DiunaBI.Plugins.Morska/Processors/t3.MultiSourceSummary.processor.cs create mode 100644 src/Backend/DiunaBI.Plugins.Morska/Processors/t3.MultiSourceYearSummary.processor.cs create mode 100644 src/Backend/DiunaBI.Plugins.Morska/Processors/t3.SingleSource.processor.cs create mode 100644 src/Backend/DiunaBI.Plugins.Morska/Processors/t3.SourceYearSummary.processor.cs create mode 100644 src/Backend/DiunaBI.Plugins.Morska/Processors/t4.SingleSource.processor.cs create mode 100644 src/Backend/DiunaBI.Plugins.Morska/Processors/t4.r2.processor.cs create mode 100644 src/Backend/DiunaBI.Plugins.Morska/Processors/t5.LastValues.processor.cs create mode 100644 src/Backend/DiunaBI.WebAPI/Controllers/AdminController.cs create mode 100644 src/Backend/DiunaBI.WebAPI/Controllers/AuthController.cs create mode 100644 src/Backend/DiunaBI.WebAPI/Controllers/DataInboxController.cs create mode 100644 src/Backend/DiunaBI.WebAPI/Controllers/LayersController.cs create mode 100644 src/Backend/DiunaBI.WebAPI/Controllers/LogsController.cs create mode 100644 src/Backend/DiunaBI.WebAPI/Controllers/PingController.cs create mode 100644 src/Backend/DiunaBI.WebAPI/Program.cs create mode 100644 src/Backend/DiunaBI.WebAPI/Properties/launchSettings.json create mode 100644 src/Backend/DiunaBI.WebAPI/client_secrets.Development.json create mode 100644 src/Backend/DiunaBI.WebAPI/client_secrets.json create mode 100644 src/Backend/DiunaBI.WebAPI/diunabi-admin-firebase.json diff --git a/src/Backend/DiunaBI.Core/Models/DataInbox.cs b/src/Backend/DiunaBI.Core/Models/DataInbox.cs new file mode 100644 index 0000000..bfea179 --- /dev/null +++ b/src/Backend/DiunaBI.Core/Models/DataInbox.cs @@ -0,0 +1,19 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace DiunaBI.Core.Models; + +public class DataInbox +{ + #region Properties + [Key] + public Guid Id { get; set; } + [StringLength(50)] + public required string Name { get; init; } + [StringLength(50)] + public required string Source { get; set; } + [StringLength(int.MaxValue)] + public required string Data { get; init; } + public DateTime CreatedAt { get; set; } + #endregion +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Core/Models/Layer.cs b/src/Backend/DiunaBI.Core/Models/Layer.cs new file mode 100644 index 0000000..ca44018 --- /dev/null +++ b/src/Backend/DiunaBI.Core/Models/Layer.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; + +namespace DiunaBI.Core.Models; + +public enum LayerType +{ + Import, + Processed, + Administration, + Dictionary, +} +public class Layer +{ + #region Properties + [Key] + public Guid Id { get; init; } + [Required] + public int Number { get; init; } + [Required] + [MaxLength(50)] + public string? Name { get; set; } + [Required] + public LayerType Type { get; init; } + [Required] + public DateTime CreatedAt { get; set; } + [Required] + public DateTime ModifiedAt { get; set; } + [Required] + public bool IsDeleted { get; init; } = false; + [Required] + public bool IsCancelled { get; init; } = false; + #endregion + #region Relations + public ICollection? Records { get; init; } + [Required] + public Guid CreatedById { get; set; } + public User? CreatedBy { get; init; } + [Required] + public Guid ModifiedById { get; set; } + public User? ModifiedBy { get; init; } + public Guid? ParentId { get; init; } + public Layer? Parent { get; init; } + #endregion +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Core/Models/LogEntry.cs b/src/Backend/DiunaBI.Core/Models/LogEntry.cs new file mode 100644 index 0000000..e9aa3e9 --- /dev/null +++ b/src/Backend/DiunaBI.Core/Models/LogEntry.cs @@ -0,0 +1,34 @@ +using System; + +namespace DiunaBI.Core.Models; + +public enum LogEntryType +{ + Info, + Warning, + Error +} +public enum LogType +{ + Import, + Backup, + Process, + PowerBi, + DataInbox, + Queue +} + +public enum LogInstance +{ + Morska +} +public class LogEntry +{ + public LogType LogType { get; init; } + public LogEntryType Type { get; init; } + public string? Message { get; init; } + public string? Title { get; init; } + public DateTime CreatedAt { get; init; } + public Guid SessionId { get; set; } + public LogInstance Instance { get; set; } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Core/Models/ProcessSource.cs b/src/Backend/DiunaBI.Core/Models/ProcessSource.cs new file mode 100644 index 0000000..59d8c65 --- /dev/null +++ b/src/Backend/DiunaBI.Core/Models/ProcessSource.cs @@ -0,0 +1,15 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace DiunaBI.Core.Models; + +public class ProcessSource +{ + #region Relations + [Required] + public Guid LayerId { get; init; } + [Required] + public Guid SourceId { get; init; } + public Layer? Source { get; init; } + #endregion +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Core/Models/QueueJob.cs b/src/Backend/DiunaBI.Core/Models/QueueJob.cs new file mode 100644 index 0000000..54f5fdb --- /dev/null +++ b/src/Backend/DiunaBI.Core/Models/QueueJob.cs @@ -0,0 +1,29 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace DiunaBI.Core.Models; + +public enum JobStatus +{ + New, + Failed, + Success +} + +public enum JobType +{ + ImportWorker, + ProcessWorker +} + +public class QueueJob +{ + [Key] public Guid Id { get; set; } + [Required] public Guid LayerId { get; set; } + [Required] public int Attempts { get; set; } + [Required] public JobStatus Status { get; set; } = JobStatus.New; + [Required] public JobType Type { get; set; } = JobType.ImportWorker; + public string Message { get; set; } = string.Empty; + [Required] public DateTime CreatedAt { get; set; } = DateTime.UtcNow; + [Required] public DateTime ModifiedAt { get; set; } = DateTime.UtcNow; +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Core/Models/Record.cs b/src/Backend/DiunaBI.Core/Models/Record.cs new file mode 100644 index 0000000..f791f06 --- /dev/null +++ b/src/Backend/DiunaBI.Core/Models/Record.cs @@ -0,0 +1,62 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace DiunaBI.Core.Models; + +public class Record +{ + #region Properties + [Key] + public Guid Id { get; set; } + [Required] + [StringLength(50)] + public string? Code { get; init; } + public double? Value1 { get; set; } + public double? Value2 { get; set; } + public double? Value3 { get; set; } + public double? Value4 { get; set; } + public double? Value5 { get; set; } + public double? Value6 { get; set; } + public double? Value7 { get; set; } + public double? Value8 { get; set; } + public double? Value9 { get; set; } + public double? Value10 { get; set; } + public double? Value11 { get; set; } + public double? Value12 { get; set; } + public double? Value13 { get; set; } + public double? Value14 { get; set; } + public double? Value15 { get; set; } + public double? Value16 { get; set; } + public double? Value17 { get; set; } + public double? Value18 { get; set; } + public double? Value19 { get; set; } + public double? Value20 { get; set; } + public double? Value21 { get; set; } + public double? Value22 { get; set; } + public double? Value23 { get; set; } + public double? Value24 { get; set; } + public double? Value25 { get; set; } + public double? Value26 { get; set; } + public double? Value27 { get; set; } + public double? Value28 { get; set; } + public double? Value29 { get; set; } + public double? Value30 { get; set; } + public double? Value31 { get; set; } + public double? Value32 { get; set; } + //Description fields + [StringLength(10000)] + public string? Desc1 { get; init; } + public DateTime CreatedAt { get; set; } + public DateTime ModifiedAt { get; set; } + public bool IsDeleted { get; init; } + #endregion + #region Relations + [Required] + public Guid CreatedById { get; set; } + public User? CreatedBy { get; init; } + [Required] + public Guid ModifiedById { get; set; } + public User? ModifiedBy { get; init; } + public Guid LayerId { get; set; } + #endregion +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Core/Models/User.cs b/src/Backend/DiunaBI.Core/Models/User.cs new file mode 100644 index 0000000..ce23280 --- /dev/null +++ b/src/Backend/DiunaBI.Core/Models/User.cs @@ -0,0 +1,17 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace DiunaBI.Core.Models; + +public class User +{ + #region Properties + [Key] + public Guid Id { get; init; } + [StringLength(50)] + public string? Email { get; init; } + [StringLength(50)] + public string? UserName { get; init; } + public DateTime CreatedAt { get; init; } + #endregion +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Core/Services/Calculations/BaseCalc.cs b/src/Backend/DiunaBI.Core/Services/Calculations/BaseCalc.cs new file mode 100644 index 0000000..0ae6397 --- /dev/null +++ b/src/Backend/DiunaBI.Core/Services/Calculations/BaseCalc.cs @@ -0,0 +1,146 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using AngouriMath; +using DiunaBI.Core.Models; + +namespace DiunaBI.Core.Services.Calculations; + +public class BaseCalc +{ + public string Expression { get; } + private string ResultCode { get; set; } + private string Formula { get; } + + public BaseCalc(string expression) + { + Expression = expression; + Formula = Expression.Split("=")[1]; + ResultCode = Expression.Split("=")[0]; + } + + public bool IsFormulaCorrect() + { + // check left side of expression + if (!ResultCode.StartsWith('[') || !ResultCode.EndsWith(']')) + { + return false; + } + + if (!ResultCode.Substring(1, ResultCode.Length - 2).All(char.IsDigit)) + { + return false; + } + + ResultCode = ResultCode.Substring(1, ResultCode.Length - 2); + + // check right side of expression + return !string.IsNullOrEmpty(Formula) && + Formula.All(c => char.IsDigit(c) || c == '[' || c == ']' || c == '+' || c == '-'); + } + + public Record CalculateT3(List records) + { + var resultCode = ResultCode; + { + var result = new Record + { + Id = Guid.NewGuid(), + Code = resultCode, + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow + }; + var codes = GetCodes(); + var ingredients = new List(); + foreach (var code in codes) + { + var ingredient = records.FirstOrDefault(r => r.Code == code); + if (ingredient == null) + { + throw new Exception($"Record for code {code} not found."); + } + + ingredients.Add(ingredient); + } + + for (var i = 1; i <= 32; i++) + { + var formula = ingredients.Aggregate(Formula, + (current, ingredient) => current.Replace($"[{ingredient.Code}]", + ProcessHelper.GetValue(ingredient, i)?.ToString(CultureInfo.InvariantCulture))); + if (formula.Contains('[')) + { + throw new Exception($"Not all placeholders were replaced. Value{i} [{formula}]"); + } + + Entity expr = formula; + ProcessHelper.SetValue(result, i, (double)expr.EvalNumerical()); + } + + return result; + } + } + + public Record CalculateT1(List records) + { + var resultCode = ResultCode; + { + var result = new Record + { + Id = Guid.NewGuid(), + Code = resultCode, + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow + }; + var codes = GetCodes(); + var ingredients = new List(); + foreach (var code in codes) + { + var ingredient = records.FirstOrDefault(r => r.Code == code); + if (ingredient == null) + { + throw new Exception($"Record for code {code} not found."); + } + + ingredients.Add(ingredient); + } + + + var formula = ingredients.Aggregate(Formula, + (current, ingredient) => current.Replace($"[{ingredient.Code}]", + ProcessHelper.GetValue(ingredient, 32)?.ToString(CultureInfo.InvariantCulture))); + if (formula.Contains('[')) + { + throw new Exception($"Not all placeholders were replaced. Value{1} [{formula}]"); + } + + Entity expr = formula; + ProcessHelper.SetValue(result, 32, (double)expr.EvalNumerical()); + + return result; + } + } + + private List GetCodes() + { + var codes = new List(); + var endIndex = -1; + + while (true) + { + var startIndex = Formula.IndexOf("[", endIndex + 1, StringComparison.CurrentCulture); + endIndex = Formula.IndexOf("]", startIndex + 1, StringComparison.CurrentCulture); + + if (startIndex == -1 || endIndex == -1) + { + break; + } + + var valueCode = Formula.Substring(startIndex + 1, endIndex - startIndex - 1); + codes.Add(valueCode); + } + + return codes; + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Core/Services/GoogleDriveHelper.cs b/src/Backend/DiunaBI.Core/Services/GoogleDriveHelper.cs new file mode 100644 index 0000000..386bda1 --- /dev/null +++ b/src/Backend/DiunaBI.Core/Services/GoogleDriveHelper.cs @@ -0,0 +1,37 @@ +using Google.Apis.Auth.OAuth2; +using Google.Apis.Drive.v3; +using Google.Apis.Services; +using System.IO; + +namespace DiunaBI.Core.Services; + +public class GoogleDriveHelper +{ + public DriveService? Service { get; private set; } + private const string ApplicationName = "Diuna"; + private static readonly string[] Scopes = [DriveService.Scope.Drive]; + public GoogleDriveHelper() + { + InitializeService(); + } + private void InitializeService() + { + var credential = GetCredentialsFromFile(); + Service = new DriveService(new BaseClientService.Initializer + { + HttpClientInitializer = credential, + ApplicationName = ApplicationName + }); + } + private static GoogleCredential GetCredentialsFromFile() + { + // ReSharper disable once RedundantAssignment + var fileName = "client_secrets.json"; +#if DEBUG + fileName = "client_secrets.Development.json"; +#endif + using var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read); + var credential = GoogleCredential.FromStream(stream).CreateScoped(Scopes); + return credential; + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Core/Services/GoogleSheetsHelper.cs b/src/Backend/DiunaBI.Core/Services/GoogleSheetsHelper.cs new file mode 100644 index 0000000..f7b4a2d --- /dev/null +++ b/src/Backend/DiunaBI.Core/Services/GoogleSheetsHelper.cs @@ -0,0 +1,36 @@ +using Google.Apis.Auth.OAuth2; +using Google.Apis.Services; +using Google.Apis.Sheets.v4; +using System.IO; + +namespace DiunaBI.Core.Services; + +public class GoogleSheetsHelper +{ + public SheetsService? Service { get; private set; } + private const string ApplicationName = "Diuna"; + private static readonly string[] Scopes = [SheetsService.Scope.Spreadsheets]; + public GoogleSheetsHelper() + { + InitializeService(); + } + private void InitializeService() + { + var credential = GetCredentialsFromFile(); + Service = new SheetsService(new BaseClientService.Initializer + { + HttpClientInitializer = credential, + ApplicationName = ApplicationName + }); + } + private static GoogleCredential GetCredentialsFromFile() + { + var fileName = "client_secrets.json"; +#if DEBUG + fileName = "client_secrets.Development.json"; +#endif + using var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read); + var credential = GoogleCredential.FromStream(stream).CreateScoped(Scopes); + return credential; + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Core/Services/ProcessHelper.cs b/src/Backend/DiunaBI.Core/Services/ProcessHelper.cs new file mode 100644 index 0000000..46c7b0c --- /dev/null +++ b/src/Backend/DiunaBI.Core/Services/ProcessHelper.cs @@ -0,0 +1,213 @@ +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using DiunaBI.Core.Models; + +namespace DiunaBI.Core.Services; +public static class ProcessHelper +{ + public static void SetValue(Record record, int number, double? value) + { + value = (double)Math.Round((decimal)(value ?? 0), 2); + switch (number) + { + case 1: + record.Value1 = value; + break; + case 2: + record.Value2 = value; + break; + case 3: + record.Value3 = value; + break; + case 4: + record.Value4 = value; + break; + case 5: + record.Value5 = value; + break; + case 6: + record.Value6 = value; + break; + case 7: + record.Value7 = value; + break; + case 8: + record.Value8 = value; + break; + case 9: + record.Value9 = value; + break; + case 10: + record.Value10 = value; + break; + case 11: + record.Value11 = value; + break; + case 12: + record.Value12 = value; + break; + case 13: + record.Value13 = value; + break; + case 14: + record.Value14 = value; + break; + case 15: + record.Value15 = value; + break; + case 16: + record.Value16 = value; + break; + case 17: + record.Value17 = value; + break; + case 18: + record.Value18 = value; + break; + case 19: + record.Value19 = value; + break; + case 20: + record.Value20 = value; + break; + case 21: + record.Value21 = value; + break; + case 22: + record.Value22 = value; + break; + case 23: + record.Value23 = value; + break; + case 24: + record.Value24 = value; + break; + case 25: + record.Value25 = value; + break; + case 26: + record.Value26 = value; + break; + case 27: + record.Value27 = value; + break; + case 28: + record.Value28 = value; + break; + case 29: + record.Value29 = value; + break; + case 30: + record.Value30 = value; + break; + case 31: + record.Value31 = value; + break; + case 32: + record.Value32 = value; + break; + } + } + public static double? GetValue(Record record, int number) + { + return number switch + { + 1 => record.Value1, + 2 => record.Value2, + 3 => record.Value3, + 4 => record.Value4, + 5 => record.Value5, + 6 => record.Value6, + 7 => record.Value7, + 8 => record.Value8, + 9 => record.Value9, + 10 => record.Value10, + 11 => record.Value11, + 12 => record.Value12, + 13 => record.Value13, + 14 => record.Value14, + 15 => record.Value15, + 16 => record.Value16, + 17 => record.Value17, + 18 => record.Value18, + 19 => record.Value19, + 20 => record.Value20, + 21 => record.Value21, + 22 => record.Value22, + 23 => record.Value23, + 24 => record.Value24, + 25 => record.Value25, + 26 => record.Value26, + 27 => record.Value27, + 28 => record.Value28, + 29 => record.Value29, + 30 => record.Value30, + 31 => record.Value31, + 32 => record.Value32, + _ => null + }; + } + public static List ParseCodes(string codes) + { + var codesList = new List(); + foreach (var code in codes.Split(';')) + { + var range = code.Split('-'); + switch (range.Length) + { + case 1: + codesList.Add(int.Parse(range[0])); + break; + case 2: + { + for (var i = int.Parse(range[0]); i <= int.Parse(range[1]); i++) + { + codesList.Add(i); + } + + break; + } + default: + throw new Exception($"Invalid code range: {code}"); + } + } + return codesList; + } + public static string? ExtractMonthFromLayerName(string layerName) + { + string pattern = @"L\d+-P-\d{4}/(\d{2})-"; + var match = Regex.Match(layerName, pattern); + if (match.Success && match.Groups.Count > 1) + { + return match.Groups[1].Value; + } + return null; + } + + public static string GetSheetName(int month, int year) + { + if (month < 1 || month > 12) + { + throw new ArgumentOutOfRangeException(nameof(month), "Month must be between 1 and 12."); + } + + var polishMonths = new[] + { + "Styczen", + "Luty", + "Marzec", + "Kwiecien", + "Maj", + "Czerwiec", + "Lipiec", + "Sierpien", + "Wrzesien", + "Pazdziernik", + "Listopad", + "Grudzien" + }; + var monthName = polishMonths[month - 1]; + return $"{monthName}_{year}"; + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Database/Context/AppDbContext.cs b/src/Backend/DiunaBI.Database/Context/AppDbContext.cs new file mode 100644 index 0000000..3b5b0e0 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Context/AppDbContext.cs @@ -0,0 +1,34 @@ +using Microsoft.EntityFrameworkCore; +using DiunaBI.Core.Models; +using Microsoft.Extensions.Logging; + +namespace DiunaBI.Database.Context; + +public class AppDbContext(DbContextOptions options) : DbContext(options) +{ + public DbSet Users { get; init; } + public DbSet Layers { get; init; } + public DbSet Records { get; init; } + public DbSet ProcessSources { get; init; } + public DbSet DataInbox { get; init; } + public DbSet QueueJobs { get; init; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().HasKey(x => new + { + x.LayerId, + x.SourceId + }); + } + + private static readonly LoggerFactory MyLoggerFactory = + new(new[] { + new Microsoft.Extensions.Logging.Debug.DebugLoggerProvider() + }); + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseLoggerFactory(MyLoggerFactory); + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Database/Context/DesignTimeDbContextFactory.cs b/src/Backend/DiunaBI.Database/Context/DesignTimeDbContextFactory.cs new file mode 100644 index 0000000..12add8d --- /dev/null +++ b/src/Backend/DiunaBI.Database/Context/DesignTimeDbContextFactory.cs @@ -0,0 +1,31 @@ +using System; +using System.IO; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Design; +using Microsoft.Extensions.Configuration; + +namespace DiunaBI.Database.Context; + +public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory +{ + public AppDbContext CreateDbContext(string[] args) + { + var configuration = new ConfigurationBuilder() + .SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "../DiunaBI.WebAPI")) // ✅ Poprawna ścieżka + .AddJsonFile("appsettings.json", optional: false) + .AddJsonFile("appsettings.Development.json", optional: true) + .Build(); + + var optionsBuilder = new DbContextOptionsBuilder(); + + var connectionString = configuration.GetConnectionString("DefaultConnection"); + if (string.IsNullOrEmpty(connectionString)) + { + throw new InvalidOperationException("Connection string 'DefaultConnection' not found in appsettings.json"); + } + + optionsBuilder.UseSqlServer(connectionString); + + return new AppDbContext(optionsBuilder.Options); + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Database/Migrations/20221205190148_Initial.Designer.cs b/src/Backend/DiunaBI.Database/Migrations/20221205190148_Initial.Designer.cs new file mode 100644 index 0000000..e22e413 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20221205190148_Initial.Designer.cs @@ -0,0 +1,52 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20221205190148_Initial")] + partial class Initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + 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"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20221205190148_Initial.cs b/src/Backend/DiunaBI.Database/Migrations/20221205190148_Initial.cs new file mode 100644 index 0000000..c44a6ff --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20221205190148_Initial.cs @@ -0,0 +1,36 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + /// + public partial class Initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: true), + UserName = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: true), + CreatedAt = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Users"); + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20221211210507_DataSetsAndDataRows.Designer.cs b/src/Backend/DiunaBI.Database/Migrations/20221211210507_DataSetsAndDataRows.Designer.cs new file mode 100644 index 0000000..d1f6ba6 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20221211210507_DataSetsAndDataRows.Designer.cs @@ -0,0 +1,193 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20221211210507_DataSetsAndDataRows")] + partial class DataSetsAndDataRows + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("WebAPI.Models.DataRow", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedById") + .HasColumnType("uniqueidentifier"); + + b.Property("DataSetId") + .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("MPK") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Value") + .HasColumnType("real"); + + b.HasKey("Id"); + + b.HasIndex("CreatedById"); + + b.HasIndex("DataSetId"); + + b.HasIndex("ModifiedById"); + + b.ToTable("DataRows"); + }); + + modelBuilder.Entity("WebAPI.Models.DataSet", 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") + .HasColumnType("nvarchar(max)"); + + b.Property("Number") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("CreatedById"); + + b.HasIndex("ModifiedById"); + + b.ToTable("DataSets"); + }); + + 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.DataRow", b => + { + b.HasOne("WebAPI.Models.User", "CreatedBy") + .WithMany() + .HasForeignKey("CreatedById") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("WebAPI.Models.DataSet", null) + .WithMany("DataRows") + .HasForeignKey("DataSetId"); + + b.HasOne("WebAPI.Models.User", "ModifiedBy") + .WithMany() + .HasForeignKey("ModifiedById") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CreatedBy"); + + b.Navigation("ModifiedBy"); + }); + + modelBuilder.Entity("WebAPI.Models.DataSet", 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.Navigation("CreatedBy"); + + b.Navigation("ModifiedBy"); + }); + + modelBuilder.Entity("WebAPI.Models.DataSet", b => + { + b.Navigation("DataRows"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20221211210507_DataSetsAndDataRows.cs b/src/Backend/DiunaBI.Database/Migrations/20221211210507_DataSetsAndDataRows.cs new file mode 100644 index 0000000..4827087 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20221211210507_DataSetsAndDataRows.cs @@ -0,0 +1,121 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + /// + public partial class DataSetsAndDataRows : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "DataSets", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + Number = table.Column(type: "nvarchar(max)", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: true), + CreatedAt = table.Column(type: "datetime2", nullable: false), + ModifiedAt = table.Column(type: "datetime2", nullable: false), + IsDeleted = table.Column(type: "bit", nullable: false), + CreatedById = table.Column(type: "uniqueidentifier", nullable: false), + ModifiedById = table.Column(type: "uniqueidentifier", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_DataSets", x => x.Id); + table.ForeignKey( + name: "FK_DataSets_Users_CreatedById", + column: x => x.CreatedById, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.NoAction); + table.ForeignKey( + name: "FK_DataSets_Users_ModifiedById", + column: x => x.ModifiedById, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.NoAction); + }); + + migrationBuilder.CreateTable( + name: "DataRows", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + MPK = table.Column(type: "nvarchar(max)", nullable: false), + Value = table.Column(type: "real", nullable: false), + Desc1 = table.Column(type: "nvarchar(max)", nullable: true), + Desc2 = table.Column(type: "nvarchar(max)", nullable: true), + Desc3 = table.Column(type: "nvarchar(max)", nullable: true), + Desc4 = table.Column(type: "nvarchar(max)", nullable: true), + Desc5 = table.Column(type: "nvarchar(max)", nullable: true), + CreatedAt = table.Column(type: "datetime2", nullable: false), + ModifiedAt = table.Column(type: "datetime2", nullable: false), + IsDeleted = table.Column(type: "bit", nullable: false), + CreatedById = table.Column(type: "uniqueidentifier", nullable: false), + ModifiedById = table.Column(type: "uniqueidentifier", nullable: false), + DataSetId = table.Column(type: "uniqueidentifier", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_DataRows", x => x.Id); + table.ForeignKey( + name: "FK_DataRows_DataSets_DataSetId", + column: x => x.DataSetId, + principalTable: "DataSets", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_DataRows_Users_CreatedById", + column: x => x.CreatedById, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.NoAction); + table.ForeignKey( + name: "FK_DataRows_Users_ModifiedById", + column: x => x.ModifiedById, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.NoAction); + }); + + migrationBuilder.CreateIndex( + name: "IX_DataRows_CreatedById", + table: "DataRows", + column: "CreatedById"); + + migrationBuilder.CreateIndex( + name: "IX_DataRows_DataSetId", + table: "DataRows", + column: "DataSetId"); + + migrationBuilder.CreateIndex( + name: "IX_DataRows_ModifiedById", + table: "DataRows", + column: "ModifiedById"); + + migrationBuilder.CreateIndex( + name: "IX_DataSets_CreatedById", + table: "DataSets", + column: "CreatedById"); + + migrationBuilder.CreateIndex( + name: "IX_DataSets_ModifiedById", + table: "DataSets", + column: "ModifiedById"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "DataRows"); + + migrationBuilder.DropTable( + name: "DataSets"); + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20221219163620_RenameFields.Designer.cs b/src/Backend/DiunaBI.Database/Migrations/20221219163620_RenameFields.Designer.cs new file mode 100644 index 0000000..3ca66f9 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20221219163620_RenameFields.Designer.cs @@ -0,0 +1,198 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20221219163620_RenameFields")] + partial class RenameFields + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("WebAPI.Models.DataRow", 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("DataSetId") + .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("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Value") + .HasColumnType("real"); + + b.HasKey("Id"); + + b.HasIndex("CreatedById"); + + b.HasIndex("DataSetId"); + + b.HasIndex("ModifiedById"); + + b.ToTable("DataRows"); + }); + + modelBuilder.Entity("WebAPI.Models.DataSet", 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") + .IsRequired() + .HasColumnType("int"); + + b.Property("Source") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("CreatedById"); + + b.HasIndex("ModifiedById"); + + b.ToTable("DataSets"); + }); + + 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.DataRow", b => + { + b.HasOne("WebAPI.Models.User", "CreatedBy") + .WithMany() + .HasForeignKey("CreatedById") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("WebAPI.Models.DataSet", null) + .WithMany("DataRows") + .HasForeignKey("DataSetId"); + + b.HasOne("WebAPI.Models.User", "ModifiedBy") + .WithMany() + .HasForeignKey("ModifiedById") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CreatedBy"); + + b.Navigation("ModifiedBy"); + }); + + modelBuilder.Entity("WebAPI.Models.DataSet", 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.Navigation("CreatedBy"); + + b.Navigation("ModifiedBy"); + }); + + modelBuilder.Entity("WebAPI.Models.DataSet", b => + { + b.Navigation("DataRows"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20221219163620_RenameFields.cs b/src/Backend/DiunaBI.Database/Migrations/20221219163620_RenameFields.cs new file mode 100644 index 0000000..2570d7f --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20221219163620_RenameFields.cs @@ -0,0 +1,73 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + /// + public partial class RenameFields : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "MPK", + table: "DataRows", + newName: "Code"); + + migrationBuilder.AlterColumn( + name: "Number", + table: "DataSets", + type: "int", + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(max)"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "DataSets", + type: "nvarchar(max)", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.AddColumn( + name: "Source", + table: "DataSets", + type: "nvarchar(max)", + nullable: false, + defaultValue: ""); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Source", + table: "DataSets"); + + migrationBuilder.RenameColumn( + name: "Code", + table: "DataRows", + newName: "MPK"); + + migrationBuilder.AlterColumn( + name: "Number", + table: "DataSets", + type: "nvarchar(max)", + nullable: false, + oldClrType: typeof(int), + oldType: "int"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "DataSets", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)"); + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20221221165749_DataSetIdOnDataRow.Designer.cs b/src/Backend/DiunaBI.Database/Migrations/20221221165749_DataSetIdOnDataRow.Designer.cs new file mode 100644 index 0000000..e151324 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20221221165749_DataSetIdOnDataRow.Designer.cs @@ -0,0 +1,200 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20221221165749_DataSetIdOnDataRow")] + partial class DataSetIdOnDataRow + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("WebAPI.Models.DataRow", 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("DataSetId") + .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("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Value") + .HasColumnType("real"); + + b.HasKey("Id"); + + b.HasIndex("CreatedById"); + + b.HasIndex("DataSetId"); + + b.HasIndex("ModifiedById"); + + b.ToTable("DataRows"); + }); + + modelBuilder.Entity("WebAPI.Models.DataSet", 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") + .IsRequired() + .HasColumnType("int"); + + b.Property("Source") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("CreatedById"); + + b.HasIndex("ModifiedById"); + + b.ToTable("DataSets"); + }); + + 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.DataRow", b => + { + b.HasOne("WebAPI.Models.User", "CreatedBy") + .WithMany() + .HasForeignKey("CreatedById") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("WebAPI.Models.DataSet", null) + .WithMany("DataRows") + .HasForeignKey("DataSetId") + .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.DataSet", 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.Navigation("CreatedBy"); + + b.Navigation("ModifiedBy"); + }); + + modelBuilder.Entity("WebAPI.Models.DataSet", b => + { + b.Navigation("DataRows"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20221221165749_DataSetIdOnDataRow.cs b/src/Backend/DiunaBI.Database/Migrations/20221221165749_DataSetIdOnDataRow.cs new file mode 100644 index 0000000..6a23fba --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20221221165749_DataSetIdOnDataRow.cs @@ -0,0 +1,60 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + /// + public partial class DataSetIdOnDataRow : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_DataRows_DataSets_DataSetId", + table: "DataRows"); + + migrationBuilder.AlterColumn( + name: "DataSetId", + table: "DataRows", + type: "uniqueidentifier", + nullable: false, + defaultValue: new Guid("00000000-0000-0000-0000-000000000000"), + oldClrType: typeof(Guid), + oldType: "uniqueidentifier", + oldNullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_DataRows_DataSets_DataSetId", + table: "DataRows", + column: "DataSetId", + principalTable: "DataSets", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_DataRows_DataSets_DataSetId", + table: "DataRows"); + + migrationBuilder.AlterColumn( + name: "DataSetId", + table: "DataRows", + type: "uniqueidentifier", + nullable: true, + oldClrType: typeof(Guid), + oldType: "uniqueidentifier"); + + migrationBuilder.AddForeignKey( + name: "FK_DataRows_DataSets_DataSetId", + table: "DataRows", + column: "DataSetId", + principalTable: "DataSets", + principalColumn: "Id"); + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20230106095427_RenameModels.Designer.cs b/src/Backend/DiunaBI.Database/Migrations/20230106095427_RenameModels.Designer.cs new file mode 100644 index 0000000..a48de5a --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20230106095427_RenameModels.Designer.cs @@ -0,0 +1,200 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20230106095427_RenameModels")] + partial class RenameModels + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.0") + .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") + .IsRequired() + .HasColumnType("int"); + + b.Property("Source") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("CreatedById"); + + b.HasIndex("ModifiedById"); + + 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("Value") + .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.Navigation("CreatedBy"); + + b.Navigation("ModifiedBy"); + }); + + 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/src/Backend/DiunaBI.Database/Migrations/20230106095427_RenameModels.cs b/src/Backend/DiunaBI.Database/Migrations/20230106095427_RenameModels.cs new file mode 100644 index 0000000..205fde2 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20230106095427_RenameModels.cs @@ -0,0 +1,227 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + /// + public partial class RenameModels : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "DataRows"); + + migrationBuilder.DropTable( + name: "DataSets"); + + migrationBuilder.CreateTable( + name: "Layers", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + Number = table.Column(type: "int", nullable: false), + Source = table.Column(type: "nvarchar(max)", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: false), + CreatedAt = table.Column(type: "datetime2", nullable: false), + ModifiedAt = table.Column(type: "datetime2", nullable: false), + IsDeleted = table.Column(type: "bit", nullable: false), + CreatedById = table.Column(type: "uniqueidentifier", nullable: false), + ModifiedById = table.Column(type: "uniqueidentifier", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Layers", x => x.Id); + table.ForeignKey( + name: "FK_Layers_Users_CreatedById", + column: x => x.CreatedById, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.NoAction); + table.ForeignKey( + name: "FK_Layers_Users_ModifiedById", + column: x => x.ModifiedById, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.NoAction); + }); + + migrationBuilder.CreateTable( + name: "Records", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + Code = table.Column(type: "nvarchar(max)", nullable: false), + Value = table.Column(type: "real", nullable: false), + Desc1 = table.Column(type: "nvarchar(max)", nullable: true), + Desc2 = table.Column(type: "nvarchar(max)", nullable: true), + Desc3 = table.Column(type: "nvarchar(max)", nullable: true), + Desc4 = table.Column(type: "nvarchar(max)", nullable: true), + Desc5 = table.Column(type: "nvarchar(max)", nullable: true), + CreatedAt = table.Column(type: "datetime2", nullable: false), + ModifiedAt = table.Column(type: "datetime2", nullable: false), + IsDeleted = table.Column(type: "bit", nullable: false), + CreatedById = table.Column(type: "uniqueidentifier", nullable: false), + ModifiedById = table.Column(type: "uniqueidentifier", nullable: false), + LayerId = table.Column(type: "uniqueidentifier", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Records", x => x.Id); + table.ForeignKey( + name: "FK_Records_Layers_LayerId", + column: x => x.LayerId, + principalTable: "Layers", + principalColumn: "Id", + onDelete: ReferentialAction.NoAction); + table.ForeignKey( + name: "FK_Records_Users_CreatedById", + column: x => x.CreatedById, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.NoAction); + table.ForeignKey( + name: "FK_Records_Users_ModifiedById", + column: x => x.ModifiedById, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.NoAction); + }); + + migrationBuilder.CreateIndex( + name: "IX_Layers_CreatedById", + table: "Layers", + column: "CreatedById"); + + migrationBuilder.CreateIndex( + name: "IX_Layers_ModifiedById", + table: "Layers", + column: "ModifiedById"); + + migrationBuilder.CreateIndex( + name: "IX_Records_CreatedById", + table: "Records", + column: "CreatedById"); + + migrationBuilder.CreateIndex( + name: "IX_Records_LayerId", + table: "Records", + column: "LayerId"); + + migrationBuilder.CreateIndex( + name: "IX_Records_ModifiedById", + table: "Records", + column: "ModifiedById"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Records"); + + migrationBuilder.DropTable( + name: "Layers"); + + migrationBuilder.CreateTable( + name: "DataSets", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + CreatedById = table.Column(type: "uniqueidentifier", nullable: false), + ModifiedById = table.Column(type: "uniqueidentifier", nullable: false), + CreatedAt = table.Column(type: "datetime2", nullable: false), + IsDeleted = table.Column(type: "bit", nullable: false), + ModifiedAt = table.Column(type: "datetime2", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Number = table.Column(type: "int", nullable: false), + Source = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_DataSets", x => x.Id); + table.ForeignKey( + name: "FK_DataSets_Users_CreatedById", + column: x => x.CreatedById, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.NoAction); + table.ForeignKey( + name: "FK_DataSets_Users_ModifiedById", + column: x => x.ModifiedById, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.NoAction); + }); + + migrationBuilder.CreateTable( + name: "DataRows", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + CreatedById = table.Column(type: "uniqueidentifier", nullable: false), + ModifiedById = table.Column(type: "uniqueidentifier", nullable: false), + Code = table.Column(type: "nvarchar(max)", nullable: false), + CreatedAt = table.Column(type: "datetime2", nullable: false), + DataSetId = table.Column(type: "uniqueidentifier", nullable: false), + Desc1 = table.Column(type: "nvarchar(max)", nullable: true), + Desc2 = table.Column(type: "nvarchar(max)", nullable: true), + Desc3 = table.Column(type: "nvarchar(max)", nullable: true), + Desc4 = table.Column(type: "nvarchar(max)", nullable: true), + Desc5 = table.Column(type: "nvarchar(max)", nullable: true), + IsDeleted = table.Column(type: "bit", nullable: false), + ModifiedAt = table.Column(type: "datetime2", nullable: false), + Value = table.Column(type: "real", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_DataRows", x => x.Id); + table.ForeignKey( + name: "FK_DataRows_DataSets_DataSetId", + column: x => x.DataSetId, + principalTable: "DataSets", + principalColumn: "Id", + onDelete: ReferentialAction.NoAction); + table.ForeignKey( + name: "FK_DataRows_Users_CreatedById", + column: x => x.CreatedById, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.NoAction); + table.ForeignKey( + name: "FK_DataRows_Users_ModifiedById", + column: x => x.ModifiedById, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.NoAction); + }); + + migrationBuilder.CreateIndex( + name: "IX_DataRows_CreatedById", + table: "DataRows", + column: "CreatedById"); + + migrationBuilder.CreateIndex( + name: "IX_DataRows_DataSetId", + table: "DataRows", + column: "DataSetId"); + + migrationBuilder.CreateIndex( + name: "IX_DataRows_ModifiedById", + table: "DataRows", + column: "ModifiedById"); + + migrationBuilder.CreateIndex( + name: "IX_DataSets_CreatedById", + table: "DataSets", + column: "CreatedById"); + + migrationBuilder.CreateIndex( + name: "IX_DataSets_ModifiedById", + table: "DataSets", + column: "ModifiedById"); + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20230626171614_LayerType.Designer.cs b/src/Backend/DiunaBI.Database/Migrations/20230626171614_LayerType.Designer.cs new file mode 100644 index 0000000..54ead09 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20230626171614_LayerType.Designer.cs @@ -0,0 +1,202 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20230626171614_LayerType")] + partial class LayerType + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.7") + .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.HasKey("Id"); + + b.HasIndex("CreatedById"); + + b.HasIndex("ModifiedById"); + + 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("Value") + .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.Navigation("CreatedBy"); + + b.Navigation("ModifiedBy"); + }); + + 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/src/Backend/DiunaBI.Database/Migrations/20230626171614_LayerType.cs b/src/Backend/DiunaBI.Database/Migrations/20230626171614_LayerType.cs new file mode 100644 index 0000000..0354276 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20230626171614_LayerType.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + /// + public partial class LayerType : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Type", + table: "Layers", + type: "int", + nullable: false, + defaultValue: 0); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Type", + table: "Layers"); + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20230821105757_Record.Values.Designer.cs b/src/Backend/DiunaBI.Database/Migrations/20230821105757_Record.Values.Designer.cs new file mode 100644 index 0000000..5787223 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20230821105757_Record.Values.Designer.cs @@ -0,0 +1,292 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20230821105757_Record.Values")] + partial class RecordValues + { + /// + 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.HasKey("Id"); + + b.HasIndex("CreatedById"); + + b.HasIndex("ModifiedById"); + + 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.Navigation("CreatedBy"); + + b.Navigation("ModifiedBy"); + }); + + 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/src/Backend/DiunaBI.Database/Migrations/20230821105757_Record.Values.cs b/src/Backend/DiunaBI.Database/Migrations/20230821105757_Record.Values.cs new file mode 100644 index 0000000..f5ecb89 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20230821105757_Record.Values.cs @@ -0,0 +1,339 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + /// + public partial class RecordValues : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Value", + table: "Records"); + + migrationBuilder.AddColumn( + name: "Value1", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value10", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value11", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value12", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value13", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value14", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value15", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value16", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value17", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value18", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value19", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value2", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value20", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value21", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value22", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value23", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value24", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value25", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value26", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value27", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value28", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value29", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value3", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value30", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value31", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value4", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value5", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value6", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value7", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value8", + table: "Records", + type: "real", + nullable: true); + + migrationBuilder.AddColumn( + name: "Value9", + table: "Records", + type: "real", + nullable: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Value1", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value10", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value11", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value12", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value13", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value14", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value15", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value16", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value17", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value18", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value19", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value2", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value20", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value21", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value22", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value23", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value24", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value25", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value26", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value27", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value28", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value29", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value3", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value30", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value31", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value4", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value5", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value6", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value7", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value8", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Value9", + table: "Records"); + + migrationBuilder.AddColumn( + name: "Value", + table: "Records", + type: "real", + nullable: false, + defaultValue: 0f); + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20230917110252_Layer.parent.Designer.cs b/src/Backend/DiunaBI.Database/Migrations/20230917110252_Layer.parent.Designer.cs new file mode 100644 index 0000000..e07e1d1 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20230917110252_Layer.parent.Designer.cs @@ -0,0 +1,303 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +#nullable disable + +namespace DiunaBI.Core.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/src/Backend/DiunaBI.Database/Migrations/20230917110252_Layer.parent.cs b/src/Backend/DiunaBI.Database/Migrations/20230917110252_Layer.parent.cs new file mode 100644 index 0000000..0020874 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20230917110252_Layer.parent.cs @@ -0,0 +1,49 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DiunaBI.Core.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/src/Backend/DiunaBI.Database/Migrations/20230918090621_ProcessSource.Designer.cs b/src/Backend/DiunaBI.Database/Migrations/20230918090621_ProcessSource.Designer.cs new file mode 100644 index 0000000..96cc281 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20230918090621_ProcessSource.Designer.cs @@ -0,0 +1,331 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +#nullable disable + +namespace DiunaBI.Core.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/src/Backend/DiunaBI.Database/Migrations/20230918090621_ProcessSource.cs b/src/Backend/DiunaBI.Database/Migrations/20230918090621_ProcessSource.cs new file mode 100644 index 0000000..e51c9c4 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20230918090621_ProcessSource.cs @@ -0,0 +1,45 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DiunaBI.Core.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/src/Backend/DiunaBI.Database/Migrations/20230918093055_TypeO.Designer.cs b/src/Backend/DiunaBI.Database/Migrations/20230918093055_TypeO.Designer.cs new file mode 100644 index 0000000..fdc03a4 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20230918093055_TypeO.Designer.cs @@ -0,0 +1,332 @@ + +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20230918093055_TypeO")] + partial class TypeO + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.11") + .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("ParentId") + .HasColumnType("uniqueidentifier"); + + b.Property("Source") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Type") + .HasColumnType("int"); + + 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/src/Backend/DiunaBI.Database/Migrations/20230918093055_TypeO.cs b/src/Backend/DiunaBI.Database/Migrations/20230918093055_TypeO.cs new file mode 100644 index 0000000..deac794 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20230918093055_TypeO.cs @@ -0,0 +1,60 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + /// + public partial class TypeO : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Layers_Layers_parentId", + table: "Layers"); + + migrationBuilder.RenameColumn( + name: "parentId", + table: "Layers", + newName: "ParentId"); + + migrationBuilder.RenameIndex( + name: "IX_Layers_parentId", + table: "Layers", + newName: "IX_Layers_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.RenameColumn( + name: "ParentId", + table: "Layers", + newName: "parentId"); + + migrationBuilder.RenameIndex( + name: "IX_Layers_ParentId", + table: "Layers", + newName: "IX_Layers_parentId"); + + migrationBuilder.AddForeignKey( + name: "FK_Layers_Layers_parentId", + table: "Layers", + column: "parentId", + principalTable: "Layers", + principalColumn: "Id"); + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20231030142419_Record.Value32.Designer.cs b/src/Backend/DiunaBI.Database/Migrations/20231030142419_Record.Value32.Designer.cs new file mode 100644 index 0000000..b60890d --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20231030142419_Record.Value32.Designer.cs @@ -0,0 +1,334 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20231030142419_Record.Value32")] + partial class RecordValue32 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.12") + .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("ParentId") + .HasColumnType("uniqueidentifier"); + + b.Property("Source") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Type") + .HasColumnType("int"); + + 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("Value32") + .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/src/Backend/DiunaBI.Database/Migrations/20231030142419_Record.Value32.cs b/src/Backend/DiunaBI.Database/Migrations/20231030142419_Record.Value32.cs new file mode 100644 index 0000000..0d204f4 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20231030142419_Record.Value32.cs @@ -0,0 +1,28 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + /// + public partial class RecordValue32 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Value32", + table: "Records", + type: "real", + nullable: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Value32", + table: "Records"); + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20240309075645_Change record value type.Designer.cs b/src/Backend/DiunaBI.Database/Migrations/20240309075645_Change record value type.Designer.cs new file mode 100644 index 0000000..c7faeaa --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20240309075645_Change record value type.Designer.cs @@ -0,0 +1,334 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20240309075645_Change record value type")] + partial class Changerecordvaluetype + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.13") + .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("ParentId") + .HasColumnType("uniqueidentifier"); + + b.Property("Source") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Type") + .HasColumnType("int"); + + 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("float"); + + b.Property("Value10") + .HasColumnType("float"); + + b.Property("Value11") + .HasColumnType("float"); + + b.Property("Value12") + .HasColumnType("float"); + + b.Property("Value13") + .HasColumnType("float"); + + b.Property("Value14") + .HasColumnType("float"); + + b.Property("Value15") + .HasColumnType("float"); + + b.Property("Value16") + .HasColumnType("float"); + + b.Property("Value17") + .HasColumnType("float"); + + b.Property("Value18") + .HasColumnType("float"); + + b.Property("Value19") + .HasColumnType("float"); + + b.Property("Value2") + .HasColumnType("float"); + + b.Property("Value20") + .HasColumnType("float"); + + b.Property("Value21") + .HasColumnType("float"); + + b.Property("Value22") + .HasColumnType("float"); + + b.Property("Value23") + .HasColumnType("float"); + + b.Property("Value24") + .HasColumnType("float"); + + b.Property("Value25") + .HasColumnType("float"); + + b.Property("Value26") + .HasColumnType("float"); + + b.Property("Value27") + .HasColumnType("float"); + + b.Property("Value28") + .HasColumnType("float"); + + b.Property("Value29") + .HasColumnType("float"); + + b.Property("Value3") + .HasColumnType("float"); + + b.Property("Value30") + .HasColumnType("float"); + + b.Property("Value31") + .HasColumnType("float"); + + b.Property("Value32") + .HasColumnType("float"); + + b.Property("Value4") + .HasColumnType("float"); + + b.Property("Value5") + .HasColumnType("float"); + + b.Property("Value6") + .HasColumnType("float"); + + b.Property("Value7") + .HasColumnType("float"); + + b.Property("Value8") + .HasColumnType("float"); + + b.Property("Value9") + .HasColumnType("float"); + + 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/src/Backend/DiunaBI.Database/Migrations/20240309075645_Change record value type.cs b/src/Backend/DiunaBI.Database/Migrations/20240309075645_Change record value type.cs new file mode 100644 index 0000000..daaaa1b --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20240309075645_Change record value type.cs @@ -0,0 +1,594 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + /// + public partial class Changerecordvaluetype : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Value9", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value8", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value7", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value6", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value5", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value4", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value32", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value31", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value30", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value3", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value29", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value28", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value27", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value26", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value25", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value24", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value23", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value22", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value21", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value20", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value2", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value19", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value18", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value17", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value16", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value15", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value14", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value13", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value12", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value11", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value10", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value1", + table: "Records", + type: "float", + nullable: true, + oldClrType: typeof(float), + oldType: "real", + oldNullable: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Value9", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value8", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value7", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value6", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value5", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value4", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value32", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value31", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value30", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value3", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value29", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value28", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value27", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value26", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value25", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value24", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value23", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value22", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value21", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value20", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value2", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value19", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value18", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value17", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value16", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value15", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value14", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value13", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value12", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value11", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value10", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Value1", + table: "Records", + type: "real", + nullable: true, + oldClrType: typeof(double), + oldType: "float", + oldNullable: true); + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20240703171630_AfterCodeRefactor.Designer.cs b/src/Backend/DiunaBI.Database/Migrations/20240703171630_AfterCodeRefactor.Designer.cs new file mode 100644 index 0000000..fea2a0b --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20240703171630_AfterCodeRefactor.Designer.cs @@ -0,0 +1,320 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20240703171630_AfterCodeRefactor")] + partial class AfterCodeRefactor + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.6") + .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() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Number") + .HasColumnType("int"); + + b.Property("ParentId") + .HasColumnType("uniqueidentifier"); + + b.Property("Type") + .HasColumnType("int"); + + 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() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Desc1") + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LayerId") + .HasColumnType("uniqueidentifier"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Value1") + .HasColumnType("float"); + + b.Property("Value10") + .HasColumnType("float"); + + b.Property("Value11") + .HasColumnType("float"); + + b.Property("Value12") + .HasColumnType("float"); + + b.Property("Value13") + .HasColumnType("float"); + + b.Property("Value14") + .HasColumnType("float"); + + b.Property("Value15") + .HasColumnType("float"); + + b.Property("Value16") + .HasColumnType("float"); + + b.Property("Value17") + .HasColumnType("float"); + + b.Property("Value18") + .HasColumnType("float"); + + b.Property("Value19") + .HasColumnType("float"); + + b.Property("Value2") + .HasColumnType("float"); + + b.Property("Value20") + .HasColumnType("float"); + + b.Property("Value21") + .HasColumnType("float"); + + b.Property("Value22") + .HasColumnType("float"); + + b.Property("Value23") + .HasColumnType("float"); + + b.Property("Value24") + .HasColumnType("float"); + + b.Property("Value25") + .HasColumnType("float"); + + b.Property("Value26") + .HasColumnType("float"); + + b.Property("Value27") + .HasColumnType("float"); + + b.Property("Value28") + .HasColumnType("float"); + + b.Property("Value29") + .HasColumnType("float"); + + b.Property("Value3") + .HasColumnType("float"); + + b.Property("Value30") + .HasColumnType("float"); + + b.Property("Value31") + .HasColumnType("float"); + + b.Property("Value32") + .HasColumnType("float"); + + b.Property("Value4") + .HasColumnType("float"); + + b.Property("Value5") + .HasColumnType("float"); + + b.Property("Value6") + .HasColumnType("float"); + + b.Property("Value7") + .HasColumnType("float"); + + b.Property("Value8") + .HasColumnType("float"); + + b.Property("Value9") + .HasColumnType("float"); + + 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") + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + 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() + .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"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20240703171630_AfterCodeRefactor.cs b/src/Backend/DiunaBI.Database/Migrations/20240703171630_AfterCodeRefactor.cs new file mode 100644 index 0000000..c1ab587 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20240703171630_AfterCodeRefactor.cs @@ -0,0 +1,135 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + /// + public partial class AfterCodeRefactor : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Desc2", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Desc3", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Desc4", + table: "Records"); + + migrationBuilder.DropColumn( + name: "Desc5", + table: "Records"); + + migrationBuilder.AlterColumn( + name: "Email", + table: "Users", + type: "nvarchar(50)", + maxLength: 50, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Desc1", + table: "Records", + type: "nvarchar(1000)", + maxLength: 1000, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Code", + table: "Records", + type: "nvarchar(50)", + maxLength: 50, + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(max)"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Layers", + type: "nvarchar(50)", + maxLength: 50, + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(max)"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Email", + table: "Users", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(50)", + oldMaxLength: 50, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Desc1", + table: "Records", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(1000)", + oldMaxLength: 1000, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Code", + table: "Records", + type: "nvarchar(max)", + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(50)", + oldMaxLength: 50); + + migrationBuilder.AddColumn( + name: "Desc2", + table: "Records", + type: "nvarchar(max)", + nullable: true); + + migrationBuilder.AddColumn( + name: "Desc3", + table: "Records", + type: "nvarchar(max)", + nullable: true); + + migrationBuilder.AddColumn( + name: "Desc4", + table: "Records", + type: "nvarchar(max)", + nullable: true); + + migrationBuilder.AddColumn( + name: "Desc5", + table: "Records", + type: "nvarchar(max)", + nullable: true); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Layers", + type: "nvarchar(max)", + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(50)", + oldMaxLength: 50); + + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20240703173337_DataInboxModel.Designer.cs b/src/Backend/DiunaBI.Database/Migrations/20240703173337_DataInboxModel.Designer.cs new file mode 100644 index 0000000..5b047dd --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20240703173337_DataInboxModel.Designer.cs @@ -0,0 +1,349 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20240703173337_DataInboxModel")] + partial class DataInboxModel + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("WebAPI.Models.DataInbox", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("Data") + .IsRequired() + .HasMaxLength(2147483647) + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Source") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("DataInbox"); + }); + + 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() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Number") + .HasColumnType("int"); + + b.Property("ParentId") + .HasColumnType("uniqueidentifier"); + + b.Property("Type") + .HasColumnType("int"); + + 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() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Desc1") + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LayerId") + .HasColumnType("uniqueidentifier"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Value1") + .HasColumnType("float"); + + b.Property("Value10") + .HasColumnType("float"); + + b.Property("Value11") + .HasColumnType("float"); + + b.Property("Value12") + .HasColumnType("float"); + + b.Property("Value13") + .HasColumnType("float"); + + b.Property("Value14") + .HasColumnType("float"); + + b.Property("Value15") + .HasColumnType("float"); + + b.Property("Value16") + .HasColumnType("float"); + + b.Property("Value17") + .HasColumnType("float"); + + b.Property("Value18") + .HasColumnType("float"); + + b.Property("Value19") + .HasColumnType("float"); + + b.Property("Value2") + .HasColumnType("float"); + + b.Property("Value20") + .HasColumnType("float"); + + b.Property("Value21") + .HasColumnType("float"); + + b.Property("Value22") + .HasColumnType("float"); + + b.Property("Value23") + .HasColumnType("float"); + + b.Property("Value24") + .HasColumnType("float"); + + b.Property("Value25") + .HasColumnType("float"); + + b.Property("Value26") + .HasColumnType("float"); + + b.Property("Value27") + .HasColumnType("float"); + + b.Property("Value28") + .HasColumnType("float"); + + b.Property("Value29") + .HasColumnType("float"); + + b.Property("Value3") + .HasColumnType("float"); + + b.Property("Value30") + .HasColumnType("float"); + + b.Property("Value31") + .HasColumnType("float"); + + b.Property("Value32") + .HasColumnType("float"); + + b.Property("Value4") + .HasColumnType("float"); + + b.Property("Value5") + .HasColumnType("float"); + + b.Property("Value6") + .HasColumnType("float"); + + b.Property("Value7") + .HasColumnType("float"); + + b.Property("Value8") + .HasColumnType("float"); + + b.Property("Value9") + .HasColumnType("float"); + + 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") + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + 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() + .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"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20240703173337_DataInboxModel.cs b/src/Backend/DiunaBI.Database/Migrations/20240703173337_DataInboxModel.cs new file mode 100644 index 0000000..7c174d7 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20240703173337_DataInboxModel.cs @@ -0,0 +1,37 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + /// + public partial class DataInboxModel : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "DataInbox", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + Name = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Source = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Data = table.Column(type: "nvarchar(max)", maxLength: 2147483647, nullable: false), + CreatedAt = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_DataInbox", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "DataInbox"); + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20240825144443_QueueJobs.Designer.cs b/src/Backend/DiunaBI.Database/Migrations/20240825144443_QueueJobs.Designer.cs new file mode 100644 index 0000000..54160aa --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20240825144443_QueueJobs.Designer.cs @@ -0,0 +1,382 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20240825144443_QueueJobs")] + partial class QueueJobs + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("WebAPI.Models.DataInbox", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("Data") + .IsRequired() + .HasMaxLength(2147483647) + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Source") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("DataInbox"); + }); + + 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() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Number") + .HasColumnType("int"); + + b.Property("ParentId") + .HasColumnType("uniqueidentifier"); + + b.Property("Type") + .HasColumnType("int"); + + 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.QueueJob", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Attempts") + .HasColumnType("int"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("LayerId") + .HasColumnType("uniqueidentifier"); + + b.Property("Message") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("QueueJobs"); + }); + + modelBuilder.Entity("WebAPI.Models.Record", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Code") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Desc1") + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LayerId") + .HasColumnType("uniqueidentifier"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Value1") + .HasColumnType("float"); + + b.Property("Value10") + .HasColumnType("float"); + + b.Property("Value11") + .HasColumnType("float"); + + b.Property("Value12") + .HasColumnType("float"); + + b.Property("Value13") + .HasColumnType("float"); + + b.Property("Value14") + .HasColumnType("float"); + + b.Property("Value15") + .HasColumnType("float"); + + b.Property("Value16") + .HasColumnType("float"); + + b.Property("Value17") + .HasColumnType("float"); + + b.Property("Value18") + .HasColumnType("float"); + + b.Property("Value19") + .HasColumnType("float"); + + b.Property("Value2") + .HasColumnType("float"); + + b.Property("Value20") + .HasColumnType("float"); + + b.Property("Value21") + .HasColumnType("float"); + + b.Property("Value22") + .HasColumnType("float"); + + b.Property("Value23") + .HasColumnType("float"); + + b.Property("Value24") + .HasColumnType("float"); + + b.Property("Value25") + .HasColumnType("float"); + + b.Property("Value26") + .HasColumnType("float"); + + b.Property("Value27") + .HasColumnType("float"); + + b.Property("Value28") + .HasColumnType("float"); + + b.Property("Value29") + .HasColumnType("float"); + + b.Property("Value3") + .HasColumnType("float"); + + b.Property("Value30") + .HasColumnType("float"); + + b.Property("Value31") + .HasColumnType("float"); + + b.Property("Value32") + .HasColumnType("float"); + + b.Property("Value4") + .HasColumnType("float"); + + b.Property("Value5") + .HasColumnType("float"); + + b.Property("Value6") + .HasColumnType("float"); + + b.Property("Value7") + .HasColumnType("float"); + + b.Property("Value8") + .HasColumnType("float"); + + b.Property("Value9") + .HasColumnType("float"); + + 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") + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + 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() + .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"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20240825144443_QueueJobs.cs b/src/Backend/DiunaBI.Database/Migrations/20240825144443_QueueJobs.cs new file mode 100644 index 0000000..253dba5 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20240825144443_QueueJobs.cs @@ -0,0 +1,40 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + /// + public partial class QueueJobs : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "QueueJobs", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + LayerId = table.Column(type: "uniqueidentifier", nullable: false), + Attempts = table.Column(type: "int", nullable: false), + Status = table.Column(type: "int", nullable: false), + Type = table.Column(type: "int", nullable: false), + Message = table.Column(type: "nvarchar(max)", nullable: false), + CreatedAt = table.Column(type: "datetime2", nullable: false), + ModifiedAt = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_QueueJobs", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "QueueJobs"); + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20250317114722_LongerDesc1.Designer.cs b/src/Backend/DiunaBI.Database/Migrations/20250317114722_LongerDesc1.Designer.cs new file mode 100644 index 0000000..6fc4823 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20250317114722_LongerDesc1.Designer.cs @@ -0,0 +1,382 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20250317114722_LongerDesc1")] + partial class LongerDesc1 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("WebAPI.Models.DataInbox", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("Data") + .IsRequired() + .HasMaxLength(2147483647) + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Source") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("DataInbox"); + }); + + 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() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Number") + .HasColumnType("int"); + + b.Property("ParentId") + .HasColumnType("uniqueidentifier"); + + b.Property("Type") + .HasColumnType("int"); + + 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.QueueJob", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Attempts") + .HasColumnType("int"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("LayerId") + .HasColumnType("uniqueidentifier"); + + b.Property("Message") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("QueueJobs"); + }); + + modelBuilder.Entity("WebAPI.Models.Record", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Code") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Desc1") + .HasMaxLength(10000) + .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("float"); + + b.Property("Value10") + .HasColumnType("float"); + + b.Property("Value11") + .HasColumnType("float"); + + b.Property("Value12") + .HasColumnType("float"); + + b.Property("Value13") + .HasColumnType("float"); + + b.Property("Value14") + .HasColumnType("float"); + + b.Property("Value15") + .HasColumnType("float"); + + b.Property("Value16") + .HasColumnType("float"); + + b.Property("Value17") + .HasColumnType("float"); + + b.Property("Value18") + .HasColumnType("float"); + + b.Property("Value19") + .HasColumnType("float"); + + b.Property("Value2") + .HasColumnType("float"); + + b.Property("Value20") + .HasColumnType("float"); + + b.Property("Value21") + .HasColumnType("float"); + + b.Property("Value22") + .HasColumnType("float"); + + b.Property("Value23") + .HasColumnType("float"); + + b.Property("Value24") + .HasColumnType("float"); + + b.Property("Value25") + .HasColumnType("float"); + + b.Property("Value26") + .HasColumnType("float"); + + b.Property("Value27") + .HasColumnType("float"); + + b.Property("Value28") + .HasColumnType("float"); + + b.Property("Value29") + .HasColumnType("float"); + + b.Property("Value3") + .HasColumnType("float"); + + b.Property("Value30") + .HasColumnType("float"); + + b.Property("Value31") + .HasColumnType("float"); + + b.Property("Value32") + .HasColumnType("float"); + + b.Property("Value4") + .HasColumnType("float"); + + b.Property("Value5") + .HasColumnType("float"); + + b.Property("Value6") + .HasColumnType("float"); + + b.Property("Value7") + .HasColumnType("float"); + + b.Property("Value8") + .HasColumnType("float"); + + b.Property("Value9") + .HasColumnType("float"); + + 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") + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + 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() + .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"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20250317114722_LongerDesc1.cs b/src/Backend/DiunaBI.Database/Migrations/20250317114722_LongerDesc1.cs new file mode 100644 index 0000000..7462942 --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20250317114722_LongerDesc1.cs @@ -0,0 +1,40 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + /// + public partial class LongerDesc1 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Desc1", + table: "Records", + type: "nvarchar(max)", + maxLength: 10000, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(1000)", + oldMaxLength: 1000, + oldNullable: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Desc1", + table: "Records", + type: "nvarchar(1000)", + maxLength: 1000, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldMaxLength: 10000, + oldNullable: true); + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20250529093632_LayersIsCancelled.Designer.cs b/src/Backend/DiunaBI.Database/Migrations/20250529093632_LayersIsCancelled.Designer.cs new file mode 100644 index 0000000..917717d --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20250529093632_LayersIsCancelled.Designer.cs @@ -0,0 +1,385 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20250529093632_LayersIsCancelled")] + partial class LayersIsCancelled + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("WebAPI.Models.DataInbox", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("Data") + .IsRequired() + .HasMaxLength(2147483647) + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Source") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("DataInbox"); + }); + + modelBuilder.Entity("WebAPI.Models.Layer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedById") + .HasColumnType("uniqueidentifier"); + + b.Property("IsCancelled") + .HasColumnType("bit"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Number") + .HasColumnType("int"); + + b.Property("ParentId") + .HasColumnType("uniqueidentifier"); + + b.Property("Type") + .HasColumnType("int"); + + 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.QueueJob", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Attempts") + .HasColumnType("int"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("LayerId") + .HasColumnType("uniqueidentifier"); + + b.Property("Message") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("QueueJobs"); + }); + + modelBuilder.Entity("WebAPI.Models.Record", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Code") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Desc1") + .HasMaxLength(10000) + .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("float"); + + b.Property("Value10") + .HasColumnType("float"); + + b.Property("Value11") + .HasColumnType("float"); + + b.Property("Value12") + .HasColumnType("float"); + + b.Property("Value13") + .HasColumnType("float"); + + b.Property("Value14") + .HasColumnType("float"); + + b.Property("Value15") + .HasColumnType("float"); + + b.Property("Value16") + .HasColumnType("float"); + + b.Property("Value17") + .HasColumnType("float"); + + b.Property("Value18") + .HasColumnType("float"); + + b.Property("Value19") + .HasColumnType("float"); + + b.Property("Value2") + .HasColumnType("float"); + + b.Property("Value20") + .HasColumnType("float"); + + b.Property("Value21") + .HasColumnType("float"); + + b.Property("Value22") + .HasColumnType("float"); + + b.Property("Value23") + .HasColumnType("float"); + + b.Property("Value24") + .HasColumnType("float"); + + b.Property("Value25") + .HasColumnType("float"); + + b.Property("Value26") + .HasColumnType("float"); + + b.Property("Value27") + .HasColumnType("float"); + + b.Property("Value28") + .HasColumnType("float"); + + b.Property("Value29") + .HasColumnType("float"); + + b.Property("Value3") + .HasColumnType("float"); + + b.Property("Value30") + .HasColumnType("float"); + + b.Property("Value31") + .HasColumnType("float"); + + b.Property("Value32") + .HasColumnType("float"); + + b.Property("Value4") + .HasColumnType("float"); + + b.Property("Value5") + .HasColumnType("float"); + + b.Property("Value6") + .HasColumnType("float"); + + b.Property("Value7") + .HasColumnType("float"); + + b.Property("Value8") + .HasColumnType("float"); + + b.Property("Value9") + .HasColumnType("float"); + + 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") + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + 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() + .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"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/20250529093632_LayersIsCancelled.cs b/src/Backend/DiunaBI.Database/Migrations/20250529093632_LayersIsCancelled.cs new file mode 100644 index 0000000..f963b5e --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/20250529093632_LayersIsCancelled.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + /// + public partial class LayersIsCancelled : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "IsCancelled", + table: "Layers", + type: "bit", + nullable: false, + defaultValue: false); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "IsCancelled", + table: "Layers"); + } + } +} diff --git a/src/Backend/DiunaBI.Database/Migrations/AppDbContextModelSnapshot.cs b/src/Backend/DiunaBI.Database/Migrations/AppDbContextModelSnapshot.cs new file mode 100644 index 0000000..0907c7e --- /dev/null +++ b/src/Backend/DiunaBI.Database/Migrations/AppDbContextModelSnapshot.cs @@ -0,0 +1,382 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +#nullable disable + +namespace DiunaBI.Core.Migrations +{ + [DbContext(typeof(AppDbContext))] + partial class AppDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("WebAPI.Models.DataInbox", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("Data") + .IsRequired() + .HasMaxLength(2147483647) + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Source") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("DataInbox"); + }); + + modelBuilder.Entity("WebAPI.Models.Layer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedById") + .HasColumnType("uniqueidentifier"); + + b.Property("IsCancelled") + .HasColumnType("bit"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Number") + .HasColumnType("int"); + + b.Property("ParentId") + .HasColumnType("uniqueidentifier"); + + b.Property("Type") + .HasColumnType("int"); + + 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.QueueJob", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Attempts") + .HasColumnType("int"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("LayerId") + .HasColumnType("uniqueidentifier"); + + b.Property("Message") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("QueueJobs"); + }); + + modelBuilder.Entity("WebAPI.Models.Record", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Code") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedById") + .HasColumnType("uniqueidentifier"); + + b.Property("Desc1") + .HasMaxLength(10000) + .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("float"); + + b.Property("Value10") + .HasColumnType("float"); + + b.Property("Value11") + .HasColumnType("float"); + + b.Property("Value12") + .HasColumnType("float"); + + b.Property("Value13") + .HasColumnType("float"); + + b.Property("Value14") + .HasColumnType("float"); + + b.Property("Value15") + .HasColumnType("float"); + + b.Property("Value16") + .HasColumnType("float"); + + b.Property("Value17") + .HasColumnType("float"); + + b.Property("Value18") + .HasColumnType("float"); + + b.Property("Value19") + .HasColumnType("float"); + + b.Property("Value2") + .HasColumnType("float"); + + b.Property("Value20") + .HasColumnType("float"); + + b.Property("Value21") + .HasColumnType("float"); + + b.Property("Value22") + .HasColumnType("float"); + + b.Property("Value23") + .HasColumnType("float"); + + b.Property("Value24") + .HasColumnType("float"); + + b.Property("Value25") + .HasColumnType("float"); + + b.Property("Value26") + .HasColumnType("float"); + + b.Property("Value27") + .HasColumnType("float"); + + b.Property("Value28") + .HasColumnType("float"); + + b.Property("Value29") + .HasColumnType("float"); + + b.Property("Value3") + .HasColumnType("float"); + + b.Property("Value30") + .HasColumnType("float"); + + b.Property("Value31") + .HasColumnType("float"); + + b.Property("Value32") + .HasColumnType("float"); + + b.Property("Value4") + .HasColumnType("float"); + + b.Property("Value5") + .HasColumnType("float"); + + b.Property("Value6") + .HasColumnType("float"); + + b.Property("Value7") + .HasColumnType("float"); + + b.Property("Value8") + .HasColumnType("float"); + + b.Property("Value9") + .HasColumnType("float"); + + 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") + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + 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() + .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"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Backend/DiunaBI.Plugins.Morska/Exporters/googleSheet.export.cs b/src/Backend/DiunaBI.Plugins.Morska/Exporters/googleSheet.export.cs new file mode 100644 index 0000000..c0cd123 --- /dev/null +++ b/src/Backend/DiunaBI.Plugins.Morska/Exporters/googleSheet.export.cs @@ -0,0 +1,123 @@ +using System.Globalization; +using Google.Apis.Sheets.v4; +using Google.Apis.Sheets.v4.Data; +using DiunaBI.Core.Models; +using Microsoft.Extensions.Configuration; + +namespace DiunaBI.Core.Services.Exports; + +public class GoogleSheetExport +{ + private readonly GoogleDriveHelper _googleDriveHelper; + private readonly SpreadsheetsResource.ValuesResource _googleSheetValues; + private readonly IConfiguration _configuration; + public GoogleSheetExport( + GoogleDriveHelper googleDriveHelper, + SpreadsheetsResource.ValuesResource googleSheetValues, + IConfiguration configuration) + { + _googleDriveHelper = googleDriveHelper; + _googleSheetValues = googleSheetValues; + _configuration = configuration; + } + public void Export(Layer layer) + { + if (_googleDriveHelper.Service is null) + { + throw new Exception("Google Drive API not initialized"); + } + try + { + + var data = new List> { new List { layer.Name! } }; + + switch (layer.Type) + { + case LayerType.Import: + { + data.Add(new List { "Code", "Value1" }); + data.AddRange(layer.Records!.Select(record => new List { record.Code!, record.Value1! })); + break; + } + case LayerType.Administration: + { + data.Add(new List { "Code", "Desc1" }); + data.AddRange(layer.Records!.Select(record => new List { record.Code!, record.Desc1! })); + break; + } + case LayerType.Processed: + { + data.Add(new List { "Code", "Value1", "Value2", "Value3", "Value3", + "Value5", "Value6", "Value7", "Value8", "Value9", "Value10", + "Value11", "Value12", "Value13", "Value14", "Value15", "Value16", + "Value17", "Value18", "Value19", "Value20", "Value21", "Value22", + "Value23", "Value24", "Value25", "Value26", "Value27", "Value28", + "Value29", "Value30", "Value31", "Value32"}); + + data.AddRange(layer.Records!.Select(record => new List + { + record.Code!, + record.Value1!, + record.Value2!, + record.Value3!, + record.Value4!, + record.Value5!, + record.Value6!, + record.Value7!, + record.Value8!, + record.Value9!, + record.Value10!, + record.Value11!, + record.Value12!, + record.Value13!, + record.Value14!, + record.Value15!, + record.Value16!, + record.Value17!, + record.Value18!, + record.Value19!, + record.Value20!, + record.Value21!, + record.Value22!, + record.Value23!, + record.Value24!, + record.Value25!, + record.Value26!, + record.Value27!, + record.Value28!, + record.Value29!, + record.Value30!, + record.Value31!, + record.Value32! + })); + break; + } + default: + throw new Exception("Wrong LayerType"); + } + + var body = new Google.Apis.Drive.v3.Data.File + { + Name = $"{DateTime.Now.ToString(new CultureInfo("pl-PL"))}", + MimeType = "application/vnd.google-apps.spreadsheet", + Parents = new List { _configuration["exportDirectory"] } + }; + var request = _googleDriveHelper.Service.Files.Create(body); + var file = request.Execute(); + + var sheetId = file.Id; + var range = $"Sheet1!A1:AG${data.Count}"; + + var valueRange = new ValueRange { Values = data }; + + var updateRequest = _googleSheetValues.Update(valueRange, sheetId, range); + updateRequest.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.RAW; + updateRequest.Execute(); + + } + catch (Exception e) + { + Console.WriteLine(e.ToString()); + } + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Plugins.Morska/Importers/morska.d1.importer.cs b/src/Backend/DiunaBI.Plugins.Morska/Importers/morska.d1.importer.cs new file mode 100644 index 0000000..b8f2964 --- /dev/null +++ b/src/Backend/DiunaBI.Plugins.Morska/Importers/morska.d1.importer.cs @@ -0,0 +1,108 @@ +using System.Globalization; +using Google.Apis.Sheets.v4; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +namespace DiunaBI.Plugins.Morska.Importers; + +public class MorskaD1Importer( + AppDbContext db, + SpreadsheetsResource.ValuesResource googleSheetValues) +{ + public void Import(Layer importWorker) + { + var sheetId = importWorker.Records!.FirstOrDefault(x => x.Code == "SheetId")?.Desc1; + if (sheetId == null) + { + throw new Exception($"SheetId not found, {importWorker.Name}"); + } + var sheetTabName = importWorker.Records!.FirstOrDefault(x => x.Code == "SheetTabName")?.Desc1; + if (sheetTabName == null) + { + throw new Exception($"SheetTabName not found, {importWorker.Name}"); + } + var year = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportYear")?.Desc1; + if (year == null) + { + throw new Exception($"ImportYear not found, {importWorker.Name}"); + } + var month = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportMonth")?.Desc1; + if (month == null) + { + throw new Exception($"ImportMonth not found, {importWorker.Name}"); + } + var name = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportName")?.Desc1; + if (name == null) + { + throw new Exception($"ImportName not found, {importWorker.Name}"); + } + + var dataRange = importWorker.Records!.FirstOrDefault(x => x.Code == "DataRange")?.Desc1; + if (dataRange == null) + { + throw new Exception($"DataRange not found, {importWorker.Name}"); + } + + var layer = new Layer + { + Number = db.Layers.Count() + 1, + ParentId = importWorker.Id, + Type = LayerType.Import, + CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"), + ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"), + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow + }; + layer.Name = $"L{layer.Number}-I-{name}-{year}/{month}-{DateTime.Now.ToString("yyyyMMddHHmm", CultureInfo.InvariantCulture)}"; + + var dataRangeResponse = googleSheetValues.Get(sheetId, $"{sheetTabName}!{dataRange}").Execute(); + var data = dataRangeResponse.Values; + var newRecords = (from t in data + where t.Count > 1 && (string)t[0] != string.Empty + select new Record + { + Id = Guid.NewGuid(), + Code = t[0].ToString(), + Value1 = IndexExists(t, 3) ? ParseValue(t[3]?.ToString()) : null, + Value2 = IndexExists(t, 4) ? ParseValue(t[4]?.ToString()) : null, + Value3 = IndexExists(t, 5) ? ParseValue(t[5]?.ToString()) : null, + Value4 = IndexExists(t, 6) ? ParseValue(t[6]?.ToString()) : null, + Value5 = IndexExists(t, 7) ? ParseValue(t[7]?.ToString()) : null, + Value6 = IndexExists(t, 8) ? ParseValue(t[8]?.ToString()) : null, + Value7 = IndexExists(t, 9) ? ParseValue(t[9]?.ToString()) : null, + Value8 = IndexExists(t, 10) ? ParseValue(t[10]?.ToString()) : null, + Value9 = IndexExists(t, 11) ? ParseValue(t[11]?.ToString()) : null, + Value10 = IndexExists(t, 12) ? ParseValue(t[12]?.ToString()) : null, + Value11 = IndexExists(t, 13) ? ParseValue(t[13]?.ToString()) : null, + Value12 = IndexExists(t, 14) ? ParseValue(t[14]?.ToString()) : null, + Value13 = IndexExists(t, 15) ? ParseValue(t[15]?.ToString()) : null, + Value14 = IndexExists(t, 16) ? ParseValue(t[16]?.ToString()) : null, + Value15 = IndexExists(t, 17) ? ParseValue(t[17]?.ToString()) : null, + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow + }).ToList(); + db.Layers.Add(layer); + // TODO: Save records to the layer + //controller.SaveRecords(layer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D")); + db.SaveChanges(); + } + + private double? ParseValue(string? value) + { + if (string.IsNullOrEmpty(value) || value == "#DIV/0!") return null; + value = new string(value.Where(c => char.IsDigit(c) || c == '.' || c == ',' || c == '-').ToArray()); + try + { + double.TryParse(value, CultureInfo.GetCultureInfo("pl-PL"), out var result); + return result; + } + catch (FormatException) + { + return null; + } + } + private bool IndexExists(IList array, int index) + { + return array != null && index >= 0 && index < array.Count; + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Plugins.Morska/Importers/morska.d3.importer.cs b/src/Backend/DiunaBI.Plugins.Morska/Importers/morska.d3.importer.cs new file mode 100644 index 0000000..4da9229 --- /dev/null +++ b/src/Backend/DiunaBI.Plugins.Morska/Importers/morska.d3.importer.cs @@ -0,0 +1,75 @@ +using System.Globalization; +using System.Text; +using System.Text.Json; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +namespace DiunaBI.Plugins.Morska.Importers; + +public class MorskaD3Importer( + AppDbContext db) +{ + public void Import(Layer importWorker) + { + var year = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportYear")?.Desc1; + if (year == null) + { + throw new Exception($"ImportYear not found, {importWorker.Name}"); + } + var month = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportMonth")?.Desc1; + if (month == null) + { + throw new Exception($"ImportMonth not found, {importWorker.Name}"); + } + var name = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportName")?.Desc1; + if (name == null) + { + throw new Exception($"ImportName not found, {importWorker.Name}"); + } + var type = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportType")?.Desc1; + if (name == null) + { + throw new Exception($"ImportType not found, {importWorker.Name}"); + } + var dataInbox = db.DataInbox.OrderByDescending(x => x.CreatedAt).FirstOrDefault(x => x.Name == type); + if (dataInbox == null) + { + throw new Exception($"DataInbox not found, {type}"); + } + var data = Convert.FromBase64String(dataInbox.Data); + var tst = Encoding.UTF8.GetString(data); + var records = JsonSerializer.Deserialize>(Encoding.UTF8.GetString(data)); + if (records == null) + { + throw new Exception($"DataInbox.Data is empty, {dataInbox.Name}"); + } + records = records.Where(x => x.Code!.StartsWith($"{year}{month}")).ToList(); + if (records.Count == 0) + { + throw new Exception($"No records found for {year}{month}"); + } + records = records.Select(x => + { + x.Id = Guid.NewGuid(); + x.CreatedAt = DateTime.UtcNow; + x.ModifiedAt = DateTime.UtcNow; + return x; + }).ToList(); + var layer = new Layer + { + Number = db.Layers.Count() + 1, + ParentId = importWorker.Id, + Type = LayerType.Import, + CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"), + ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"), + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow + }; + layer.Name = $"L{layer.Number}-I-{name}-{year}/{month}-{DateTime.Now.ToString("yyyyMMddHHmm", CultureInfo.InvariantCulture)}"; + + db.Layers.Add(layer); + // TODO: Save records to the layer + //controller.SaveRecords(layer.Id, records, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D")); + db.SaveChanges(); + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Plugins.Morska/Importers/morska.fk2.importer.cs b/src/Backend/DiunaBI.Plugins.Morska/Importers/morska.fk2.importer.cs new file mode 100644 index 0000000..79c8d66 --- /dev/null +++ b/src/Backend/DiunaBI.Plugins.Morska/Importers/morska.fk2.importer.cs @@ -0,0 +1,92 @@ +using System.Globalization; +using Google.Apis.Sheets.v4; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +namespace DiunaBI.Plugins.Morska.Importers; + +public class MorskaFk2Importer( + AppDbContext db, + SpreadsheetsResource.ValuesResource googleSheetValues) +{ + public void Import(Layer importWorker) + { + var sheetId = importWorker.Records!.FirstOrDefault(x => x.Code == "SheetId")?.Desc1; + if (sheetId == null) + { + throw new Exception($"SheetId not found, {importWorker.Name}"); + } + var sheetTabName = importWorker.Records!.FirstOrDefault(x => x.Code == "SheetTabName")?.Desc1; + if (sheetTabName == null) + { + throw new Exception($"SheetTabName not found, {importWorker.Name}"); + } + var year = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportYear")?.Desc1; + if (year == null) + { + throw new Exception($"ImportYear not found, {importWorker.Name}"); + } + var month = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportMonth")?.Desc1; + if (month == null) + { + throw new Exception($"ImportMonth not found, {importWorker.Name}"); + } + var name = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportName")?.Desc1; + if (name == null) + { + throw new Exception($"ImportName not found, {importWorker.Name}"); + } + + var dataRange = importWorker.Records!.FirstOrDefault(x => x.Code == "DataRange")?.Desc1; + if (dataRange == null) + { + throw new Exception($"DataRange not found, {importWorker.Name}"); + } + + var layer = new Layer + { + Number = db.Layers.Count() + 1, + ParentId = importWorker.Id, + Type = LayerType.Import, + CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"), + ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"), + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow + }; + layer.Name = $"L{layer.Number}-I-{name}-{year}/{month}-{DateTime.Now.ToString("yyyyMMddHHmm", CultureInfo.InvariantCulture)}"; + + var newRecords = new List(); + + var dataRangeResponse = googleSheetValues.Get(sheetId, $"{sheetTabName}!{dataRange}").Execute(); + var data = dataRangeResponse.Values; + for (var i = 0; i < data.Count; i++) + { + if (data[i].Count <= 9 || (string)data[i][3] == string.Empty) continue; + var dateArr = data[i][1].ToString()!.Split("."); + if (dateArr.Length != 3) + { + throw new Exception($"Invalid date in row {i}"); + } + + var number = data[i][2].ToString()!; + if (number.Length == 1) number = $"0{number}"; + var code = dateArr[2] + dateArr[1] + dateArr[0] + number; + if (!(data[i][9].ToString()?.Length > 0) || + !double.TryParse(data[i][9].ToString(), CultureInfo.GetCultureInfo("pl-PL"), out var value)) continue; + var record = new Record + { + Id = Guid.NewGuid(), + Code = code, + Desc1 = data[i][3].ToString(), + Value1 = value, + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow + }; + newRecords.Add(record); + } + db.Layers.Add(layer); + // TODO: Save records to the layer + //controller.SaveRecords(layer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D")); + db.SaveChanges(); + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Plugins.Morska/Importers/morska.importer.cs b/src/Backend/DiunaBI.Plugins.Morska/Importers/morska.importer.cs new file mode 100644 index 0000000..146701c --- /dev/null +++ b/src/Backend/DiunaBI.Plugins.Morska/Importers/morska.importer.cs @@ -0,0 +1,81 @@ +using System.Globalization; +using Google.Apis.Sheets.v4; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +namespace DiunaBI.Plugins.Morska.Importers; + +public class MorskaImporter( + AppDbContext db, + SpreadsheetsResource.ValuesResource googleSheetValues) +{ + public void Import(Layer importWorker) + { + var sheetId = importWorker.Records!.FirstOrDefault(x => x.Code == "SheetId")?.Desc1; + if (sheetId == null) + { + throw new Exception($"SheetId not found, {importWorker.Name}"); + } + var sheetTabName = importWorker.Records!.FirstOrDefault(x => x.Code == "SheetTabName")?.Desc1; + if (sheetTabName == null) + { + throw new Exception($"SheetTabName not found, {importWorker.Name}"); + } + var year = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportYear")?.Desc1; + if (year == null) + { + throw new Exception($"ImportYear not found, {importWorker.Name}"); + } + var month = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportMonth")?.Desc1; + if (month == null) + { + throw new Exception($"ImportMonth not found, {importWorker.Name}"); + } + var name = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportName")?.Desc1; + if (name == null) + { + throw new Exception($"ImportName not found, {importWorker.Name}"); + } + + var dataRange = importWorker.Records!.FirstOrDefault(x => x.Code == "DataRange")?.Desc1; + if (dataRange == null) + { + throw new Exception($"DataRange not found, {importWorker.Name}"); + } + + var layer = new Layer + { + Number = db.Layers.Count() + 1, + ParentId = importWorker.Id, + Type = LayerType.Import, + CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"), + ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"), + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow + }; + layer.Name = $"L{layer.Number}-I-{name}-{year}/{month}-{DateTime.Now:yyyyMMddHHmm}"; + + var newRecords = new List(); + + var dataRangeResponse = googleSheetValues.Get(sheetId, $"{sheetTabName}!{dataRange}").Execute(); + var data = dataRangeResponse.Values; + for (var i = 0; i < data[1].Count; i++) + { + if (!(data[0][i].ToString()?.Length > 0) || + !double.TryParse(data[1][i].ToString(), CultureInfo.GetCultureInfo("pl-PL"), out var value)) continue; + var record = new Record + { + Id = Guid.NewGuid(), + Code = data[0][i].ToString(), + Value1 = value, + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow + }; + newRecords.Add(record); + } + db.Layers.Add(layer); + // TODO: Save records to the layer + //controller.SaveRecords(layer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D")); + db.SaveChanges(); + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Plugins.Morska/Processors/t1.r1.processor.cs b/src/Backend/DiunaBI.Plugins.Morska/Processors/t1.r1.processor.cs new file mode 100644 index 0000000..05d7726 --- /dev/null +++ b/src/Backend/DiunaBI.Plugins.Morska/Processors/t1.r1.processor.cs @@ -0,0 +1,287 @@ +using System.Globalization; +using Google.Apis.Sheets.v4; +using Google.Apis.Sheets.v4.Data; +using Microsoft.EntityFrameworkCore; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; +using DiunaBI.Core.Services; +using DiunaBI.Core.Services.Calculations; + +namespace DiunaBI.Plugins.Morska.Processors; + +public class T1R1Processor( + AppDbContext db, + SpreadsheetsResource.ValuesResource googleSheetValues) +{ + public void Process(Layer processWorker) + { + var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!); + var sources = processWorker.Records?.Where(x => x.Code == "Source").ToList(); + if (sources!.Count == 0) + { + throw new Exception("Source record not found"); + } + + var processedLayer = db.Layers + .Where(x => x.ParentId == processWorker.Id + && !x.IsDeleted && !x.IsCancelled) + .OrderByDescending(x => x.CreatedAt) + .FirstOrDefault(); + + var isNew = false; + if (processedLayer == null) + { + isNew = true; + processedLayer = new Layer + { + Id = Guid.NewGuid(), + Type = LayerType.Processed, + ParentId = processWorker.Id, + Number = db.Layers.Count() + 1 + }; + processedLayer.Name = $"L{processedLayer.Number}-P-{year}-R1-T1"; + processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.CreatedAt = DateTime.UtcNow; + processedLayer.ModifiedAt = DateTime.UtcNow; + } + + processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.ModifiedAt = DateTime.UtcNow; + + var dynamicCodes = processWorker.Records?.Where(x => x.Code!.Contains("DynamicCode-")) + .OrderBy(x => int.Parse(x.Code!.Split('-')[1])) + .ToList(); + + var newRecords = new List(); + + for (var month = 1; month < 14; month++) + { + if (year > DateTime.UtcNow.Year || ((year == DateTime.UtcNow.Year && month > DateTime.UtcNow.Month && month != 13))) + { + continue; + } + + var records = new List(); + foreach (var source in sources) + { + var monthCopy = month; + var dataSource = db.Layers.Where(x => + x.Type == LayerType.Processed && + !x.IsDeleted && !x.IsCancelled && + x.Name != null && x.Name.Contains($"{year}/{monthCopy:D2}-{source.Desc1}-T3") + ).Include(x => x.Records) + .AsNoTracking() + .FirstOrDefault(); + + if (dataSource == null) + { + throw new Exception($"Source layer {year}/{monthCopy}-{source.Desc1}-T3 not found."); + } + + var codesRecord = processWorker.Records?.Where(x => x.Code == $"Codes-{source.Desc1}").FirstOrDefault(); + if (codesRecord != null) + { + var codes = ProcessHelper.ParseCodes(codesRecord.Desc1!); + records.AddRange(dataSource.Records!.Where(x => codes.Contains(int.Parse(x.Code!)))); + } + else + { + records.AddRange(dataSource.Records!); + } + } + + if (dynamicCodes != null) + { + foreach (var dynamicCode in dynamicCodes) + { + try + { + if (dynamicCode.Desc1 == null) + { + //TODO throw exception or log warning + /* + logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Warning, + LogType = LogType.Process, + Message = $"Formula in Record {dynamicCode.Id} is missing.", + CreatedAt = DateTime.UtcNow + }); + */ + continue; + } + + var calc = new BaseCalc(dynamicCode.Desc1); + if (!calc.IsFormulaCorrect()) + { + //TODO throw exception or log warning + /* + logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Warning, + LogType = LogType.Process, + Message = $"Formula {calc.Expression} in Record {dynamicCode.Id} is not correct", + CreatedAt = DateTime.UtcNow + }); + */ + continue; + } + + try + { + records.Add(calc.CalculateT1(records)); + } + catch (Exception e) + { + //TODO throw exception or log warning + /* + logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Warning, + LogType = LogType.Process, + Message = + $"Formula {calc.Expression} in Record {dynamicCode.Id} error: {e.Message}", + CreatedAt = DateTime.UtcNow + }); + */ + } + } + catch (Exception e) + { + //TODO throw exception or log warning + /* + logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Warning, + LogType = LogType.Process, + Message = $"Calculation error {dynamicCode.Id}: {e.Message} ", + CreatedAt = DateTime.UtcNow + }); + */ + } + } + } + + newRecords.AddRange(records.Select(x => new Record + { + Id = Guid.NewGuid(), + Code = $"{x.Code}{month:D2}", + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow, + Value1 = x.Value32 + } + )); + } + + if (isNew) + { + db.Layers.Add(processedLayer); + } + else + { + db.Layers.Update(processedLayer); + } + //TODO: Save records to the layer + //controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D")); + db.SaveChanges(); + + var sheetName = processWorker.Records?.SingleOrDefault(x => x.Code == "GoogleSheetName")?.Desc1; + if (sheetName == null) + { + throw new Exception("GoogleSheetName record not found"); + } + + UpdateReport(processedLayer.Id, sheetName); + } + + private void UpdateReport(Guid sourceId, string sheetName) + { + const string sheetId = "1pph-XowjlK5CIaCEV_A5buK4ceJ0Z0YoUlDI4VMkhhA"; + var request = googleSheetValues.Get(sheetId, $"{sheetName}!C4:DA4"); + var response = request.Execute(); + + var r1 = db.Layers + .Where(x => x.Id == sourceId) + .Include(x => x.Records) + .AsNoTracking() + .FirstOrDefault(); + + var codesRow = response.Values[0]; + + var valueRange = new ValueRange + { + Values = new List>() + }; + + for (var i = 1; i <= 12; i++) + { + var values = new List(); + foreach (string code in codesRow) + { + var record = r1!.Records?.SingleOrDefault(x => x.Code == $"{code}{i:D2}"); + if (record != null) + { + values.Add(record.Value1!.Value); + } + else + { + values.Add("0"); + } + } + valueRange.Values.Add(values); + } + + // sum + var valuesSum = new List(); + var emptyRow = new List(); + foreach (string code in codesRow) + { + var record = r1!.Records?.SingleOrDefault(x => x.Code == $"{code}13"); + emptyRow.Add(""); + if (record != null) + { + valuesSum.Add(record.Value1!.Value); + } + else + { + valuesSum.Add("0"); + } + } + + valueRange.Values.Add(emptyRow); + valueRange.Values.Add(valuesSum); + + var update = googleSheetValues.Update(valueRange, sheetId, $"{sheetName}!C7:DA20"); + update.ValueInputOption = + SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED; + update.Execute(); + + // update time + var timeUtc = new List + { + r1!.ModifiedAt.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.GetCultureInfo("pl-PL")) + }; + var warsawTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time"); + var warsawTime = TimeZoneInfo.ConvertTimeFromUtc(r1.ModifiedAt.ToUniversalTime(), warsawTimeZone); + var timeWarsaw = new List + { + warsawTime.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.GetCultureInfo("pl-PL")) + }; + var valueRangeTime = new ValueRange + { + Values = new List>() + }; + valueRangeTime.Values.Add(timeUtc); + valueRangeTime.Values.Add(timeWarsaw); + + var updateTimeUtc = googleSheetValues.Update(valueRangeTime, sheetId, $"{sheetName}!G1:G2"); + updateTimeUtc.ValueInputOption = + SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED; + updateTimeUtc.Execute(); + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Plugins.Morska/Processors/t1.r3.processor.cs b/src/Backend/DiunaBI.Plugins.Morska/Processors/t1.r3.processor.cs new file mode 100644 index 0000000..95ad917 --- /dev/null +++ b/src/Backend/DiunaBI.Plugins.Morska/Processors/t1.r3.processor.cs @@ -0,0 +1,192 @@ +using System.Globalization; +using System.Text.RegularExpressions; +using DiunaBI.Core.Services; +using Google.Apis.Sheets.v4; +using Google.Apis.Sheets.v4.Data; +using Microsoft.EntityFrameworkCore; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +namespace DiunaBI.Plugins.Morska.Processors; + +public class T1R3Processor( + AppDbContext db, + SpreadsheetsResource.ValuesResource googleSheetValues) +{ + public void Process(Layer processWorker) + { + var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!); + var source = processWorker.Records?.Where(x => x.Code == "Source").First().Desc1; + if (source == null) + { + throw new Exception("Source record not found"); + } + + var processedLayer = db.Layers + .Where(x => x.ParentId == processWorker.Id + && !x.IsDeleted && !x.IsCancelled) + .OrderByDescending(x => x.CreatedAt) + .FirstOrDefault(); + + var isNew = false; + if (processedLayer == null) + { + isNew = true; + processedLayer = new Layer + { + Id = Guid.NewGuid(), + Type = LayerType.Processed, + ParentId = processWorker.Id, + Number = db.Layers.Count() + 1 + }; + processedLayer.Name = $"L{processedLayer.Number}-P-{year}-R3-T1"; + processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.CreatedAt = DateTime.UtcNow; + processedLayer.ModifiedAt = DateTime.UtcNow; + } + + processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.ModifiedAt = DateTime.UtcNow; + + + var newRecords = new List(); + + string pattern = @$"^L\d+-P-{year}/\d+-{source}-T5$"; + var dataSources = db.Layers + .Where(x => !x.IsDeleted && !x.IsCancelled) + .Include(layer => layer.Records!) + .AsNoTracking() + .AsEnumerable() + .Where(x => Regex.IsMatch(x.Name!, pattern)) + .ToList(); + + foreach (var dataSource in dataSources) + { + var month = ProcessHelper.ExtractMonthFromLayerName(dataSource.Name!); + if (month == null) + { + throw new Exception($"Month not found: {dataSource.Name}"); + } + + foreach (var record in dataSource.Records!) + { + if (record.Value1 == null) continue; + for (var i = 1; i < 33; i++) + { + if (ProcessHelper.GetValue(record, i) == null) continue; + + var newRecord = new Record + { + Id = Guid.NewGuid(), + Code = $"{record.Code}{month}{i:D2}", + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow, + Value1 = i == 1 ? record.Value1 : record.Value1 * ProcessHelper.GetValue(record, i) / 100, + Desc1 = record.Desc1 + }; + + newRecords.Add(newRecord); + } + } + } + + if (isNew) + { + db.Layers.Add(processedLayer); + } + else + { + db.Layers.Update(processedLayer); + } + //TODO save records + //controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D")); + db.SaveChanges(); + + UpdateReport(processedLayer.Id, year); + } + + private void UpdateReport(Guid sourceId, int year) + { + const string sheetId = "10Xo8BBF92nM7_JzzeOuWp49Gz8OsYuCxLDOeChqpW_8"; + + var r3 = db.Layers + .Where(x => x.Id == sourceId) + .Include(x => x.Records) + .AsNoTracking() + .FirstOrDefault(); + + for (var i = 1; i <= 12; i++) + { + var sheetName = ProcessHelper.GetSheetName(i, year); + ValueRange? dataRangeResponse; + try + { + dataRangeResponse = googleSheetValues.Get(sheetId, $"{sheetName}!A7:A200").Execute(); + } + catch + { + continue; // Sheet not exist + } + + if (dataRangeResponse == null) continue; // Sheet not exist + var data = dataRangeResponse.Values; + + var updateValueRange = new ValueRange + { + Values = new List>() + }; + + foreach (var row in data) + { + if (row.Count == 0) continue; + var code = row[0].ToString(); + + var updateRow = new List(); + + for (var j = 1; j < 16; j++) + { + var codeRecord = r3!.Records!.FirstOrDefault(x => x.Code == $"{code}{i:D2}{j:D2}"); + if (codeRecord is { Value1: not null }) + { + updateRow.Add(codeRecord.Value1); + } + else + { + updateRow.Add(""); + } + } + + updateValueRange.Values.Add(updateRow); + } + + dataRangeResponse.Values = data; + var update = googleSheetValues.Update(updateValueRange, sheetId, $"{sheetName}!C7:Q200"); + update.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED; + update.Execute(); + + // update time + var timeUtc = new List + { + r3!.ModifiedAt.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.GetCultureInfo("pl-PL")) + }; + var warsawTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time"); + var warsawTime = TimeZoneInfo.ConvertTimeFromUtc(r3.ModifiedAt.ToUniversalTime(), warsawTimeZone); + var timeWarsaw = new List + { + warsawTime.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.GetCultureInfo("pl-PL")) + }; + var valueRangeTime = new ValueRange + { + Values = new List>() + }; + valueRangeTime.Values.Add(timeUtc); + valueRangeTime.Values.Add(timeWarsaw); + + var updateTimeUtc = googleSheetValues.Update(valueRangeTime, sheetId, $"{sheetName}!G1:G2"); + updateTimeUtc.ValueInputOption = + SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED; + updateTimeUtc.Execute(); + } + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Plugins.Morska/Processors/t3.MultiSourceCopySelectedCodes.processor.cs b/src/Backend/DiunaBI.Plugins.Morska/Processors/t3.MultiSourceCopySelectedCodes.processor.cs new file mode 100644 index 0000000..7387d10 --- /dev/null +++ b/src/Backend/DiunaBI.Plugins.Morska/Processors/t3.MultiSourceCopySelectedCodes.processor.cs @@ -0,0 +1,98 @@ +using DiunaBI.Core.Services; +using Microsoft.EntityFrameworkCore; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +namespace DiunaBI.Plugins.Morska.Processors; + +public class T3MultiSourceCopySelectedCodesProcessor( + AppDbContext db) +{ + public void Process(Layer processWorker) + { + var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!); + var month = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1!); + var sources = processWorker.Records?.Where(x => x.Code == "Source").ToList(); + if (sources!.Count == 0) + { + throw new Exception("Source record not found"); + } + var codes = processWorker.Records?.SingleOrDefault(x => x.Code == "Codes")?.Desc1; + if (codes == null) + { + throw new Exception("Codes record not found"); + } + + var codesList = ProcessHelper.ParseCodes(codes); + + var processedLayer = db.Layers + .Where(x => x.ParentId == processWorker.Id + && !x.IsDeleted && !x.IsCancelled) + .OrderByDescending(x => x.CreatedAt) + .FirstOrDefault(); + + var isNew = false; + if (processedLayer == null) + { + isNew = true; + processedLayer = new Layer + { + Id = Guid.NewGuid(), + Type = LayerType.Processed, + ParentId = processWorker.Id, + Number = db.Layers.Count() + 1 + }; + processedLayer.Name = $"L{processedLayer.Number}-P-{year}/{month:D2}-AB-T3"; + processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.CreatedAt = DateTime.UtcNow; + processedLayer.ModifiedAt = DateTime.UtcNow; + } + + processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.ModifiedAt = DateTime.UtcNow; + + var dataSources = sources.Select(source => db.Layers + .Where(x => x.Type == LayerType.Processed && !x.IsDeleted && !x.IsCancelled && x.Name != null && x.Name.Contains($"{year}/{month:D2}-{source.Desc1}-T3")) + .Include(x => x.Records).AsNoTracking() + .FirstOrDefault()) + .OfType() + .ToList(); + if (dataSources.Count == 0) + { + throw new Exception("DataSources are empty"); + } + + + var newRecords = dataSources + .SelectMany(x => x.Records!) + .Where(x => codesList.Contains(int.Parse(x.Code!))) + .Select(x => + { + var newRecord = new Record + { + Id = Guid.NewGuid(), + Code = x.Code, + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow + }; + for (var i = 1; i < 33; i++) + { + ProcessHelper.SetValue(newRecord, i, ProcessHelper.GetValue(x, i)); + } + return newRecord; + }) + .ToList(); + if (isNew) + { + db.Layers.Add(processedLayer); + } + else + { + db.Layers.Update(processedLayer); + } + //TODO: Save records + //controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D")); + db.SaveChanges(); + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Plugins.Morska/Processors/t3.MultiSourceCopySelectedCodesYearSummary.processor.cs b/src/Backend/DiunaBI.Plugins.Morska/Processors/t3.MultiSourceCopySelectedCodesYearSummary.processor.cs new file mode 100644 index 0000000..ea9ad52 --- /dev/null +++ b/src/Backend/DiunaBI.Plugins.Morska/Processors/t3.MultiSourceCopySelectedCodesYearSummary.processor.cs @@ -0,0 +1,100 @@ +using DiunaBI.Core.Services; +using Microsoft.EntityFrameworkCore; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +namespace DiunaBI.Plugins.Morska.Processors; + +public class T3MultiSourceCopySelectedCodesYearSummaryProcessor( + AppDbContext db) +{ + public void Process(Layer processWorker) + { + var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!); + + var processedLayer = db.Layers + .Where(x => x.ParentId == processWorker.Id + && !x.IsDeleted && !x.IsCancelled) + .OrderByDescending(x => x.CreatedAt) + .FirstOrDefault(); + + var isNew = false; + if (processedLayer == null) + { + isNew = true; + processedLayer = new Layer + { + Id = Guid.NewGuid(), + Type = LayerType.Processed, + ParentId = processWorker.Id, + Number = db.Layers.Count() + 1 + }; + processedLayer.Name = $"L{processedLayer.Number}-P-{year}/13-AB-T3"; + processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.CreatedAt = DateTime.UtcNow; + processedLayer.ModifiedAt = DateTime.UtcNow; + } + + processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.ModifiedAt = DateTime.UtcNow; + + var newRecords = new List(); + + var dataSources = new List(); + + for (var i = 1; i < 13; i++) + { + var j = i; + var dataSource = db.Layers.Where(x => + x.Type == LayerType.Processed + && !x.IsDeleted && !x.IsCancelled + && x.Name != null && x.Name.Contains($"{year}/{j:D2}-AB-T3")) + .Include(x => x.Records) + .AsNoTracking() + .FirstOrDefault(); + if (dataSource != null) + { + dataSources.Add(dataSource); + } + } + + if (dataSources.Count == 0) + { + throw new Exception("DataSources are empty"); + } + + var allRecords = dataSources.SelectMany(x => x.Records!).ToList(); + + foreach (var baseRecord in dataSources.Last().Records!) + { + var codeRecords = allRecords.Where(x => x.Code == baseRecord.Code).ToList(); + var processedRecord = new Record + { + Id = Guid.NewGuid(), + Code = baseRecord.Code, + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow + }; + for (var i = 1; i < 33; i++) + { + ProcessHelper.SetValue(processedRecord, i, + codeRecords.Sum(x => ProcessHelper.GetValue(x, i))); + } + + newRecords.Add(processedRecord); + } + + if (isNew) + { + db.Layers.Add(processedLayer); + } + else + { + db.Layers.Update(processedLayer); + } + //TODO: save records + //controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D")); + db.SaveChanges(); + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Plugins.Morska/Processors/t3.MultiSourceSummary.processor.cs b/src/Backend/DiunaBI.Plugins.Morska/Processors/t3.MultiSourceSummary.processor.cs new file mode 100644 index 0000000..506fd75 --- /dev/null +++ b/src/Backend/DiunaBI.Plugins.Morska/Processors/t3.MultiSourceSummary.processor.cs @@ -0,0 +1,178 @@ +using DiunaBI.Core.Services; +using Microsoft.EntityFrameworkCore; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; +using DiunaBI.Core.Services.Calculations; + +namespace DiunaBI.Plugins.Morska.Processors; + +public class T3MultiSourceSummaryProcessor( + AppDbContext db) +{ + public void Process(Layer processWorker) + { + var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!); + var month = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1!); + var sources = processWorker.Records?.Where(x => x.Code == "Source").ToList(); + if (sources!.Count == 0) + { + throw new Exception("Source record not found"); + } + + var processedLayer = db.Layers + .Where(x => x.ParentId == processWorker.Id + && !x.IsDeleted && !x.IsCancelled) + .OrderByDescending(x => x.CreatedAt) + .FirstOrDefault(); + + var isNew = false; + if (processedLayer == null) + { + isNew = true; + processedLayer = new Layer + { + Id = Guid.NewGuid(), + Type = LayerType.Processed, + ParentId = processWorker.Id, + Number = db.Layers.Count() + 1 + }; + processedLayer.Name = $"L{processedLayer.Number}-P-{year}/{month:D2}-AA-T3"; + processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.CreatedAt = DateTime.UtcNow; + processedLayer.ModifiedAt = DateTime.UtcNow; + } + + processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.ModifiedAt = DateTime.UtcNow; + + var newRecords = new List(); + + var dataSources = sources.Select(source => db.Layers.Where(x => x.Type == LayerType.Processed && !x.IsDeleted && !x.IsCancelled && x.Name != null && x.Name.Contains($"{year}/{month:D2}-{source.Desc1}-T3")) + .Include(x => x.Records) + .AsNoTracking() + .FirstOrDefault()) + .OfType() + .ToList(); + + if (dataSources.Count == 0) + { + throw new Exception("DataSources are empty"); + } + + var allRecords = dataSources.SelectMany(x => x.Records!).ToList(); + var baseCodes = allRecords.Select(x => x.Code!.Remove(0, 1)).Distinct().ToList(); + + foreach (var baseCode in baseCodes) + { + + var codeRecords = allRecords.Where(x => + x.Code![1..] == baseCode) + .ToList(); + var processedRecord = new Record + { + Id = Guid.NewGuid(), + Code = $"9{baseCode}", + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow + }; + for (var i = 1; i < 33; i++) + { + ProcessHelper.SetValue(processedRecord, i, + codeRecords.Sum(x => ProcessHelper.GetValue(x, i))); + } + newRecords.Add(processedRecord); + } + + // Dynamic Codes + var dynamicCodes = processWorker.Records? + .Where(x => x.Code!.Contains("DynamicCode-")) + .OrderBy(x => int.Parse(x.Code!.Split('-')[1])).ToList(); + if (dynamicCodes != null && dynamicCodes.Count != 0) + { + foreach (var dynamicCode in dynamicCodes) + { + try + { + if (dynamicCode.Desc1 == null) + { + //TODO: log warning + /* + logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Warning, + LogType = LogType.Process, + Message = $"Formula in Record {dynamicCode.Id} is missing.", + CreatedAt = DateTime.UtcNow + }); + */ + continue; + } + var calc = new BaseCalc(dynamicCode.Desc1); + if (!calc.IsFormulaCorrect()) + { + //TODO: log warning + /* + logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Warning, + LogType = LogType.Process, + Message = $"Formula {calc.Expression} in Record {dynamicCode.Id} is not correct", + CreatedAt = DateTime.UtcNow + }); + */ + continue; + } + + try + { + newRecords.Add(calc.CalculateT3(newRecords)); + } + catch (Exception e) + { + //TODO: log warning + /* + logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Warning, + LogType = LogType.Process, + Message = $"Formula {calc.Expression} in Record {dynamicCode.Id} error: {e.Message}", + CreatedAt = DateTime.UtcNow + }); + */ + } + } + catch (Exception e) + { + // TODO: log warning + /* + logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Warning, + LogType = LogType.Process, + Message = $"Calculation error {dynamicCode.Id}: {e.Message} ", + CreatedAt = DateTime.UtcNow + }); + */ + } + } + } + + + if (isNew) + { + db.Layers.Add(processedLayer); + } + else + { + db.Layers.Update(processedLayer); + } + //TODO: save records + //controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D")); + db.SaveChanges(); + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Plugins.Morska/Processors/t3.MultiSourceYearSummary.processor.cs b/src/Backend/DiunaBI.Plugins.Morska/Processors/t3.MultiSourceYearSummary.processor.cs new file mode 100644 index 0000000..e95e037 --- /dev/null +++ b/src/Backend/DiunaBI.Plugins.Morska/Processors/t3.MultiSourceYearSummary.processor.cs @@ -0,0 +1,198 @@ +using Microsoft.EntityFrameworkCore; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; +using DiunaBI.Core.Services; +using DiunaBI.Core.Services.Calculations; + +namespace DiunaBI.Plugins.Morska.Processors; + +public class T3MultiSourceYearSummaryProcessor( + AppDbContext db) +{ + public void Process(Layer processWorker) + { + var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!); + var sources = processWorker.Records?.Where(x => x.Code == "Source").ToList(); + if (sources!.Count == 0) + { + throw new Exception("Source record not found"); + } + + var processedLayer = db.Layers + .Where(x => x.ParentId == processWorker.Id + && !x.IsDeleted && !x.IsCancelled) + .OrderByDescending(x => x.CreatedAt) + .FirstOrDefault(); + + var isNew = false; + if (processedLayer == null) + { + isNew = true; + processedLayer = new Layer + { + Id = Guid.NewGuid(), + Type = LayerType.Processed, + ParentId = processWorker.Id, + Number = db.Layers.Count() + 1 + }; + processedLayer.Name = $"L{processedLayer.Number}-P-{year}/13-AA-T3"; + processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.CreatedAt = DateTime.UtcNow; + processedLayer.ModifiedAt = DateTime.UtcNow; + } + + processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.ModifiedAt = DateTime.UtcNow; + + var newRecords = new List(); + + var dataSources = sources.Select(source => db.Layers.Where(x => x.Type == LayerType.Processed && !x.IsDeleted && !x.IsCancelled && x.Name != null && x.Name.Contains($"{year}/13-{source.Desc1}-T3")) + .Include(x => x.Records) + .AsNoTracking() + .FirstOrDefault()) + .OfType() + .ToList(); + if (dataSources.Count == 0) + { + throw new Exception("DataSources are empty"); + } + + if (dataSources.Count == 0) + { + throw new Exception("DataSourcesValidation are empty"); + } + + var allRecords = dataSources + .SelectMany(x => x.Records!).ToList(); + var baseCodes = allRecords.Select(x => x.Code!.Remove(0, 1)).Distinct().ToList(); + + foreach (var baseCode in baseCodes) + { + + var codeRecords = allRecords.Where(x => + x.Code![1..] == baseCode) + .ToList(); + var codeRecordsValidation = allRecords.Where(x => + x.Code![1..] == baseCode) + .ToList(); + var processedRecord = new Record + { + Id = Guid.NewGuid(), + Code = $"9{baseCode}", + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow + }; + var validationRecord = new Record(); + for (var i = 1; i < 33; i++) + { + ProcessHelper.SetValue(processedRecord, i, + codeRecords.Sum(x => ProcessHelper.GetValue(x, i))); + + ProcessHelper.SetValue(validationRecord, i, + codeRecordsValidation.Sum(x => ProcessHelper.GetValue(x, i))); + + if ( + double.Abs((double)(ProcessHelper.GetValue(processedRecord, i) - + ProcessHelper.GetValue(validationRecord, i))!) > 0.01) + { + throw new Exception($"ValidationError: Code {baseCode}, " + + $"Value{i} ({ProcessHelper.GetValue(processedRecord, i)} | " + + $"{ProcessHelper.GetValue(validationRecord, i)})"); + } + } + newRecords.Add(processedRecord); + } + + + + // Dynamic Codes + var dynamicCodes = processWorker.Records? + .Where(x => x.Code!.Contains("DynamicCode-")) + .OrderBy(x => int.Parse(x.Code!.Split('-')[1])).ToList(); + if (dynamicCodes != null && dynamicCodes.Count != 0) + { + foreach (var dynamicCode in dynamicCodes) + { + try + { + if (dynamicCode.Desc1 == null) + { + //TODO: log warning + /* + logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Warning, + LogType = LogType.Process, + Message = $"Formula in Record {dynamicCode.Id} is missing.", + CreatedAt = DateTime.UtcNow + }); + */ + continue; + } + var calc = new BaseCalc(dynamicCode.Desc1); + if (!calc.IsFormulaCorrect()) + { + //TODO: log warning + /* + logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Warning, + LogType = LogType.Process, + Message = $"Formula {calc.Expression} in Record {dynamicCode.Id} is not correct", + CreatedAt = DateTime.UtcNow + }); + */ + continue; + } + + try + { + newRecords.Add(calc.CalculateT3(newRecords)); + } + catch (Exception e) + { + //TODO: log warning + /* + logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Warning, + LogType = LogType.Process, + Message = $"Formula {calc.Expression} in Record {dynamicCode.Id} error: {e.Message}", + CreatedAt = DateTime.UtcNow + }); + */ + } + } + catch (Exception e) + { + //TODO: log warning + /* + logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Warning, + LogType = LogType.Process, + Message = $"Calculation error {dynamicCode.Id}: {e.Message} ", + CreatedAt = DateTime.UtcNow + }); + */ + } + } + } + if (isNew) + { + db.Layers.Add(processedLayer); + } + else + { + db.Layers.Update(processedLayer); + } + //TODO: save records + //controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D")); + db.SaveChanges(); + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Plugins.Morska/Processors/t3.SingleSource.processor.cs b/src/Backend/DiunaBI.Plugins.Morska/Processors/t3.SingleSource.processor.cs new file mode 100644 index 0000000..4f8bfdb --- /dev/null +++ b/src/Backend/DiunaBI.Plugins.Morska/Processors/t3.SingleSource.processor.cs @@ -0,0 +1,141 @@ +using Microsoft.EntityFrameworkCore; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; +using DiunaBI.Core.Services; + +namespace DiunaBI.Plugins.Morska.Processors; + +public class T3SingleSourceProcessor( + AppDbContext db) +{ + public void Process(Layer processWorker) + { + var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!); + var month = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1!); + var sourceLayer = processWorker.Records?.SingleOrDefault(x => x.Code == "SourceLayer")?.Desc1; + if (sourceLayer == null) + { + throw new Exception("SourceLayer record not found"); + } + var sourceImportWorker = db.Layers.SingleOrDefault(x => x.Name == sourceLayer && !x.IsDeleted && !x.IsCancelled); + if (sourceImportWorker == null) + { + throw new Exception("SourceImportWorkerL layer not found"); + } + var source = processWorker.Records?.SingleOrDefault(x => x.Code == "Source")?.Desc1; + if (sourceLayer == null) + { + throw new Exception("Source record not found"); + } + + var processedLayer = db.Layers + .Where(x => x.ParentId == processWorker.Id) + .OrderByDescending(x => x.CreatedAt) + .FirstOrDefault(); + + var isNew = false; + if (processedLayer == null) + { + isNew = true; + processedLayer = new Layer + { + Id = Guid.NewGuid(), + Type = LayerType.Processed, + ParentId = processWorker.Id, + Number = db.Layers.Count() + 1 + }; + processedLayer.Name = $"L{processedLayer.Number}-P-{year}/{month:D2}-{source}-T3"; + processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.CreatedAt = DateTime.UtcNow; + processedLayer.ModifiedAt = DateTime.UtcNow; + } + + processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.ModifiedAt = DateTime.UtcNow; + + + var newRecords = new List(); + + var dataSources = db.Layers + .Include(x => x.Records) + .Where(x => x.ParentId == sourceImportWorker.Id + && !x.IsDeleted && !x.IsCancelled) + .OrderBy(x => x.CreatedAt) + .AsNoTracking() + .ToList(); + if (dataSources.Count == 0) + { + throw new Exception($"DataSources are empty, {sourceImportWorker.Name}"); + } + + var allRecords = dataSources.SelectMany(x => x.Records!).ToList(); + + foreach (var baseRecord in dataSources.Last().Records!) + { + var codeRecords = allRecords.Where(x => x.Code == baseRecord.Code).ToList(); + + var processedRecord = new Record + { + Id = Guid.NewGuid(), + Code = baseRecord.Code, + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow + }; + + var lastDayInMonth = DateTime.DaysInMonth(year, month); + //day 1 + var firstVal = codeRecords + .Where(x => x.CreatedAt.Date <= new DateTime(year, month, 1)).MaxBy(x => x.CreatedAt)?.Value1 ?? 0; + ProcessHelper.SetValue(processedRecord, 1, firstVal); + var previousValue = firstVal; + //days 2-29/30 + for (var i = 2; i < lastDayInMonth; i++) + { + var dayVal = codeRecords + .Where(x => x.CreatedAt.Day == i && x.CreatedAt.Month == month).MaxBy(x => x.CreatedAt)?.Value1; + if (dayVal == null) + { + ProcessHelper.SetValue(processedRecord, i, 0); + } + else + { + var processedVal = dayVal - previousValue; + ProcessHelper.SetValue(processedRecord, i, processedVal); + previousValue = (double)dayVal; + } + } + //last day + var lastVal = codeRecords + .Where(x => x.CreatedAt.Date >= new DateTime(year, month, lastDayInMonth)).MaxBy(x => x.CreatedAt)?.Value1; + + if (lastVal == null) + { + ProcessHelper.SetValue(processedRecord, lastDayInMonth, 0); + } + else + { + ProcessHelper.SetValue(processedRecord, lastDayInMonth, (double)lastVal - previousValue); + } + + // copy last value + var valueToCopy = codeRecords.MaxBy(x => x.CreatedAt)?.Value1; + ProcessHelper.SetValue(processedRecord, 32, valueToCopy); + + newRecords.Add(processedRecord); + } + + if (isNew) + { + db.Layers.Add(processedLayer); + } + else + { + db.Layers.Update(processedLayer); + } + //TODO: save records + //controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D")); + db.SaveChanges(); + } + +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Plugins.Morska/Processors/t3.SourceYearSummary.processor.cs b/src/Backend/DiunaBI.Plugins.Morska/Processors/t3.SourceYearSummary.processor.cs new file mode 100644 index 0000000..3bf207c --- /dev/null +++ b/src/Backend/DiunaBI.Plugins.Morska/Processors/t3.SourceYearSummary.processor.cs @@ -0,0 +1,102 @@ +using Microsoft.EntityFrameworkCore; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; +using DiunaBI.Core.Services; + +namespace DiunaBI.Plugins.Morska.Processors; + +public class T3SourceYearSummaryProcessor( + AppDbContext db) +{ + public void Process(Layer processWorker) + { + var year = processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1; + var source = processWorker.Records?.SingleOrDefault(x => x.Code == "Source")?.Desc1; + if (source == null) + { + throw new Exception("Source record not found"); + } + var processedLayer = db.Layers + .Where(x => x.ParentId == processWorker.Id + && !x.IsDeleted && !x.IsCancelled) + .OrderByDescending(x => x.CreatedAt) + .FirstOrDefault(); + + var isNew = false; + if (processedLayer == null) + { + isNew = true; + processedLayer = new Layer + { + Id = Guid.NewGuid(), + Type = LayerType.Processed, + ParentId = processWorker.Id, + Number = db.Layers.Count() + 1 + }; + processedLayer.Name = $"L{processedLayer.Number}-P-{year}/13-{source}-T3"; + processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.CreatedAt = DateTime.UtcNow; + processedLayer.ModifiedAt = DateTime.UtcNow; + } + + processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.ModifiedAt = DateTime.UtcNow; + + var newRecords = new List(); + + var dataSources = new List(); + for (var i = 1; i < 13; i++) + { + var j = i; + var dataSource = db.Layers.Where(x => + x.Type == LayerType.Processed + && !x.IsDeleted && !x.IsCancelled + && x.Name != null && x.Name.Contains($"{year}/{j:D2}-{source}-T3")) + .Include(x => x.Records) + .AsNoTracking() + .FirstOrDefault(); + if (dataSource != null) + { + dataSources.Add(dataSource); + } + } + + if (dataSources.Count == 0) + { + throw new Exception("DataSources are empty"); + } + + var allRecords = dataSources.SelectMany(x => x.Records!).ToList(); + + foreach (var baseRecord in dataSources.Last().Records!) + { + var codeRecords = allRecords.Where(x => x.Code == baseRecord.Code).ToList(); + var processedRecord = new Record + { + Id = Guid.NewGuid(), + Code = baseRecord.Code, + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow + }; + for (var i = 1; i < 33; i++) + { + ProcessHelper.SetValue(processedRecord, i, + codeRecords.Sum(x => ProcessHelper.GetValue(x, i))); + } + newRecords.Add(processedRecord); + } + + if (isNew) + { + db.Layers.Add(processedLayer); + } + else + { + db.Layers.Update(processedLayer); + } + //TODO: save records + //controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D")); + db.SaveChanges(); + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Plugins.Morska/Processors/t4.SingleSource.processor.cs b/src/Backend/DiunaBI.Plugins.Morska/Processors/t4.SingleSource.processor.cs new file mode 100644 index 0000000..c881323 --- /dev/null +++ b/src/Backend/DiunaBI.Plugins.Morska/Processors/t4.SingleSource.processor.cs @@ -0,0 +1,95 @@ +using Microsoft.EntityFrameworkCore; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +namespace DiunaBI.Plugins.Morska.Processors; + +public class T4SingleSourceProcessor( + AppDbContext db) +{ + public void Process(Layer processWorker) + { + var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!); + var month = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1!); + var sourceLayer = processWorker.Records?.SingleOrDefault(x => x.Code == "SourceLayer")?.Desc1; + if (sourceLayer == null) + { + throw new Exception("SourceLayer record not found"); + } + var sourceImportWorker = db.Layers.SingleOrDefault(x => x.Name == sourceLayer && !x.IsDeleted && !x.IsCancelled); + if (sourceImportWorker == null) + { + throw new Exception("SourceImportWorkerL layer not found"); + } + var source = processWorker.Records?.SingleOrDefault(x => x.Code == "Source")?.Desc1; + if (sourceLayer == null) + { + throw new Exception("Source record not found"); + } + + var processedLayer = db.Layers + .Where(x => x.ParentId == processWorker.Id && + !x.IsDeleted && !x.IsCancelled) + .OrderByDescending(x => x.CreatedAt) + .FirstOrDefault(); + + var isNew = false; + if (processedLayer == null) + { + isNew = true; + processedLayer = new Layer + { + Id = Guid.NewGuid(), + Type = LayerType.Processed, + ParentId = processWorker.Id, + Number = db.Layers.Count() + 1 + }; + processedLayer.Name = $"L{processedLayer.Number}-P-{year}/{month:D2}-{source}-T4"; + processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.CreatedAt = DateTime.UtcNow; + processedLayer.ModifiedAt = DateTime.UtcNow; + } + + processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.ModifiedAt = DateTime.UtcNow; + + + var dataSource = db.Layers + .Include(x => x.Records) + .Where(x => x.ParentId == sourceImportWorker.Id + && !x.IsDeleted && !x.IsCancelled) + .OrderByDescending(x => x.CreatedAt) + .AsNoTracking() + .FirstOrDefault(); + + if (dataSource == null) + { + throw new Exception($"DataSource not found, {sourceImportWorker.Name}"); + } + + var newRecords = dataSource.Records!.Select(record => new Record + { + Id = Guid.NewGuid(), + Code = record.Code, + Desc1 = record.Desc1, + Value1 = record.Value1, + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow + }) + .ToList(); + + if (isNew) + { + db.Layers.Add(processedLayer); + } + else + { + db.Layers.Update(processedLayer); + } + // TODO: save records + //controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D")); + db.SaveChanges(); + } + +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Plugins.Morska/Processors/t4.r2.processor.cs b/src/Backend/DiunaBI.Plugins.Morska/Processors/t4.r2.processor.cs new file mode 100644 index 0000000..b4d93e5 --- /dev/null +++ b/src/Backend/DiunaBI.Plugins.Morska/Processors/t4.r2.processor.cs @@ -0,0 +1,362 @@ +using System.Globalization; +using Google.Apis.Sheets.v4; +using Google.Apis.Sheets.v4.Data; +using Microsoft.EntityFrameworkCore; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; +using DiunaBI.Core.Services; + + +namespace DiunaBI.Plugins.Morska.Processors; + +public class T4R2Processor( + AppDbContext db, + SpreadsheetsResource.ValuesResource googleSheetValues) +{ + public void Process(Layer processWorker) + { + var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!); + var sources = processWorker.Records?.Where(x => x.Code == "Source").ToList(); + if (sources!.Count == 0) + { + throw new Exception("Source record not found"); + } + + var layerName = processWorker.Records?.SingleOrDefault(x => x.Code == "LayerName")?.Desc1; + if (layerName == null) + { + throw new Exception("LayerName record not found"); + } + + + var processedLayer = db.Layers + .Where(x => x.ParentId == processWorker.Id + && !x.IsDeleted && !x.IsCancelled) + .OrderByDescending(x => x.CreatedAt) + .FirstOrDefault(); + + var isNew = false; + if (processedLayer == null) + { + isNew = true; + processedLayer = new Layer + { + Id = Guid.NewGuid(), + Type = LayerType.Processed, + ParentId = processWorker.Id, + Number = db.Layers.Count() + 1 + }; + processedLayer.Name = $"L{processedLayer.Number}-{layerName}"; + processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.CreatedAt = DateTime.UtcNow; + processedLayer.ModifiedAt = DateTime.UtcNow; + } + + processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.ModifiedAt = DateTime.UtcNow; + + + var newRecords = new List(); + + foreach (var source in sources) + { + var rawSourceCodes = processWorker.Records?.SingleOrDefault(x => x.Code == $"Codes-{source.Desc1}") + ?.Desc1; + var sourceCodes = new List(); + if (rawSourceCodes != null) + { + sourceCodes = ProcessHelper.ParseCodes(rawSourceCodes); + } + + List lastSourceCodes = []; + + for (var month = 1; month <= 12; month++) + { + if ((year == DateTime.UtcNow.Year && month <= DateTime.UtcNow.Month) || year < DateTime.UtcNow.Year) + { + var monthCopy = month; + var dataSource = db.Layers.Where(x => + x.Type == LayerType.Processed && + !x.IsDeleted && !x.IsCancelled && + x.Name != null && x.Name.Contains($"{year}/{monthCopy:D2}-{source.Desc1}-T") + ) + .Include(x => x.Records) + .AsNoTracking() + .FirstOrDefault(); + if (dataSource != null) + { + lastSourceCodes = dataSource.Records!.Select(x => x.Code!).ToList(); + var news = dataSource.Records! + .Where(x => sourceCodes.Count <= 0 || sourceCodes.Contains(int.Parse(x.Code!))) + .Select(x => + { + var newRecord = new Record + { + Id = Guid.NewGuid(), + Code = $"{x.Code}{month:D2}", + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow, + Value1 = source.Desc1 != "FK2" ? x.Value32 : x.Value1, + Desc1 = x.Desc1 + }; + return newRecord; + } + ).ToList(); + newRecords.AddRange(news); + } + else + { + // TODO: log warning + /* + logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Warning, + LogType = LogType.Process, + Message = $"Data source {year}/{month:D2}-{source.Desc1}-T3 not found", + CreatedAt = DateTime.UtcNow + }); + */ + } + } + else + { + //0 values for future months + if (source.Desc1 == "FK2" || lastSourceCodes.Count <= 0) continue; + var news = lastSourceCodes + .Where(x => sourceCodes.Contains(int.Parse(x))) + .Select(x => + { + var newRecord = new Record + { + Id = Guid.NewGuid(), + Code = $"{x}{month:D2}", + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow, + Value1 = 0, + }; + return newRecord; + } + ).ToList(); + newRecords.AddRange(news); + } + } + + // year summary + var dataSourceSum = db.Layers.Where(x => + x.Type == LayerType.Processed && + !x.IsDeleted && !x.IsCancelled && + x.Name != null && x.Name.Contains($"{year}/13-{source.Desc1}-T") + ) + .Include(x => x.Records) + .AsNoTracking() + .FirstOrDefault(); + if (dataSourceSum != null) + { + var news = dataSourceSum.Records! + .Where(x => sourceCodes.Count <= 0 || sourceCodes.Contains(int.Parse(x.Code!))) + .Select(x => + { + var newRecord = new Record + { + Id = Guid.NewGuid(), + Code = $"{x.Code}13", + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow, + Value1 = x.Value32 + }; + return newRecord; + } + ).ToList(); + newRecords.AddRange(news); + } + else + { + // TODO: log warning + /* + logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Warning, + LogType = LogType.Process, + Message = $"Data source {year}/13-{source.Desc1}-T3 not found", + CreatedAt = DateTime.UtcNow + }); + */ + } + } + + if (isNew) + { + db.Layers.Add(processedLayer); + } + else + { + db.Layers.Update(processedLayer); + } + // TODO: save records + //controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D")); + db.SaveChanges(); + + var reportSheetName = processWorker.Records?.SingleOrDefault(x => x.Code == "GoogleSheetName")?.Desc1; + if (reportSheetName == null) + { + throw new Exception("GoogleSheetName record not found"); + } + + var invoicesSheetName = processWorker.Records?.SingleOrDefault(x => x.Code == "GoogleSheetName-Invoices")?.Desc1; + if (invoicesSheetName == null) + { + throw new Exception("GoogleSheetName-Invoices record not found"); + } + UpdateReport(processedLayer.Id, reportSheetName, invoicesSheetName); + } + + private void UpdateReport(Guid sourceId, string reportSheetName, string invoicesSheetName) + { + const string sheetId = "1FsUmk_YRIeeGzFCX9tuUJCaLyRtjutX2ZGAEU1DMfJQ"; + var request = googleSheetValues.Get(sheetId, "C4:Z4"); + var response = request.Execute(); + + var r2 = db.Layers + .Where(x => x.Id == sourceId && !x.IsDeleted && !x.IsCancelled) + .Include(x => x.Records) + .AsNoTracking() + .FirstOrDefault(); + + const int startRow = 6; + + var codesRow = response.Values[0]; + for (var i = 1; i <= 12; i++) + { + var values = new List(); + var month = i < 10 ? $"0{i}" : i.ToString(); + var row = (startRow + i).ToString(); + foreach (string code in codesRow) + { + var record = r2!.Records?.SingleOrDefault(x => x.Code == $"{code}{month}"); + if (record != null) + { + values.Add(record.Value1!.Value); + } + else + { + values.Add("0"); + } + } + var valueRange = new ValueRange + { + Values = new List> { values } + }; + var update = googleSheetValues.Update(valueRange, sheetId, $"{reportSheetName}!C{row}:XZ{row}"); + update.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED; + update.Execute(); + } + + // sum + var valuesSum = new List(); + var emptyRow = new List(); + var rowEmpty = (startRow + 13).ToString(); + var rowSum = (startRow + 14).ToString(); + foreach (string code in codesRow) + { + var record = r2!.Records?.SingleOrDefault(x => x.Code == $"{code}13"); + emptyRow.Add(""); + if (record != null) + { + valuesSum.Add(record.Value1!.Value); + } + else + { + valuesSum.Add("0"); + } + } + // insert empty row before sum + var valueRangeEmpty = new ValueRange + { + Values = new List> { emptyRow } + }; + var updateEmpty = googleSheetValues.Update(valueRangeEmpty, sheetId, $"{reportSheetName}!C{rowEmpty}:XZ{rowEmpty}"); + updateEmpty.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED; + updateEmpty.Execute(); + + var valueRangeSum = new ValueRange + { + Values = new List> { valuesSum } + }; + var updateSum = googleSheetValues.Update(valueRangeSum, sheetId, $"{reportSheetName}!C{rowSum}:XZ{rowSum}"); + updateSum.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED; + updateSum.Execute(); + + // update time + var timeUtc = new List + { + r2!.ModifiedAt.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.GetCultureInfo("pl-PL")) + }; + var valueRangeUtcTime = new ValueRange + { + Values = new List> { timeUtc } + }; + var updateTimeUtc = googleSheetValues.Update(valueRangeUtcTime, sheetId, $"{reportSheetName}!G1"); + updateTimeUtc.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED; + updateTimeUtc.Execute(); + + var warsawTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time"); + var warsawTime = TimeZoneInfo.ConvertTimeFromUtc(r2.ModifiedAt.ToUniversalTime(), warsawTimeZone); + var timeWarsaw = new List + { + warsawTime.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.GetCultureInfo("pl-PL")) + }; + var valueRangeWarsawTime = new ValueRange + { + Values = new List> { timeWarsaw } + }; + var updateTimeWarsaw = googleSheetValues.Update(valueRangeWarsawTime, sheetId, $"{reportSheetName}!G2"); + updateTimeWarsaw.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED; + updateTimeWarsaw.Execute(); + + //invoices + + var invoices = r2.Records!.Where(x => x.Code!.Length == 12) + .OrderByDescending(x => x.Code); + + var invoicesValues = new List>(); + var cleanUpValues = new List>(); + foreach (var invoice in invoices) + { + var invoiceDate = + DateTime.ParseExact(invoice.Code!.Substring(0, 8), "yyyyMMdd", CultureInfo.InvariantCulture) + .ToString("dd.MM.yyyy", CultureInfo.GetCultureInfo("pl-PL")); + var invoiceRow = new List + { + invoiceDate, + "", + invoice.Desc1!, + invoice.Value1! + }; + invoicesValues.Add(invoiceRow); + + var cleanupRow = new List + { + "", "", "", "" + }; + cleanUpValues.Add(cleanupRow); + } + + + var cleanupValueRange = new ValueRange { Values = cleanUpValues }; + var cleanupInvoices = googleSheetValues.Update(cleanupValueRange, sheetId, $"{invoicesSheetName}!A6:E"); + cleanupInvoices.ValueInputOption = + SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED; + cleanupInvoices.Execute(); + + + var invoicesValueRange = new ValueRange { Values = invoicesValues }; + var updateInvoices = googleSheetValues.Update(invoicesValueRange, sheetId, $"{invoicesSheetName}!A6:E"); + updateInvoices.ValueInputOption = + SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED; + updateInvoices.Execute(); + + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Plugins.Morska/Processors/t5.LastValues.processor.cs b/src/Backend/DiunaBI.Plugins.Morska/Processors/t5.LastValues.processor.cs new file mode 100644 index 0000000..2095ea5 --- /dev/null +++ b/src/Backend/DiunaBI.Plugins.Morska/Processors/t5.LastValues.processor.cs @@ -0,0 +1,95 @@ +using DiunaBI.Core.Services; +using Microsoft.EntityFrameworkCore; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +namespace DiunaBI.Plugins.Morska.Processors; + +public class T5LastValuesProcessor( + AppDbContext db) +{ + public void Process(Layer processWorker) + { + var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!); + var month = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1!); + var sourceLayer = processWorker.Records?.SingleOrDefault(x => x.Code == "SourceLayer")?.Desc1; + if (sourceLayer == null) throw new Exception("SourceLayer record not found"); + var sourceImportWorker = db.Layers.SingleOrDefault(x => x.Name == sourceLayer && !x.IsDeleted && !x.IsCancelled); + if (sourceImportWorker == null) throw new Exception("SourceImportWorker layer not found"); + var source = processWorker.Records?.SingleOrDefault(x => x.Code == "Source")?.Desc1; + if (sourceLayer == null) throw new Exception("Source record not found"); + + var processedLayer = db.Layers + .Where(x => x.ParentId == processWorker.Id + && !x.IsDeleted && !x.IsCancelled) + .OrderByDescending(x => x.CreatedAt) + .FirstOrDefault(); + + var isNew = false; + if (processedLayer == null) + { + isNew = true; + processedLayer = new Layer + { + Id = Guid.NewGuid(), + Type = LayerType.Processed, + ParentId = processWorker.Id, + Number = db.Layers.Count() + 1 + }; + processedLayer.Name = $"L{processedLayer.Number}-P-{year}/{month:D2}-{source}-T5"; + processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.CreatedAt = DateTime.UtcNow; + processedLayer.ModifiedAt = DateTime.UtcNow; + } + + processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"); + processedLayer.ModifiedAt = DateTime.UtcNow; + + var newRecords = new List(); + + var dataSources = db.Layers + .Include(x => x.Records) + .Where(x => x.ParentId == sourceImportWorker.Id + && !x.IsDeleted && !x.IsCancelled) + .OrderByDescending(x => x.CreatedAt) + .AsNoTracking() + .ToList(); + + if (dataSources.Count == 0) throw new Exception($"DataSource is empty, {sourceImportWorker.Name}"); + + var codes = dataSources.SelectMany(x => x.Records!).Select(x => x.Code).Distinct().ToList(); + + foreach (var code in codes) + { + var lastRecord = dataSources.SelectMany(x => x.Records!).Where(x => x.Code == code).OrderByDescending(x => x.CreatedAt).FirstOrDefault(); + if (lastRecord == null) continue; + + var processedRecord = new Record + { + Id = Guid.NewGuid(), + Code = code, + CreatedAt = DateTime.UtcNow, + ModifiedAt = DateTime.UtcNow + }; + + for (var i = 1; i < 33; i++) + { + if (ProcessHelper.GetValue(lastRecord, i) != null) + { + ProcessHelper.SetValue(processedRecord, i, ProcessHelper.GetValue(lastRecord, i)); + } + } + + newRecords.Add(processedRecord); + } + + if (isNew) + db.Layers.Add(processedLayer); + else + db.Layers.Update(processedLayer); + // TODO: save records + //controller.SaveRecords(processedLayer.Id, newRecords, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D")); + db.SaveChanges(); + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.WebAPI/Controllers/AdminController.cs b/src/Backend/DiunaBI.WebAPI/Controllers/AdminController.cs new file mode 100644 index 0000000..ad4b843 --- /dev/null +++ b/src/Backend/DiunaBI.WebAPI/Controllers/AdminController.cs @@ -0,0 +1,28 @@ +using System.Data; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Data.SqlClient; +using DiunaBI.Core.Models; + +namespace DiunaBI.Core.Controllers; + +[ApiController] +[Route("api/[controller]")] +public class AdminController : Controller +{ + + private readonly IConfiguration _configuration; + + public AdminController( + IConfiguration configuration) + { + _configuration = configuration; + } + + [HttpGet] + [Route("Version")] + public IActionResult GetVersion() + { + return Ok(new { version = _configuration["app-version"] }); + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.WebAPI/Controllers/AuthController.cs b/src/Backend/DiunaBI.WebAPI/Controllers/AuthController.cs new file mode 100644 index 0000000..7ae6717 --- /dev/null +++ b/src/Backend/DiunaBI.WebAPI/Controllers/AuthController.cs @@ -0,0 +1,60 @@ +using Google.Apis.Auth; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.IdentityModel.Tokens; +using System.IdentityModel.Tokens.Jwt; +using System.Security.Claims; +using System.Text; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; + +namespace DiunaBI.WebAPI.Controllers; + +[ApiController] +[Route("api/[controller]")] +// [Authorize] +public class AuthController : Controller +{ + private readonly AppDbContext _db; + private readonly IConfiguration _configuration; + public AuthController( + AppDbContext db, IConfiguration configuration) + { _db = db; _configuration = configuration; } + + [HttpPost] + [Route("apiToken")] + public async Task ApiToken([FromBody] string credential) + { + var settings = new GoogleJsonWebSignature.ValidationSettings + { + Audience = new List { _configuration.GetValue("GoogleClientId")! } + }; + var payload = await GoogleJsonWebSignature.ValidateAsync(credential, settings); + var user = _db.Users.AsNoTracking().FirstOrDefault(x => x.Email == payload.Email); + return user != null ? (IActionResult)Ok(JwtGenerator(user)) : Unauthorized(); + } + + private dynamic JwtGenerator(User user) + { + var key = Encoding.ASCII.GetBytes(_configuration.GetValue("Secret")!); + var expirationTime = DateTime.UtcNow.AddMinutes(5); + var tokenDescriptor = new SecurityTokenDescriptor + { + Subject = new ClaimsIdentity(new[] + { + new Claim("Id", Guid.NewGuid().ToString()), + new Claim(JwtRegisteredClaimNames.Sub, user.Id.ToString()), + new Claim(JwtRegisteredClaimNames.Jti, + Guid.NewGuid().ToString()) + }), + Expires = expirationTime, + SigningCredentials = new SigningCredentials + (new SymmetricSecurityKey(key), + SecurityAlgorithms.HmacSha512Signature) + }; + var tokenHandler = new JwtSecurityTokenHandler(); + var token = tokenHandler.CreateToken(tokenDescriptor); + var stringToken = tokenHandler.WriteToken(token); + return new { token = stringToken, id = user.Id, expirationTime }; + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.WebAPI/Controllers/DataInboxController.cs b/src/Backend/DiunaBI.WebAPI/Controllers/DataInboxController.cs new file mode 100644 index 0000000..569495a --- /dev/null +++ b/src/Backend/DiunaBI.WebAPI/Controllers/DataInboxController.cs @@ -0,0 +1,168 @@ +using System.Text; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using DiunaBI.Database.Context; +using Google.Cloud.Firestore; +using DiunaBI.Core.Models; + +namespace DiunaBI.WebAPI.Controllers; + +[ApiController] +[Route("api/[controller]")] +public class DataInboxController : Controller +{ + private readonly AppDbContext _db; + private readonly IConfiguration _configuration; + private readonly LogsController _logsController; + + public DataInboxController( + AppDbContext db, + IConfiguration configuration, + FirestoreDb firestoreDb) + { + _db = db; + _configuration = configuration; + _logsController = new LogsController(firestoreDb); + } + + [HttpPut] + [Route("Add/{apiKey}")] + [AllowAnonymous] + public IActionResult Add(string apiKey, [FromBody] DataInbox dataInbox) + { + if (apiKey != _configuration["apiKey"]) + { + _logsController.AddEntry(new LogEntry + { + Title = $"Unauthorized request - wrong apiKey ({dataInbox.Source})", + Type = LogEntryType.Warning, + LogType = LogType.DataInbox, + CreatedAt = DateTime.UtcNow + }); + return Unauthorized(); + } + + try + { + if ( + !Request.Headers.TryGetValue("Authorization", out var authHeader)) + { + _logsController.AddEntry(new LogEntry + { + Title = $"Unauthorized request - no authorization header ({dataInbox.Source})", + Type = LogEntryType.Warning, + LogType = LogType.DataInbox, + CreatedAt = DateTime.UtcNow + }); + return Unauthorized(); + } + + var credentialsArr = authHeader.ToString().Split(" "); + if (credentialsArr.Length != 2) + { + _logsController.AddEntry(new LogEntry + { + Title = $"Unauthorized request - wrong auth header format ({dataInbox.Source})", + Type = LogEntryType.Warning, + LogType = LogType.DataInbox, + CreatedAt = DateTime.UtcNow + }); + return Unauthorized(); + } + + var authValue = Encoding.UTF8.GetString(Convert.FromBase64String(credentialsArr[1])); + var username = authValue.Split(':')[0]; + var password = authValue.Split(':')[1]; + if (username != _configuration["morska-user"] || password != _configuration["morska-pass"]) + { + _logsController.AddEntry(new LogEntry + { + Title = $"Unauthorized request - bad credentials ({dataInbox.Source})", + Type = LogEntryType.Warning, + LogType = LogType.DataInbox, + CreatedAt = DateTime.UtcNow + }); + return Unauthorized(); + } + + // check if datainbox.data is base64 encoded value + if (!string.IsNullOrEmpty(dataInbox.Data) && !IsBase64String(dataInbox.Data)) + { + _logsController.AddEntry(new LogEntry + { + Title = $"Invalid data format - not base64 encoded ({dataInbox.Source})", + Type = LogEntryType.Warning, + LogType = LogType.DataInbox, + CreatedAt = DateTime.UtcNow + }); + return BadRequest("Invalid data format - not base64 encoded"); + } + + + dataInbox.Id = Guid.NewGuid(); + dataInbox.CreatedAt = DateTime.UtcNow; + _db.DataInbox.Add(dataInbox); + _db.SaveChanges(); + + _logsController.AddEntry(new LogEntry + { + Title = $"Insert success: {dataInbox.Source}, {dataInbox.Name}", + Type = LogEntryType.Info, + LogType = LogType.DataInbox, + CreatedAt = DateTime.UtcNow + }); + + if (dataInbox.Name == "morska.d3.importer") + { + // TODO: import dataInbox as Layer + } + + return Ok(); + } + catch (Exception e) + { + _logsController.AddEntry(new LogEntry + { + Title = $"Insert error: {dataInbox.Source}, {dataInbox.Name}", + Type = LogEntryType.Error, + LogType = LogType.DataInbox, + Message = e.ToString(), + CreatedAt = DateTime.UtcNow + }); + return BadRequest(e.ToString()); + } + } + + [HttpGet] + public IActionResult GetAll() + { + return Ok(_db.DataInbox.AsNoTracking().ToList()); + } + + // helpers + private bool IsBase64String(string data) + { + if (string.IsNullOrEmpty(data)) + { + return false; + } + try + { + var base64Bytes = Convert.FromBase64String(data); + + var utf8String = Encoding.UTF8.GetString(base64Bytes); + + var reEncoded = Convert.ToBase64String(Encoding.UTF8.GetBytes(utf8String)); + return data.TrimEnd('=') == reEncoded.TrimEnd('='); + } + catch (FormatException) + { + return false; + } + catch (DecoderFallbackException) + { + return false; + } + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.WebAPI/Controllers/LayersController.cs b/src/Backend/DiunaBI.WebAPI/Controllers/LayersController.cs new file mode 100644 index 0000000..612e5e5 --- /dev/null +++ b/src/Backend/DiunaBI.WebAPI/Controllers/LayersController.cs @@ -0,0 +1,857 @@ +using System.Globalization; +using System.Text; +using Google.Apis.Sheets.v4; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; +using DiunaBI.Core.Services; +using Google.Cloud.Firestore; +using DiunaBI.Plugins.Morska.Importers; +using DiunaBI.Plugins.Morska.Processors; +using DiunaBI.Core.Services.Exports; + +namespace DiunaBI.WebAPI.Controllers; + +[ApiController] +[Route("api/[controller]")] +public class LayersController : Controller +{ + private readonly AppDbContext _db; + private readonly SpreadsheetsResource.ValuesResource? _googleSheetValues; + private readonly GoogleDriveHelper _googleDriveHelper; + private readonly IConfiguration _configuration; + private readonly LogsController _logsController; + + public LayersController( + AppDbContext db, + GoogleSheetsHelper googleSheetsHelper, + GoogleDriveHelper googleDriveHelper, + IConfiguration configuration, + FirestoreDb firestoreDb + ) + { + _db = db; + if (googleSheetsHelper.Service is not null) + { + _googleSheetValues = googleSheetsHelper.Service.Spreadsheets.Values; + } + + _googleDriveHelper = googleDriveHelper; + _configuration = configuration; + _logsController = new LogsController(firestoreDb); + } + + [HttpGet] + public IActionResult GetAll(int start, int limit, string? name, LayerType? type) + { + try + { + var response = _db.Layers.Where(x => !x.IsDeleted); + if (name != null) + { + response = response.Where(x => x.Name != null && x.Name.Contains(name)); + } + + if (type != null) + { + response = response.Where(x => x.Type == type); + } + + return Ok(response + .OrderByDescending(x => x.Number) + .Skip(start).Take(limit).AsNoTracking().ToList()); + } + catch (Exception e) + { + return BadRequest(e.ToString()); + } + } + + [HttpGet] + [Route("{id:guid}")] + public IActionResult Get(Guid id) + { + try + { + return Ok(_db.Layers + .Include(x => x.CreatedBy) + .Include(x => x.ModifiedBy) + .Include(x => x.Records).AsNoTracking().First(x => x.Id == id && !x.IsDeleted)); + } + catch (Exception e) + { + return BadRequest(e.ToString()); + } + } + + [HttpGet] + [Route("getForPowerBI/{apiKey}/{number:int}")] + public IActionResult GetByNumber(string apiKey, int number) + { + if (apiKey != _configuration["apiKey"]) + { + _logsController.AddEntry(new LogEntry + { + Title = $"Unauthorized request - wrong apiKey ({number})", + Type = LogEntryType.Warning, + LogType = LogType.PowerBi, + CreatedAt = DateTime.UtcNow + }); + return Unauthorized(); + } + + try + { + if ( + !Request.Headers.TryGetValue("Authorization", out var authHeader)) + { + _logsController.AddEntry(new LogEntry + { + Title = $"Unauthorized request - no authorization header ({number})", + Type = LogEntryType.Warning, + LogType = LogType.PowerBi, + CreatedAt = DateTime.UtcNow + }); + return Unauthorized(); + } + + var credentialsArr = authHeader.ToString().Split(" "); + if (credentialsArr.Length != 2) + { + _logsController.AddEntry(new LogEntry + { + Title = $"Unauthorized request - wrong auth header format ({number})", + Type = LogEntryType.Warning, + LogType = LogType.PowerBi, + CreatedAt = DateTime.UtcNow + }); + return Unauthorized(); + } + + var authValue = Encoding.UTF8.GetString(Convert.FromBase64String(credentialsArr[1])); + var username = authValue.Split(':')[0]; + var password = authValue.Split(':')[1]; + if (username != _configuration["powerBI-user"] || password != _configuration["powerBI-pass"]) + { + _logsController.AddEntry(new LogEntry + { + Title = $"Unauthorized request - bad credentials ({number})", + Type = LogEntryType.Warning, + LogType = LogType.PowerBi, + CreatedAt = DateTime.UtcNow + }); + return Unauthorized(); + } + + _logsController.AddEntry(new LogEntry + { + Title = $"Sending data for layer {number}", + Type = LogEntryType.Info, + LogType = LogType.PowerBi, + CreatedAt = DateTime.UtcNow + }); + + return Ok(_db.Layers + .Include(x => x.CreatedBy) + .Include(x => x.Records).AsNoTracking().First(x => x.Number == number && !x.IsDeleted)); + } + catch (Exception e) + { + _logsController.AddEntry(new LogEntry + { + Title = e.ToString(), + Type = LogEntryType.Error, + LogType = LogType.PowerBi, + CreatedAt = DateTime.UtcNow + }); + return BadRequest(e.ToString()); + } + } + + [HttpGet] + [Route("getConfiguration/{apiKey}/{number:int}")] + public IActionResult GetConfigurationByNumber(string apiKey, int number) + { + if (apiKey != _configuration["apiKey"]) + { + return Unauthorized(); + } + + try + { + if ( + !Request.Headers.TryGetValue("Authorization", out var authHeader)) + { + return Unauthorized(); + } + + var credentialsArr = authHeader.ToString().Split(" "); + if (credentialsArr.Length != 2) + { + return Unauthorized(); + } + + var authValue = Encoding.UTF8.GetString(Convert.FromBase64String(credentialsArr[1])); + var username = authValue.Split(':')[0]; + var password = authValue.Split(':')[1]; + if (username != _configuration["morska-user"] || password != _configuration["morska-pass"]) + { + return Unauthorized(); + } + + var config = _db.Layers + .Include(x => x.Records) + .AsNoTracking() + .First(x => x.Number == number && !x.IsDeleted); + + if (config is null) + { + return BadRequest(); + } + + var type = config.Records?.Where(x => x.Code == "Type").FirstOrDefault(); + if (type is null || type.Desc1 != "ExternalConfiguration") + { + return BadRequest(); + } + + return Ok(config); + } + catch + { + return BadRequest(); + } + } + + [HttpGet] + [Route("exportToGoogleSheet/{id:guid}")] + public IActionResult ExportToGoogleSheet(Guid id) + { + if (_googleSheetValues is null) + { + throw new Exception("Google Sheets API not initialized"); + } + + var layer = _db.Layers + .Include(x => x.Records!.OrderByDescending(y => y.Code)).AsNoTracking().First(x => x.Id == id && !x.IsDeleted); + + var export = new GoogleSheetExport(_googleDriveHelper, _googleSheetValues, _configuration); + export.Export(layer); + return Ok(true); + } + + [HttpGet] + [Route("AutoImportWithQueue/{apiKey}")] + [AllowAnonymous] + public IActionResult AutoImportWithQueue(string apiKey) + { + if (Request.Host.Value != _configuration["apiLocalUrl"] || apiKey != _configuration["apiKey"]) + { + return Unauthorized(); + } + + var importWorkerLayers = _db.Layers + .Include(x => x.Records) + .Where(x => + x.Records!.Any(y => y.Code == "Type" && y.Desc1 == "ImportWorker") && + x.Records!.Any(y => y.Code == "IsEnabled" && y.Desc1 == "True") + ) + .OrderBy(x => x.CreatedAt) + .AsNoTracking() + .ToList(); + + if (importWorkerLayers.Count == 0) + { + _logsController.AddEntry(new LogEntry + { + Title = "No Layers to import.", + Type = LogEntryType.Info, + LogType = LogType.Queue, + CreatedAt = DateTime.UtcNow + }); + return Ok(); + } + + foreach (var importWorker in importWorkerLayers) + { + try + { + /* + await _queue.AddJob(new QueueJob + { + LayerId = importWorker.Id, + Type = JobType.ImportWorker, + }); + */ + } + catch (Exception e) + { + _logsController.AddEntry(new LogEntry + { + Title = $"Error while adding job into queue (import): {importWorker.Name}, {importWorker.Id}", + Type = LogEntryType.Error, + LogType = LogType.Queue, + Message = e.ToString(), + CreatedAt = DateTime.UtcNow + }); + } + } + return Ok(); + } + + [HttpGet] + [Route("ProcessQueue/{apiKey}")] + [AllowAnonymous] + public IActionResult ProcessQueue(string apiKey) + { + /* + var allJobs = await _queue.GetJobs(); + var importJobs = allJobs + .Where(x => x.Type == JobType.ImportWorker && x.Status == JobStatus.New); + + foreach (var job in importJobs) + { + job.Attempts = job.Attempts + 1; + //await _queue.UpdateJob(job); + } + */ + return Ok(); + } + + [HttpGet] + [Route("AutoImport/{apiKey}/{nameFilter}")] + [AllowAnonymous] + public IActionResult AutoImport(string apiKey, string nameFilter) + { + if (Request.Host.Value != _configuration["apiLocalUrl"] || apiKey != _configuration["apiKey"]) + { + return Unauthorized(); + } + + if (_googleSheetValues is null) + { + throw new Exception("Google Sheets API not initialized"); + } + + var importWorkerLayers = _db.Layers + .Include(x => x.Records) + .Where(x => + x.Name != null && x.Name.Contains(nameFilter) && + x.Records!.Any(y => y.Code == "Type" && y.Desc1 == "ImportWorker") && + x.Records!.Any(y => y.Code == "IsEnabled" && y.Desc1 == "True") + ) + .OrderByDescending(x => x.CreatedAt) + .AsNoTracking() + .ToList(); + _logsController.AddEntry(new LogEntry + { + Title = $"Starting import: {nameFilter}, Admin layers count ({importWorkerLayers.Count})", + Type = LogEntryType.Info, + LogType = LogType.Import, + CreatedAt = DateTime.UtcNow + }); + try + { + if (importWorkerLayers.Count == 0) + { + _logsController.AddEntry(new LogEntry + { + Title = "No Layers to import.", + Type = LogEntryType.Info, + LogType = LogType.Import, + CreatedAt = DateTime.UtcNow + }); + return Ok(); + } + + foreach (var importWorker in importWorkerLayers) + { + try + { + var type = importWorker.Records!.FirstOrDefault(x => x.Code == "ImportType")?.Desc1 ?? + "Standard"; + var source = importWorker.Records!.FirstOrDefault(x => x.Code == "Source")?.Desc1 ?? + "GoogleSheet"; + if (source == "DataInbox" && type == "Import-D3") + { + var d3Importer = new MorskaD3Importer(_db); + d3Importer.Import(importWorker); + _logsController.AddEntry(new LogEntry + { + Title = $"{importWorker.Name}, {importWorker.Id}", + Type = LogEntryType.Info, + LogType = LogType.Import, + Message = "Success", + CreatedAt = DateTime.UtcNow + }); + continue; + } + switch (type) + { + case "D1": + var d1Importer = new MorskaD1Importer(_db, _googleSheetValues); + d1Importer.Import(importWorker); + Thread.Sleep(5000); // be aware of GSheet API quota + + _logsController.AddEntry(new LogEntry + { + Title = $"{importWorker.Name}, {importWorker.Id}", + Type = LogEntryType.Info, + LogType = LogType.Import, + Message = "Success", + CreatedAt = DateTime.UtcNow + }); + break; + case "FK2": + { + var fk2Importer = new MorskaFk2Importer(_db, _googleSheetValues); + fk2Importer.Import(importWorker); + Thread.Sleep(5000); // be aware of GSheet API quota + + _logsController.AddEntry(new LogEntry + { + Title = $"{importWorker.Name}, {importWorker.Id}", + Type = LogEntryType.Info, + LogType = LogType.Import, + Message = "Success", + CreatedAt = DateTime.UtcNow + }); + break; + } + default: + { + var startDate = importWorker.Records!.FirstOrDefault(x => x.Code == "StartDate")?.Desc1; + if (startDate == null) + { + throw new Exception("StartDate record nod found"); + } + + var endDate = importWorker.Records!.First(x => x.Code == "EndDate").Desc1; + if (endDate == null) + { + throw new Exception("EndDate record nod found"); + } + + 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) + { + var importer = new MorskaImporter(_db, _googleSheetValues); + importer.Import(importWorker); + Thread.Sleep(5000); // be aware of GSheet API quota + + _logsController.AddEntry(new LogEntry + { + Title = $"{importWorker.Name}, {importWorker.Id}", + Type = LogEntryType.Info, + LogType = LogType.Import, + Message = "Success", + CreatedAt = DateTime.UtcNow + }); + } + else if (IsImportedLayerUpToDate(importWorker) == false) + { + var importer = new MorskaImporter(_db, _googleSheetValues); + importer.Import(importWorker); + Thread.Sleep(5000); // be aware of GSheet API quota + + _logsController.AddEntry(new LogEntry + { + Title = $"{importWorker.Name}, {importWorker.Id}", + Type = LogEntryType.Warning, + LogType = LogType.Import, + Message = "Success (reimported)", + CreatedAt = DateTime.UtcNow + }); + } + else + { + _logsController.AddEntry(new LogEntry + { + Title = $"{importWorker.Name}, {importWorker.Id}", + Type = LogEntryType.Warning, + LogType = LogType.Import, + Message = "importLayer records are up to date. Not processed.", + CreatedAt = DateTime.UtcNow + }); + } + + break; + } + } + } + catch (Exception e) + { + _logsController.AddEntry(new LogEntry + { + Title = $"{importWorker.Name}, {importWorker.Id}", + Type = LogEntryType.Error, + LogType = LogType.Import, + Message = e.ToString(), + CreatedAt = DateTime.UtcNow + }); + } + } + + return Ok(); + } + catch (Exception e) + { + _logsController.AddEntry(new LogEntry + { + Title = "Process error", + Type = LogEntryType.Error, + LogType = LogType.Import, + Message = e.ToString(), + CreatedAt = DateTime.UtcNow + }); + return BadRequest(e.ToString()); + } + } + + [HttpGet] + [Route("AutoProcess/{apiKey}")] + [AllowAnonymous] + public IActionResult AutoProcess(string apiKey) + { + if (Request.Host.Value != _configuration["apiLocalUrl"] || apiKey != _configuration["apiKey"]) + { + return Unauthorized(); + } + + if (_googleSheetValues is null) + { + throw new Exception("Google Sheets API not initialized"); + } + + string[] processTypes = + [ + "T3-SingleSource", + "T3-SourceYearSummary", + "T3-MultiSourceSummary", // AA + "T3-MultiSourceYearSummary", // AA/13 + "T4-SingleSource", + "T5-LastValues", + "T1-R1", + "T4-R2", + "T1-R3" + ]; + + foreach (var type in processTypes) + { + try + { + var processWorkerLayers = _db.Layers + .Include(x => x.Records) + .Where(x => + x.Records!.Any(y => y.Code == "Type" && y.Desc1 == "ProcessWorker") && + x.Records!.Any(y => y.Code == "IsEnabled" && y.Desc1 == "True") && + x.Records!.Any(y => y.Code == "ProcessType" && y.Desc1 == type) + ) + .OrderBy(x => x.CreatedAt) + .AsNoTracking() + .ToList(); + + foreach (var processWorker in processWorkerLayers) + { + try + { + ProcessLayer(processWorker); + } + catch (Exception e) + { + _logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Error, + LogType = LogType.Process, + Message = e.ToString(), + CreatedAt = DateTime.UtcNow + }); + } + } + } + catch (Exception e) + { + _logsController.AddEntry(new LogEntry + { + Title = "Process error", + Type = LogEntryType.Error, + LogType = LogType.Process, + Message = e.ToString(), + CreatedAt = DateTime.UtcNow + }); + } + } + + return Ok(); + } + + private void ProcessLayer(Layer processWorker) + { + if (_googleSheetValues == null) + { + throw new Exception("Google Sheets API not initialized"); + } + + var year = processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1; + if (year == null) + { + throw new Exception("Year record nod found"); + } + + var processType = processWorker.Records?.SingleOrDefault(x => x.Code == "ProcessType")?.Desc1; + switch (processType) + { + case null: + throw new Exception("ProcessType record not found"); + case "T3-SourceYearSummary": + { + var processor = + new T3SourceYearSummaryProcessor(_db); + processor.Process(processWorker); + + _logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Info, + LogType = LogType.Process, + Message = "Success", + CreatedAt = DateTime.UtcNow + }); + return; + } + case "T3-MultiSourceYearSummary": + { + var processor = + new T3MultiSourceYearSummaryProcessor(_db); + processor.Process(processWorker); + + _logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Info, + LogType = LogType.Process, + Message = "Success", + CreatedAt = DateTime.UtcNow + }); + return; + } + case "T3-MultiSourceCopySelectedCodesYearSummary": + { + var processor = + new T3MultiSourceCopySelectedCodesYearSummaryProcessor(_db); + processor.Process(processWorker); + + _logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Info, + LogType = LogType.Process, + Message = "Success", + CreatedAt = DateTime.UtcNow + }); + return; + } + case "T1-R1": + { + var processor = new T1R1Processor(_db, _googleSheetValues); + processor.Process(processWorker); + + _logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Info, + LogType = LogType.Process, + Message = "Success", + CreatedAt = DateTime.UtcNow + }); + return; + } + case "T4-R2": + { + var processor = new T4R2Processor(_db, _googleSheetValues); + processor.Process(processWorker); + + _logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Info, + LogType = LogType.Process, + Message = "Success", + CreatedAt = DateTime.UtcNow + }); + return; + } + case "T1-R3": + { + var processor = new T1R3Processor(_db, _googleSheetValues); + processor.Process(processWorker); + + _logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Info, + LogType = LogType.Process, + Message = "Success", + CreatedAt = DateTime.UtcNow + }); + return; + } + } + + var month = processWorker.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1; + if (month == null) + { + throw new Exception("Month record not found"); + } + + switch (processType!) + { + case "T3-SingleSource": + { + var t3SingleSource = new T3SingleSourceProcessor(_db); + t3SingleSource.Process(processWorker); + break; + } + case "T4-SingleSource": + { + var t4SingleSource = new T4SingleSourceProcessor(_db); + t4SingleSource.Process(processWorker); + break; + } + case "T5-LastValues": + { + var t5LastValues = new T5LastValuesProcessor(_db); + t5LastValues.Process(processWorker); + break; + } + case "T3-MultiSourceSummary": + { + var t3MultiSourceSummary = + new T3MultiSourceSummaryProcessor(_db); + t3MultiSourceSummary.Process(processWorker); + break; + } + case "T3-MultiSourceCopySelectedCodes": + { + var t3MultiSourceCopySelectedCode = + new T3MultiSourceCopySelectedCodesProcessor(_db); + t3MultiSourceCopySelectedCode.Process(processWorker); + break; + } + } + + _logsController.AddEntry(new LogEntry + { + Title = $"{processWorker.Name}, {processWorker.Id}", + Type = LogEntryType.Info, + LogType = LogType.Process, + Message = "Success", + CreatedAt = DateTime.UtcNow + }); + } + + internal void SaveRecords(Guid id, ICollection records, Guid currentUserId) + { + var toDelete = _db.Records.Where(x => x.LayerId == id).ToList(); + if (toDelete.Count > 0) + { + _db.Records.RemoveRange(toDelete); + } + + foreach (var record in records) + { + record.CreatedById = currentUserId; + record.CreatedAt = DateTime.UtcNow; + record.ModifiedById = currentUserId; + record.ModifiedAt = DateTime.UtcNow; + record.LayerId = id; + _db.Records.Add(record); + } + } + + private static void WriteToConsole(params string[] messages) + { + foreach (var message in messages) + { + Console.WriteLine($"DiunaLog: {message}"); + } + } + + private bool IsImportedLayerUpToDate(Layer importWorker) + { + if (_googleSheetValues is null) + { + throw new Exception("Google Sheets API not initialized"); + } + + var newestLayer = _db.Layers + .Include(x => x.Records) + .Where(x => x.ParentId == importWorker.Id) + .OrderByDescending(x => x.CreatedAt) + .AsNoTracking() + .FirstOrDefault(); + + if (newestLayer is null) + { + return true; // importWorker is not active yet, no check needed + } + + var sheetId = importWorker.Records!.FirstOrDefault(x => x.Code == "SheetId")?.Desc1; + if (sheetId == null) + { + throw new Exception($"SheetId not found, {importWorker.Name}"); + } + + var sheetTabName = importWorker.Records!.FirstOrDefault(x => x.Code == "SheetTabName")?.Desc1; + if (sheetTabName == null) + { + throw new Exception($"SheetTabName not found, {importWorker.Name}"); + } + + var dataRange = importWorker.Records!.FirstOrDefault(x => x.Code == "DataRange")?.Desc1; + if (dataRange == null) + { + throw new Exception($"DataRange not found, {importWorker.Name}"); + } + + var dataRangeResponse = _googleSheetValues.Get(sheetId, $"{sheetTabName}!{dataRange}").Execute(); + var data = dataRangeResponse.Values; + + var isUpToDate = true; + + for (var i = 0; i < data[1].Count; i++) + { + if (data[0][i].ToString() == "") continue; + var record = newestLayer.Records!.FirstOrDefault(x => x.Code == data[0][i].ToString()); + if (record == null) + { + WriteToConsole("Code not found in DiunaBI", data[0][i].ToString()!); + isUpToDate = false; + continue; + } + + if (!double.TryParse(data[1][i].ToString(), CultureInfo.GetCultureInfo("pl-PL"), + out var value) || + double.Abs((double)(record.Value1 - value)!) < 0.01) continue; + isUpToDate = false; + } + + foreach (var record in newestLayer.Records!) + { + if (data[0].Contains(record.Code)) + { + continue; + } + + WriteToConsole($"Code not found in GoogleSheet: {record.Code}"); + isUpToDate = false; + } + + return isUpToDate; + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.WebAPI/Controllers/LogsController.cs b/src/Backend/DiunaBI.WebAPI/Controllers/LogsController.cs new file mode 100644 index 0000000..d98eae9 --- /dev/null +++ b/src/Backend/DiunaBI.WebAPI/Controllers/LogsController.cs @@ -0,0 +1,46 @@ +using Microsoft.AspNetCore.Mvc; +using DiunaBI.Core.Models; +using Google.Cloud.Firestore; + +namespace DiunaBI.WebAPI.Controllers; + +public class LogsController : Controller +{ + + private readonly FirestoreDb _firestoreDb; + private readonly Guid _SessionId = Guid.NewGuid(); + public LogsController( + FirestoreDb firestoreDb + ) + { + _firestoreDb = firestoreDb; + } + + public void AddEntry(LogEntry entry) + { + entry.SessionId = _SessionId; + entry.Instance = LogInstance.Morska; + + if (entry.Type == LogEntryType.Info) { return; } + + try + { + var collection = _firestoreDb.Collection("ApiLogs"); + var document = collection.Document(); + document.SetAsync(new + { + entry.Message, + entry.Title, + Type = Enum.GetName(typeof(LogEntryType), entry.Type), + LogType = Enum.GetName(typeof(LogType), entry.LogType), + Instance = Enum.GetName(typeof(LogInstance), entry.Instance), + entry.CreatedAt, + SessionId = entry.SessionId.ToString() + }).Wait(); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.WebAPI/Controllers/PingController.cs b/src/Backend/DiunaBI.WebAPI/Controllers/PingController.cs new file mode 100644 index 0000000..04193e3 --- /dev/null +++ b/src/Backend/DiunaBI.WebAPI/Controllers/PingController.cs @@ -0,0 +1,25 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace DiunaBI.WebAPI.Controllers; + +[ApiController] +[Route("api/[controller]")] +[Authorize] +public class PingController : Controller +{ + private readonly IConfiguration _configuration; + public PingController( + IConfiguration configuration) + { + _configuration = configuration; + } + + [HttpGet] + [Route("Ping")] + [AllowAnonymous] + public IActionResult Ping() + { + return Ok(_configuration["PONG"]); + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.WebAPI/Program.cs b/src/Backend/DiunaBI.WebAPI/Program.cs new file mode 100644 index 0000000..9583526 --- /dev/null +++ b/src/Backend/DiunaBI.WebAPI/Program.cs @@ -0,0 +1,100 @@ +using FirebaseAdmin; +using Google.Apis.Auth.OAuth2; +using Google.Cloud.Firestore; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.EntityFrameworkCore; +using Microsoft.IdentityModel.Tokens; +using System.IdentityModel.Tokens.Jwt; +using System.Text; +using DiunaBI.Core.Models; +using DiunaBI.Database.Context; +using DiunaBI.Core.Services; + +var builder = WebApplication.CreateBuilder(args); + +var connectionString = builder.Configuration.GetConnectionString("SQLDatabase"); +builder.Services.AddDbContext(x => +{ + x.UseSqlServer(connectionString); + x.EnableSensitiveDataLogging(); +}); + +builder.Services.AddCors(options => +{ + options.AddPolicy("CORSPolicy", corsPolicyBuilder => + { + corsPolicyBuilder.WithOrigins("http://localhost:4200") + .AllowAnyMethod() + .AllowAnyHeader() + .AllowCredentials(); + + corsPolicyBuilder.WithOrigins("https://diuna.bim-it.pl") + .AllowAnyMethod() + .AllowAnyHeader() + .AllowCredentials(); + }); +}); + +builder.Services.AddControllers(); + + +builder.Services.AddAuthentication(options => +{ + options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; + options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; + options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; +}).AddJwtBearer(options => +{ + options.TokenValidationParameters = new TokenValidationParameters + { + ValidateIssuer = false, + ValidateAudience = false, + ValidateLifetime = true, + ValidateIssuerSigningKey = true, + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Secret"]!)) + }; + +}); +builder.Services.AddAuthentication(); + +builder.Services.AddSingleton(typeof(GoogleSheetsHelper)); +builder.Services.AddSingleton(typeof(GoogleDriveHelper)); + +var fileName = "diunabi-admin-firebase.json"; +#if DEBUG +fileName = "diunabi-admin-firebase-Development.json"; +#endif +var credentialPath = Path.Combine(Directory.GetCurrentDirectory(), fileName); +System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", credentialPath); +FirebaseAdmin.FirebaseApp.Create(new AppOptions() +{ + Credential = GoogleCredential.GetApplicationDefault() +}); +builder.Services.AddSingleton(FirestoreDb.Create("diunabi-admin")); + +var app = builder.Build(); + + +app.Use(async (context, next) => +{ + var token = context.Request.Headers.Authorization.ToString(); + if (token.Length > 0 + && !context.Request.Path.ToString().Contains("getForPowerBI") + && !context.Request.Path.ToString().Contains("getConfiguration") + && !context.Request.Path.ToString().Contains("DataInbox/Add")) + { + var handler = new JwtSecurityTokenHandler(); + var data = handler.ReadJwtToken(token.Split(' ')[1]); + context.Request.Headers.Append("UserId", new Microsoft.Extensions.Primitives.StringValues(data.Subject)); + } + await next(context); +}); + +app.UseCors("CORSPolicy"); + +app.UseAuthentication(); +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/src/Backend/DiunaBI.WebAPI/Properties/launchSettings.json b/src/Backend/DiunaBI.WebAPI/Properties/launchSettings.json new file mode 100644 index 0000000..c37a5a2 --- /dev/null +++ b/src/Backend/DiunaBI.WebAPI/Properties/launchSettings.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "http://localhost:5163", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "https://localhost:7148;http://localhost:5163", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/src/Backend/DiunaBI.WebAPI/client_secrets.Development.json b/src/Backend/DiunaBI.WebAPI/client_secrets.Development.json new file mode 100644 index 0000000..0b9dadb --- /dev/null +++ b/src/Backend/DiunaBI.WebAPI/client_secrets.Development.json @@ -0,0 +1,12 @@ +{ + "type": "service_account", + "project_id": "diuna-370117", + "private_key_id": "f48fd588724e6733b9639fe7d7933091b96be34f", + "private_key": "-----BEGIN PRIVATE KEY-----MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCenqveXpGKXA10psAQ4Wreeiom9GMbZywnqMAhxc0wobI7EfnbP4FPOjfS8oWFRRrVzRil78zeUGWXb1WMHYvUyU3IrGXp6kVxuxbjBvwooOB5cEgz928A3aUUZRXxwjPV3+KuuAeQydVwPMQo2a0AQ+YAOK2QMG+BGAPAzYB+/35Zf6JsDOIDgWMaJq3etKgIijk40Nmf+uaGRAQlEbMhnAaAYz2B6I7W3z0pFDq2btgYJII+DWRC2DjSrA4UUeuds8Kz5qwfafJ8ki9N1RdYdbB/q6T74xQ3G/aEOK+CYmkWQz2woY5y8b5RCbKoGGIXpu6FVuWTnVxYJpP5QvIFAgMBAAECggEAJC3Evb+MKqa8WvL9s9v2aDAtFR2AzWtG4vTWfd2D46e940NCXgOqFswMl4zBb5hHeqSBDrgXXk2wHk5CkObcUfhoSXEo/aV1mW821SluskWfbZNypIe3RddII9K6op3M/OdH6NoIv7mJeUQi6b5ce0cBWuOSkuS5ShSUJpG40T5RQfl0iMuEYDpU1tvKmwhFlPTUTUGH7RdeqGFYIfE3kzFQiiSrS8V5L1GJKWcxMLdTq4P9JzaSW7eAAYKJiFTMSQvqs7pssCIj1JNLzD9PTsQmid2V2mUJIg3joXMNGbxNqMcIqbEesidIsDOkQ06taUIYG39og6rc9bar6XWRgQKBgQDK/+a8jCmUByhedUT5ZnREtHm4HcVo1tfBcmmqSEV0VJPJd14+CYvaUzCCJ9+xiLo6yOWRUk2h1GANAp50AdiVAHNibfwtri7vKWNhpnd111N/ebh6GIksT0ZTvu7sq5qbYXU3q6l6YRCyXSdF1oRfQED8I8G1xZP5j6fspBgoKQKBgQDICIKo3gmUEeFSt+o+Lucd2BljaFq/hUMA6WFdKbRyyd2iKBmGR15VNihiuJWy5i2nmuFaXMkeHo/PUJeEYC+vkc7M7UCYtD9l2xwp78o3ss7vxdPvOKhrcvux/Wpk1nuAEpM459MC0bmtOGIKU+QmDbsBbMHZ6p0R8DvECJ9mfQKBgEj60PAOD9CY9ilnTYHAFKKyo2POyC7VtkFkqZo/W0DkOzFdybLR6cZ2y+SvAxunRRRnLykchq5cVJ+4xlB8bWm7/L9xPQ0LJvJyVblAiIgD/o/AqdKzSXV1lpn69Zh+ZRnhYqu9+jL1/HOzS7Au2+4GgpZjIHwB6R36SGup3slpAoGAZW2jSxsjQjh6x2XIWfWQbVqZLQXKFhjta7XrD8FI5XekcUfiAWuI0q5edghgp9D9T2JCaH5p4GLgyt9zpMTdCSpm8RRQT93905jxw/X51JpPQddO6psRE0K/i3YTD8SN5NgGXLF4FpLfkozncZMuOXl23HcYKHZFZMYql/FDWkUCgYAjGQKzYV7IXA7UDAY3ejawWMbsDttSPQ0E1ouuJWIX/eb4SXYr0u/gdLuX1uM7EsxqIGVFWfgtUGopoVGr604Sg+dfOPZgUzaGAlUE2iRMVp6YoRRbrvPsYJwDrV0Xwil1k6UEzn8bgXO/IQ4fgIWjkxS5sDkZ6LVSCfDn5tLThg==-----END PRIVATE KEY-----", + "client_email": "diuna-backend@diuna-370117.iam.gserviceaccount.com", + "client_id": "101546901561736131820", + "auth_uri": "https://accounts.google.com/o/oauth2/auth", + "token_uri": "https://oauth2.googleapis.com/token", + "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", + "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/diuna-backend%40diuna-370117.iam.gserviceaccount.com" +} diff --git a/src/Backend/DiunaBI.WebAPI/client_secrets.json b/src/Backend/DiunaBI.WebAPI/client_secrets.json new file mode 100644 index 0000000..f4f3207 --- /dev/null +++ b/src/Backend/DiunaBI.WebAPI/client_secrets.json @@ -0,0 +1,12 @@ +{ + "type": "service_account", + "project_id": "#{google-backend-project-id}#", + "private_key_id": "#{google-backend-private-key-id}#", + "private_key": "#{google-backend-private-key}#", + "client_email": "#{google-backend-client-email}#", + "client_id": "#{google-backend-client-id}#", + "auth_uri": "https://accounts.google.com/o/oauth2/auth", + "token_uri": "https://oauth2.googleapis.com/token", + "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", + "client_x509_cert_url": "#{google-backend-client-cert-url}#" +} diff --git a/src/Backend/DiunaBI.WebAPI/diunabi-admin-firebase.json b/src/Backend/DiunaBI.WebAPI/diunabi-admin-firebase.json new file mode 100644 index 0000000..a27955f --- /dev/null +++ b/src/Backend/DiunaBI.WebAPI/diunabi-admin-firebase.json @@ -0,0 +1,13 @@ +{ + "type": "service_account", + "project_id": "#{firebase-project-id}#", + "private_key_id": "#{firebase-private-key-id}#", + "private_key": "#{firebase-private-key}#", + "client_email": "#{firebase-client-email}#", + "client_id": "#{firebase-client-id}#", + "auth_uri": "https://accounts.google.com/o/oauth2/auth", + "token_uri": "https://oauth2.googleapis.com/token", + "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", + "client_x509_cert_url": "#{firebase-client-cert-url}#", + "universe_domain": "googleapis.com" +}