Moved all of the file paths to appsettings file.

This commit is contained in:
Daniel Wathen
2023-01-19 13:05:54 -07:00
parent 7d2eb5ef0f
commit afdd487b7d
7 changed files with 28 additions and 22 deletions

View File

@ -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");
}