Moved all of the file paths to appsettings file.
This commit is contained in:
@ -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"
|
||||
}
|
Reference in New Issue
Block a user