Moved all of the file paths to appsettings file.
This commit is contained in:
parent
7d2eb5ef0f
commit
afdd487b7d
@ -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<string, string> filePaths, string baseUrlScrapeDb)
|
||||
{
|
||||
DailyReport report = new();
|
||||
DateTime currentDateTime = DateTime.Now;
|
||||
|
||||
try
|
||||
{
|
||||
List<SLLTool> tools = JsonFileHandler.LoadJSONFile<List<SLLTool>>(_SLLFilePath);
|
||||
ManualReportEntries manualEntries = JsonFileHandler.LoadJSONFile<ManualReportEntries>(_dailyRptFilePath);
|
||||
List<SLLTool> tools = JsonFileHandler.LoadJSONFile<List<SLLTool>>(filePaths["SLL"]);
|
||||
ManualReportEntries manualEntries = JsonFileHandler.LoadJSONFile<ManualReportEntries>(filePaths["DailyReport"]);
|
||||
|
||||
if (currentDateTime.DayOfWeek == DayOfWeek.Monday && tools[^1].Date == currentDateTime.Date.AddDays(-1))
|
||||
report.SLLTools = new List<SLLTool>();
|
||||
@ -26,12 +23,14 @@ public static class DailyReportHelper
|
||||
|
||||
report.ManualReportEntries = manualEntries;
|
||||
|
||||
report.ToolStatesByOwner = JsonFileHandler.LoadJSONFile<Dictionary<string, List<string>>>(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<string> 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)
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace ReportingServices.Shared.ViewModels.ProductionReport;
|
||||
namespace ReportingServices.Shared.Models.ProductionReport;
|
||||
|
||||
public class SLLTool
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
namespace ReportingServices.Shared.ViewModels.ProductionReport;
|
||||
namespace ReportingServices.Shared.Models.ProductionReport;
|
||||
|
||||
public class UnloadTempsByDay
|
||||
{
|
@ -9,16 +9,20 @@ namespace ReportingServices.UI.Controllers;
|
||||
public class ProductionReportController : Controller
|
||||
{
|
||||
private readonly ILogger<ProductionReportController> _logger;
|
||||
private readonly string _dailyRptFilePath;
|
||||
private readonly string _toolStateOwnerFilePath;
|
||||
private readonly Dictionary<string, string> _filePaths;
|
||||
private readonly string _baseDBUrl;
|
||||
|
||||
public ProductionReportController(ILogger<ProductionReportController> 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<string, List<string>> toolStateOwners = JsonFileHandler.LoadJSONFile<Dictionary<string, List<string>>>(_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<ManualReportEntries>(_dailyRptFilePath);
|
||||
ManualReportEntries entries = JsonFileHandler.LoadJSONFile<ManualReportEntries>(_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");
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ public record AppSettings(string BaseAPIAddress,
|
||||
bool IsStaging,
|
||||
string MonAResource,
|
||||
string MonASite,
|
||||
string SLLFilePath,
|
||||
string ToolStateOwnerFilePath)
|
||||
{
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -55,5 +55,6 @@
|
||||
"Application": "Sample"
|
||||
}
|
||||
},
|
||||
"SLLFilePath": "wwwroot/Assets/SLLTools.json",
|
||||
"ToolStateOwnerFilePath": "wwwroot/Assets/ToolStates.json"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user