< Summary

Information
Class: OzonOrdersWeb.Areas.Studio2.Controllers.Directories.FidSupplierLinkController
Assembly: OzonOrdersWeb
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Areas/Studio2/Controllers/Directories/FidSupplierLinkController.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 38
Coverable lines: 38
Total lines: 103
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 34
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
Index()100%210%
Rows()0%4260%
ActionRequiredCount()100%210%
Save()0%7280%
Unlink()0%2040%
SetAutoCart()0%7280%
SetRowAutoCart()0%7280%
BuildModelAsync()100%210%
NotifyAsync()100%210%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Areas/Studio2/Controllers/Directories/FidSupplierLinkController.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Authorization;
 2using Microsoft.AspNetCore.Mvc;
 3using OzonOrdersWeb.Areas.Studio2.Helpers;
 4using OzonOrdersWeb.Areas.Studio2.ViewModels.FidSupplierLink;
 5using OzonOrdersWeb.Authorization;
 6using Services.ApiServices.ApiSupplierIntegration;
 7using Services.FidSupplierLinkServices;
 8using Services.SignalRServices;
 9
 10namespace OzonOrdersWeb.Areas.Studio2.Controllers.Directories;
 11
 12[Area("Studio2")]
 13[Authorize(Roles = "User,Admin")]
 14public sealed class FidSupplierLinkController : Controller
 15{
 16    private readonly FidSupplierLinkService _links;
 17    private readonly ApiSupplierConnectorRegistry _providers;
 18
 019    public FidSupplierLinkController(FidSupplierLinkService links, ApiSupplierConnectorRegistry providers)
 020    { _links = links; _providers = providers; }
 21
 022    public async Task<IActionResult> Index(CancellationToken ct) => View(await BuildModelAsync(false, ct));
 23
 24    [HttpGet, ServiceEndpoint]
 25    public async Task<IActionResult> Rows(CancellationToken ct)
 26    {
 027        var refresh = await _links.RefreshAsync(ct);
 028        if (!refresh.IsInitialSnapshot && refresh.NewSupplierNames.Count > 0 &&
 029            await NotifyAsync("Из фида добавлены новые поставщики", "#D97706", string.Join(", ", refresh.NewSupplierName
 030            await _links.MarkNotifiedAsync(refresh.NewSupplierNames, ct);
 31
 032        return Json(FidSupplierLinkGridData.From(refresh.Overview, refresh.NewSupplierNames));
 033    }
 34
 35    [HttpGet, ServiceEndpoint]
 036    public async Task<IActionResult> ActionRequiredCount(CancellationToken ct) => Json(new { count = await _links.CountA
 37
 38    [HttpPost, Authorize(Roles = "Admin"), ValidateAntiForgeryToken, ServiceEndpoint]
 39    public async Task<IActionResult> Save(string fidSupplierName, string? providerKey, string? note, CancellationToken c
 40    {
 41        try
 42        {
 043            await _links.SaveAsync(new FidSupplierLinkInput(fidSupplierName, providerKey, note), User.Identity?.Name ?? 
 044            await NotifyAsync(providerKey is null ? "Связь с фидом удалена" : "Связь с фидом сохранена", providerKey is 
 045            return Json(new { success = true });
 46        }
 047        catch (Exception ex) { return Json(new { success = false, error = ex.Message }); }
 048    }
 49
 50    [HttpPost, Authorize(Roles = "Admin"), ValidateAntiForgeryToken, ServiceEndpoint]
 51    public async Task<IActionResult> Unlink(string fidSupplierName, CancellationToken ct)
 52    {
 53        try
 54        {
 055            await _links.UnlinkAsync(fidSupplierName, User.Identity?.Name ?? "unknown", ct);
 056            await NotifyAsync("Связь с фидом удалена", "#DC2626", fidSupplierName);
 057            return Json(new { success = true });
 58        }
 059        catch (Exception ex) { return Json(new { success = false, error = ex.Message }); }
 060    }
 61
 62    /// <summary>Главный рубильник автопроценки: выключает автоподстановку по всем связям сразу.</summary>
 63    [HttpPost, Authorize(Roles = "Admin"), ValidateAntiForgeryToken, ServiceEndpoint]
 64    public async Task<IActionResult> SetAutoCart(bool enabled, CancellationToken ct)
 65    {
 66        try
 67        {
 068            await _links.SetGlobalAutoCartAsync(enabled, User.Identity?.Name ?? "unknown", ct);
 069            await NotifyAsync(enabled ? "Автопроценка включена" : "Автопроценка выключена", enabled ? "#16A34A" : "#DC26
 070            return Json(new { success = true });
 71        }
 072        catch (Exception ex) { return Json(new { success = false, error = ex.Message }); }
 073    }
 74
 75    [HttpPost, Authorize(Roles = "Admin"), ValidateAntiForgeryToken, ServiceEndpoint]
 76    public async Task<IActionResult> SetRowAutoCart(string fidSupplierName, bool enabled, CancellationToken ct)
 77    {
 78        try
 79        {
 080            await _links.SetRowAutoCartAsync(fidSupplierName, enabled, User.Identity?.Name ?? "unknown", ct);
 081            await NotifyAsync(enabled ? "Автопроценка включена" : "Автопроценка выключена", enabled ? "#16A34A" : "#DC26
 082            return Json(new { success = true });
 83        }
 084        catch (Exception ex) { return Json(new { success = false, error = ex.Message }); }
 085    }
 86
 87    private async Task<FidSupplierLinkIndexViewModel> BuildModelAsync(bool forceRefresh, CancellationToken ct)
 88    {
 089        var providers = _providers.GetAll().OrderBy(x => x.DisplayName).Select(x => new FidProviderOption(
 090            x.ProviderKey, x.DisplayName, ApiProviderBrand.LogoUrl(x.ProviderKey), ApiProviderBrand.DirectionTag(x.Provi
 091        return new FidSupplierLinkIndexViewModel { Overview = await _links.GetOverviewAsync(forceRefresh, ct), Providers
 092    }
 93
 94    private static async Task<bool> NotifyAsync(string action, string color, string name)
 95    {
 96        try
 97        {
 098            await NotificationService.NotifyAsync("Связи фида", color, $"{action}: {name}", "fa-link");
 099            return true;
 100        }
 0101        catch { return false; /* SignalR не влияет на сохранение */ }
 0102    }
 103}