< Summary

Information
Class: OzonOrdersWeb.Areas.Studio2.Controllers.FavoritPartsRostovPriceController
Assembly: OzonOrdersWeb
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Areas/Studio2/Controllers/FavoritPartsRostovPriceController.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 22
Coverable lines: 22
Total lines: 59
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
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%
Search()0%156120%
ResolveDeliveryDestinationAsync()100%210%
<ResolveDeliveryDestinationAsync()100%210%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Areas/Studio2/Controllers/FavoritPartsRostovPriceController.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Authorization;
 2using Microsoft.AspNetCore.Mvc;
 3using Microsoft.Extensions.Caching.Memory;
 4using OzonOrdersWeb.Filters;
 5using Services.ApiServices.FavoritPartsApi;
 6using Services.ApiServices.TradesoftApi.Models.Response;
 7using Services.ApiSupplierSettingsServices;
 8
 9namespace OzonOrdersWeb.Areas.Studio2.Controllers;
 10
 11[Area("Studio2")]
 12[Authorize(Roles = "User,Admin")]
 13[ServiceFilter(typeof(SupplierQuotationHistoryFilter), Order = 0)]
 14[ServiceFilter(typeof(SupplierDeliverySurchargeFilter), Order = 1)]
 15[ServiceFilter(typeof(SupplierWarehouseRestrictionFilter), Order = 2)]
 16public sealed class FavoritPartsRostovPriceController : Controller
 17{
 18    private readonly FavoritPartsRostovDataManager _favoritParts;
 19    private readonly ApiSupplierSettingsService _settings;
 20    private readonly IMemoryCache _cache;
 21
 022    public FavoritPartsRostovPriceController(FavoritPartsRostovDataManager favoritParts, ApiSupplierSettingsService sett
 023        (_favoritParts, _settings, _cache) = (favoritParts, settings, cache);
 24
 25    [HttpGet]
 26    public async Task<IActionResult> Search(string code, string? brand, int? orderId = null, bool analogues = false)
 27    {
 028        if (string.IsNullOrWhiteSpace(code)) return Ok(Array.Empty<PreOrderItem>());
 29        try
 30        {
 031            var settings = await _settings.GetFavoritPartsRostovAsync(HttpContext.RequestAborted);
 032            if (!settings.IsQuotationEnabled) return Ok(Array.Empty<PreOrderItem>());
 033            var withAnalogues = analogues && !string.IsNullOrWhiteSpace(brand);
 034            var profileTask = ResolveDeliveryDestinationAsync(HttpContext.RequestAborted);
 035            var response = await _favoritParts.SearchGoodsAsync(code.Trim(), brand?.Trim(), withAnalogues, HttpContext.R
 036            var deliveryDestination = settings.DeliveryAddress ?? await profileTask;
 037            return Ok(FavoritPartsPriceMapper.Map(response, code.Trim(), settings.SupplierId, settings.Supplier?.Currenc
 038                includeAnalogues: withAnalogues, providerKey: "FavoritPartsRostov", supplierName: "Фаворит Ростов", deli
 39        }
 040        catch (FavoritPartsApiException ex) { return Ok(new { items = Array.Empty<PreOrderItem>(), error = ex.Message })
 041        catch (Exception ex) when (ex is HttpRequestException or TimeoutException or TaskCanceledException)
 42        {
 043            return Ok(new { items = Array.Empty<PreOrderItem>(), error = "Сервис Фаворит Ростов временно недоступен." })
 44        }
 045    }
 46
 47    private async Task<string?> ResolveDeliveryDestinationAsync(CancellationToken cancellationToken)
 48    {
 49        try
 50        {
 051            return await _cache.GetOrCreateAsync("api-supplier:favorit-parts-rostov:profile-delivery", async entry =>
 052            {
 053                entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30);
 054                return FavoritPartsProfile.ResolveDefaultDeliveryDestination(await _favoritParts.GetProfileAsync(cancell
 055            });
 56        }
 057        catch (FavoritPartsApiException) { return null; }
 058    }
 59}