diff --git a/ReportingServices.Shared/HelperClasses/DailyReportHelper.cs b/ReportingServices.Shared/HelperClasses/DailyReportHelper.cs index ccf7225..392fd40 100644 --- a/ReportingServices.Shared/HelperClasses/DailyReportHelper.cs +++ b/ReportingServices.Shared/HelperClasses/DailyReportHelper.cs @@ -6,18 +6,15 @@ namespace ReportingServices.Shared.HelperClasses; public static class DailyReportHelper { - private static readonly string _dailyRptFilePath = "wwwroot/Assets/DailyReportInfo.json"; - private static readonly string _SLLFilePath = "wwwroot/Assets/SLLTools.json"; - - public static DailyReport SetUpDailyReport(ILogger logger, string baseUrlScrapeDb) + public static DailyReport SetUpDailyReport(ILogger logger, Dictionary filePaths, string baseUrlScrapeDb) { DailyReport report = new(); DateTime currentDateTime = DateTime.Now; try { - List tools = JsonFileHandler.LoadJSONFile>(_SLLFilePath); - ManualReportEntries manualEntries = JsonFileHandler.LoadJSONFile(_dailyRptFilePath); + List tools = JsonFileHandler.LoadJSONFile>(filePaths["SLL"]); + ManualReportEntries manualEntries = JsonFileHandler.LoadJSONFile(filePaths["DailyReport"]); if (currentDateTime.DayOfWeek == DayOfWeek.Monday && tools[^1].Date == currentDateTime.Date.AddDays(-1)) report.SLLTools = new List(); @@ -26,12 +23,14 @@ public static class DailyReportHelper report.ManualReportEntries = manualEntries; + report.ToolStatesByOwner = JsonFileHandler.LoadJSONFile>>(filePaths["ToolStateOwners"]); + } catch (Exception ex) { logger.LogError(ex, "Failed to load JsonFiles."); - logger.LogInformation("SLL File Path: {path}", _SLLFilePath); - logger.LogInformation("Manual Report Entries File Path: {path}", _dailyRptFilePath); + logger.LogInformation("SLL File Path: {path}", filePaths["SLL"]); + logger.LogInformation("Manual Report Entries File Path: {path}", filePaths["DailyReport"]); } List cleanTools = new() @@ -169,8 +168,8 @@ public static class DailyReportHelper try { - JsonFileHandler.SaveJSONFile(entries, _dailyRptFilePath); - JsonFileHandler.SaveJSONFile(sll, _SLLFilePath); + JsonFileHandler.SaveJSONFile(entries, filePaths["DailyReport"]); + JsonFileHandler.SaveJSONFile(sll, filePaths["SLL"]); } catch (Exception ex) { diff --git a/ReportingServices.Shared/ViewModels/ProductionReport/SLLTool.cs b/ReportingServices.Shared/Models/ProductionReport/SLLTool.cs similarity index 65% rename from ReportingServices.Shared/ViewModels/ProductionReport/SLLTool.cs rename to ReportingServices.Shared/Models/ProductionReport/SLLTool.cs index 2f5afcd..fe1cb93 100644 --- a/ReportingServices.Shared/ViewModels/ProductionReport/SLLTool.cs +++ b/ReportingServices.Shared/Models/ProductionReport/SLLTool.cs @@ -1,4 +1,4 @@ -namespace ReportingServices.Shared.ViewModels.ProductionReport; +namespace ReportingServices.Shared.Models.ProductionReport; public class SLLTool { diff --git a/ReportingServices.Shared/ViewModels/ProductionReport/UnloadTempsByDay.cs b/ReportingServices.Shared/Models/ProductionReport/UnloadTempsByDay.cs similarity index 71% rename from ReportingServices.Shared/ViewModels/ProductionReport/UnloadTempsByDay.cs rename to ReportingServices.Shared/Models/ProductionReport/UnloadTempsByDay.cs index e415373..62f83c4 100644 --- a/ReportingServices.Shared/ViewModels/ProductionReport/UnloadTempsByDay.cs +++ b/ReportingServices.Shared/Models/ProductionReport/UnloadTempsByDay.cs @@ -1,4 +1,4 @@ -namespace ReportingServices.Shared.ViewModels.ProductionReport; +namespace ReportingServices.Shared.Models.ProductionReport; public class UnloadTempsByDay { diff --git a/ReportingServices.UI/Controllers/ProductionReportController.cs b/ReportingServices.UI/Controllers/ProductionReportController.cs index fc66e87..47227e4 100644 --- a/ReportingServices.UI/Controllers/ProductionReportController.cs +++ b/ReportingServices.UI/Controllers/ProductionReportController.cs @@ -9,16 +9,20 @@ namespace ReportingServices.UI.Controllers; public class ProductionReportController : Controller { private readonly ILogger _logger; - private readonly string _dailyRptFilePath; - private readonly string _toolStateOwnerFilePath; + private readonly Dictionary _filePaths; private readonly string _baseDBUrl; public ProductionReportController(ILogger logger, AppSettings appSettings) { _logger = logger; _baseDBUrl = appSettings.BaseAPIAddress; - _dailyRptFilePath = appSettings.DailyReportFilePath; - _toolStateOwnerFilePath = appSettings.ToolStateOwnerFilePath; + + _filePaths = new() + { + { "DailyReport", appSettings.DailyReportFilePath }, + { "ToolStateOwners", appSettings.ToolStateOwnerFilePath }, + { "SLL", appSettings.SLLFilePath }, + }; _logger.LogInformation("Base Database Address: {baseUrl}", _baseDBUrl); } @@ -29,10 +33,7 @@ public class ProductionReportController : Controller { try { - DailyReport dailyReport = DailyReportHelper.SetUpDailyReport(_logger, _baseDBUrl); - Dictionary> toolStateOwners = JsonFileHandler.LoadJSONFile>>(_toolStateOwnerFilePath); - - dailyReport.ToolStatesByOwner = toolStateOwners; + DailyReport dailyReport = DailyReportHelper.SetUpDailyReport(_logger, _filePaths, _baseDBUrl); return View(dailyReport); } @@ -45,7 +46,7 @@ public class ProductionReportController : Controller public IActionResult EditDailyReport() { - ManualReportEntries entries = JsonFileHandler.LoadJSONFile(_dailyRptFilePath); + ManualReportEntries entries = JsonFileHandler.LoadJSONFile(_filePaths["DailyReport"]); return View(entries); } @@ -53,7 +54,7 @@ public class ProductionReportController : Controller [HttpPost] public IActionResult EditDailyReport(ManualReportEntries rpt) { - JsonFileHandler.SaveJSONFile(rpt, _dailyRptFilePath); + JsonFileHandler.SaveJSONFile(rpt, _filePaths["DailyReport"]); return RedirectToAction("DailyReport"); } diff --git a/ReportingServices.UI/Models/AppSettings.cs b/ReportingServices.UI/Models/AppSettings.cs index 0a558b1..791b8d4 100644 --- a/ReportingServices.UI/Models/AppSettings.cs +++ b/ReportingServices.UI/Models/AppSettings.cs @@ -12,6 +12,7 @@ public record AppSettings(string BaseAPIAddress, bool IsStaging, string MonAResource, string MonASite, + string SLLFilePath, string ToolStateOwnerFilePath) { diff --git a/ReportingServices.UI/Models/Binder/AppSettings.cs b/ReportingServices.UI/Models/Binder/AppSettings.cs index 7e89de9..ceed528 100644 --- a/ReportingServices.UI/Models/Binder/AppSettings.cs +++ b/ReportingServices.UI/Models/Binder/AppSettings.cs @@ -18,6 +18,7 @@ public class AppSettings [Display(Name = "Is Staging"), Required] public bool? IsStaging { get; set; } [Display(Name = "MonA Resource"), Required] public string MonAResource { get; set; } [Display(Name = "MonA Site"), Required] public string MonASite { get; set; } + [Display(Name = "SLL File Path"), Required] public string SLLFilePath { get; set; } [Display(Name = "Tool State Owner File Path"), Required] public string ToolStateOwnerFilePath { get; set; } #nullable enable @@ -53,6 +54,8 @@ public class AppSettings throw new NullReferenceException(nameof(MonAResource)); if (appSettings.MonASite is null) throw new NullReferenceException(nameof(MonASite)); + if (appSettings.SLLFilePath is null) + throw new NullReferenceException(nameof(SLLFilePath)); if (appSettings.ToolStateOwnerFilePath is null) throw new NullReferenceException(nameof(ToolStateOwnerFilePath)); result = new( @@ -66,6 +69,7 @@ public class AppSettings appSettings.IsStaging.Value, appSettings.MonAResource, appSettings.MonASite, + appSettings.SLLFilePath, appSettings.ToolStateOwnerFilePath); return result; } diff --git a/ReportingServices.UI/appsettings.json b/ReportingServices.UI/appsettings.json index 88a8e04..7d9e9f6 100644 --- a/ReportingServices.UI/appsettings.json +++ b/ReportingServices.UI/appsettings.json @@ -55,5 +55,6 @@ "Application": "Sample" } }, + "SLLFilePath": "wwwroot/Assets/SLLTools.json", "ToolStateOwnerFilePath": "wwwroot/Assets/ToolStates.json" } \ No newline at end of file