diff --git a/src/PowderCoating.Web/Controllers/PowderCatalogController.cs b/src/PowderCoating.Web/Controllers/PowderCatalogController.cs index d29e840..25329c3 100644 --- a/src/PowderCoating.Web/Controllers/PowderCatalogController.cs +++ b/src/PowderCoating.Web/Controllers/PowderCatalogController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using PowderCoating.Application.Constants; using PowderCoating.Application.DTOs.Common; using PowderCoating.Application.DTOs.Inventory; using PowderCoating.Application.Interfaces; @@ -19,15 +20,21 @@ public class PowderCatalogController : Controller private readonly IUnitOfWork _unitOfWork; private readonly IInventoryAiLookupService _aiLookupService; + private readonly IColumbiaCatalogSyncService _columbiaSyncService; + private readonly IPlatformSettingsService _platformSettings; private readonly ILogger _logger; public PowderCatalogController( IUnitOfWork unitOfWork, IInventoryAiLookupService aiLookupService, + IColumbiaCatalogSyncService columbiaSyncService, + IPlatformSettingsService platformSettings, ILogger logger) { _unitOfWork = unitOfWork; _aiLookupService = aiLookupService; + _columbiaSyncService = columbiaSyncService; + _platformSettings = platformSettings; _logger = logger; } @@ -135,6 +142,11 @@ public class PowderCatalogController : Controller } }; + // Columbia sync status for the admin panel (last run + master switch). + ViewBag.ColumbiaSyncEnabled = await _platformSettings.GetBoolAsync(ColumbiaIntegrationConstants.SettingEnabled); + ViewBag.ColumbiaLastSyncedAt = await _platformSettings.GetAsync(ColumbiaIntegrationConstants.SettingLastSyncedAt); + ViewBag.ColumbiaLastResult = await _platformSettings.GetAsync(ColumbiaIntegrationConstants.SettingLastResult); + return View(vm); } @@ -422,6 +434,24 @@ public class PowderCatalogController : Controller return Json(results); } + /// + /// Manually triggers a full Columbia Coatings catalog sync (SuperAdmin only). Bypasses the + /// scheduled interval. Reports the run outcome via TempData on the catalog index. + /// + [HttpPost] + [ValidateAntiForgeryToken] + public async Task SyncColumbia(CancellationToken cancellationToken) + { + var result = await _columbiaSyncService.RunSyncAsync(cancellationToken); + + if (result.Success) + TempData["Success"] = $"Columbia sync complete — {result.Summary}"; + else + TempData["Error"] = $"Columbia sync failed: {result.ErrorMessage}"; + + return RedirectToAction(nameof(Index)); + } + // Private helpers private async Task ApplyTdsCureFallbackAsync(InventoryAiLookupResult result, string? colorName) diff --git a/src/PowderCoating.Web/Views/PowderCatalog/Index.cshtml b/src/PowderCoating.Web/Views/PowderCatalog/Index.cshtml index 37f0115..4ceb16d 100644 --- a/src/PowderCoating.Web/Views/PowderCatalog/Index.cshtml +++ b/src/PowderCoating.Web/Views/PowderCatalog/Index.cshtml @@ -110,12 +110,42 @@
Platform-level lookup library for inventory autofill, SDS/TDS links, and curing specs.
+
+ @Html.AntiForgeryToken() + +
Add Powder
+ @{ + var columbiaLastSynced = ViewBag.ColumbiaLastSyncedAt as string; + var columbiaLastResult = ViewBag.ColumbiaLastResult as string; + var columbiaEnabled = ViewBag.ColumbiaSyncEnabled is true; + } +
+ + Scheduled sync @(columbiaEnabled ? "on" : "off") + + @if (!string.IsNullOrWhiteSpace(columbiaLastSynced) && DateTime.TryParse(columbiaLastSynced, out var lastSyncedAt)) + { + Last synced @lastSyncedAt.ToLocalTime().ToString("MMM d, yyyy h:mm tt") + } + else + { + Never synced + } + @if (!string.IsNullOrWhiteSpace(columbiaLastResult)) + { + — @columbiaLastResult + } +
+