using Microsoft.AspNetCore.Mvc; using ReportingServices.Shared.HelperClasses; using ReportingServices.Shared.Models.ProductionReport; using ReportingServices.Shared.ViewModels.ProductionReport; using ReportingServices.UI.Models; namespace ReportingServices.UI.Controllers; public class ProductionReportController : Controller { private readonly ILogger<ProductionReportController> _logger; private readonly string _dailyRptFilePath; private readonly string _toolStateOwnerFilePath; private readonly string _baseDBUrl; public ProductionReportController(ILogger<ProductionReportController> logger, AppSettings appSettings) { _logger = logger; _baseDBUrl = appSettings.BaseAPIAddress; _dailyRptFilePath = appSettings.DailyReportFilePath; _toolStateOwnerFilePath = appSettings.ToolStateOwnerFilePath; _logger.LogInformation("Base Database Address: {baseUrl}", _baseDBUrl); } public IActionResult Index() => View(); public IActionResult DailyReport() { try { DailyReport dailyReport = DailyReportHelper.SetUpDailyReport(_logger, _baseDBUrl); Dictionary<string, List<string>> toolStateOwners = JsonFileHandler.LoadJSONFile<Dictionary<string, List<string>>>(_toolStateOwnerFilePath); dailyReport.ToolStatesByOwner = toolStateOwners; return View(dailyReport); } catch (Exception ex) { _logger.LogCritical(ex, "Failed to load report"); return View(); } } public IActionResult EditDailyReport() { ManualReportEntries entries = JsonFileHandler.LoadJSONFile<ManualReportEntries>(_dailyRptFilePath); return View(entries); } [HttpPost] public IActionResult EditDailyReport(ManualReportEntries rpt) { JsonFileHandler.SaveJSONFile(rpt, _dailyRptFilePath); return RedirectToAction("DailyReport"); } public IActionResult HoldLotReport() { List<HoldLot> holdLots = ApiCaller.GetApi<List<HoldLot>>(_baseDBUrl + "GetCurrentHoldLots").Result; return View(holdLots); } }