| | | 1 | | using Microsoft.AspNetCore.Authorization; |
| | | 2 | | using Microsoft.AspNetCore.Mvc; |
| | | 3 | | using Services.ApiServices.ForumAutoApi; |
| | | 4 | | using Services.ApiServices.TradesoftApi.Models.Response; |
| | | 5 | | using Services.ApiSupplierSettingsServices; |
| | | 6 | | using OzonOrdersWeb.Filters; |
| | | 7 | | |
| | | 8 | | namespace OzonOrdersWeb.Areas.Studio2.Controllers; |
| | | 9 | | |
| | | 10 | | [Area("Studio2")] |
| | | 11 | | [Authorize(Roles = "User,Admin")] |
| | | 12 | | [ServiceFilter(typeof(SupplierQuotationHistoryFilter), Order = 0)] |
| | | 13 | | [ServiceFilter(typeof(SupplierDeliverySurchargeFilter), Order = 1)] |
| | | 14 | | [ServiceFilter(typeof(SupplierWarehouseRestrictionFilter), Order = 2)] |
| | | 15 | | public sealed class ForumAutoInterpartsPriceController : Controller |
| | | 16 | | { |
| | | 17 | | private readonly ForumAutoInterpartsDataManager _forumAuto; |
| | | 18 | | private readonly ApiSupplierSettingsService _settings; |
| | | 19 | | |
| | 0 | 20 | | public ForumAutoInterpartsPriceController(ForumAutoInterpartsDataManager forumAuto, ApiSupplierSettingsService setti |
| | | 21 | | { |
| | 0 | 22 | | _forumAuto = forumAuto; |
| | 0 | 23 | | _settings = settings; |
| | 0 | 24 | | } |
| | | 25 | | |
| | | 26 | | [HttpGet] |
| | | 27 | | public async Task<IActionResult> Search(string code, string? brand, int? orderId = null) |
| | | 28 | | { |
| | 0 | 29 | | if (string.IsNullOrWhiteSpace(code)) |
| | 0 | 30 | | return Ok(Array.Empty<PreOrderItem>()); |
| | | 31 | | |
| | | 32 | | try |
| | | 33 | | { |
| | 0 | 34 | | var settings = await _settings.GetForumAutoInterpartsAsync(HttpContext.RequestAborted); |
| | 0 | 35 | | if (!settings.IsQuotationEnabled) |
| | 0 | 36 | | return Ok(Array.Empty<PreOrderItem>()); |
| | | 37 | | |
| | 0 | 38 | | var response = await _forumAuto.ListGoodsAsync(code.Trim(), brand?.Trim(), cross: false, ct: HttpContext.Req |
| | 0 | 39 | | return Ok(SupplierQuotationDeliveryDestination.Apply( |
| | 0 | 40 | | ForumAutoPriceMapper.Map(response, code.Trim(), settings.SupplierId, settings.Supplier?.CurrencyCode, |
| | 0 | 41 | | "ForumAutoInterparts", settings.DisplayName ?? ApiSupplierSettingsService.GetDefaultDisplayName(sett |
| | | 42 | | } |
| | 0 | 43 | | catch (ForumAutoApiException ex) when (ex.FaultCode == 27) |
| | | 44 | | { |
| | | 45 | | // FaultCode 27 — "Товары не найдены": нормальный пустой результат, а не ошибка. |
| | 0 | 46 | | return Ok(Array.Empty<PreOrderItem>()); |
| | | 47 | | } |
| | 0 | 48 | | catch (ForumAutoApiException ex) |
| | | 49 | | { |
| | 0 | 50 | | return Ok(new { items = Array.Empty<PreOrderItem>(), error = ex.Message }); |
| | | 51 | | } |
| | 0 | 52 | | catch (Exception ex) when (ex is HttpRequestException or TimeoutException or TaskCanceledException) |
| | | 53 | | { |
| | 0 | 54 | | return Ok(new { items = Array.Empty<PreOrderItem>(), error = "Сервис Forum-Auto (Интерпартс) временно недост |
| | | 55 | | } |
| | 0 | 56 | | } |
| | | 57 | | } |