< Summary

Information
Class: OzonOrdersWeb.Areas.Studio2.Controllers.JapartsPriceController
Assembly: OzonOrdersWeb
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Areas/Studio2/Controllers/JapartsPriceController.cs
Line coverage
96%
Covered lines: 30
Uncovered lines: 1
Coverable lines: 31
Total lines: 59
Line coverage: 96.7%
Branch coverage
53%
Covered branches: 15
Total branches: 28
Branch coverage: 53.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Search()50%6688.88%

File(s)

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

#LineLine coverage
 1using System.Globalization;
 2using Microsoft.AspNetCore.Authorization;
 3using Microsoft.AspNetCore.Mvc;
 4using OzonDomains;
 5using OzonOrdersWeb.Filters;
 6using Services.ApiServices.JapartsApi;
 7using Services.ApiServices.TradesoftApi.Models.Response;
 8using Services.ApiSupplierSettingsServices;
 9
 10namespace OzonOrdersWeb.Areas.Studio2.Controllers;
 11
 12[Area("Studio2")]
 13[Authorize(Roles = "User,Admin")]
 14[ServiceFilter(typeof(SupplierQuotationHistoryFilter), Order = 0)]
 15[ServiceFilter(typeof(SupplierDeliverySurchargeFilter), Order = 1)]
 16[ServiceFilter(typeof(SupplierWarehouseRestrictionFilter), Order = 2)]
 317public sealed class JapartsPriceController(JapartsDataManager japarts, ApiSupplierSettingsService settings) : Controller
 18{
 19    [HttpGet]
 20    public async Task<IActionResult> Search(string code, string? brand, int? orderId = null)
 21    {
 322        if (string.IsNullOrWhiteSpace(code)) return BadRequest(new { error = "Не указан артикул Japarts." });
 23        try
 24        {
 325            var config = await settings.GetAsync("Japarts", CurrencyCode.RUB, HttpContext.RequestAborted);
 326            if (!config.IsQuotationEnabled) return Ok(Array.Empty<PreOrderItem>());
 327            var offers = await japarts.SearchAsync(code.Trim(), brand?.Trim(), HttpContext.RequestAborted);
 228            return Ok(offers.Select(x => new PreOrderItem
 229            {
 230                Caption = x.DetailName, Producer = x.MakeName, Code = x.DetailNum,
 231                Rest = x.Quantity?.ToString(CultureInfo.InvariantCulture) ?? "", MinQuantity = (int)x.Lot,
 232                DeliveryDays = x.DeliveryDays?.ToString(CultureInfo.InvariantCulture) ?? "—",
 233                DeliveryDaysMin = x.DeliveryDays ?? 0, DeliveryDaysMax = x.GuaranteedDeliveryDays ?? x.DeliveryDays ?? 0
 234                Price = x.PriceRub.ToString("0.##", CultureInfo.InvariantCulture), CostPrice = x.PriceRub.ToString("0.##
 235                CostPriceFormatted = x.PriceRub.ToString("0.##", CultureInfo.InvariantCulture), CurrencyCode = "RUB", So
 236                Direction = string.Join(" ", new[] { x.Country, x.SupplierCode }.Where(value => !string.IsNullOrWhiteSpa
 237                Title = "Japarts", SiteUrl = "https://www.japarts.ru/", ItemId = x.PriceId, ItemHash = x.PriceId,
 238                Description = $"Поставщик: {x.SupplierCode}; кратность: {x.Lot}; статистика: {x.Statistic?.ToString() ??
 239                PriceDescription = $"Japarts: {x.PriceRub:0.##} RUB", PreferredSupplierId = config.SupplierId,
 240                PreferredSupplierCurrencyCode = config.Supplier?.CurrencyCode.ToString(),
 241                ProviderData = new Dictionary<string, string?>
 242                {
 243                    ["providerKey"] = "Japarts",
 244                    ["priceId"] = x.PriceId,
 245                    ["lot"] = x.Lot.ToString(CultureInfo.InvariantCulture),
 246                    ["deposit"] = x.Deposit ? "1" : "0"
 247                }
 248            }));
 49        }
 050        catch (JapartsApiException ex) { return Ok(new { items = Array.Empty<PreOrderItem>(), error = ex.Message }); }
 51        // Регрессия #2259, #2260, #2261, #2265, #2266, #2267: Japarts недоступен (connection refused,
 52        // таймаут HttpClient) — проценка по остальным поставщикам не должна получать 500.
 253        catch (Exception ex) when (ex is HttpRequestException or TimeoutException
 254                                   || (ex is TaskCanceledException && !HttpContext.RequestAborted.IsCancellationRequeste
 55        {
 256            return Ok(new { items = Array.Empty<PreOrderItem>(), error = "Сервис Japarts временно недоступен." });
 57        }
 358    }
 59}