| | | 1 | | using Microsoft.AspNetCore.Authorization; |
| | | 2 | | using Microsoft.AspNetCore.Mvc; |
| | | 3 | | using Newtonsoft.Json; |
| | | 4 | | using Newtonsoft.Json.Linq; |
| | | 5 | | using Services.ApiServices.ApiSupplierRequestLog; |
| | | 6 | | using Services.ApiServices.MoskvorechieApi; |
| | | 7 | | |
| | | 8 | | namespace OzonOrdersWeb.Areas.Studio2.Controllers.Directories; |
| | | 9 | | |
| | | 10 | | [Area("Studio2")] |
| | | 11 | | [Authorize(Roles = "User,Admin")] |
| | | 12 | | [Route("MoskvorechieIstra/[action]")] |
| | | 13 | | public sealed class MoskvorechieIstraController : Controller |
| | | 14 | | { |
| | | 15 | | private readonly MoskvorechieIstraDataManager _api; |
| | | 16 | | private readonly ApiSupplierRequestLogStore _logs; |
| | 0 | 17 | | public MoskvorechieIstraController(MoskvorechieIstraDataManager api, ApiSupplierRequestLogStore logs) => (_api, _log |
| | 0 | 18 | | [HttpGet, Route("~/MoskvorechieIstra")] public IActionResult Index() => View(); |
| | 0 | 19 | | [HttpGet] public IActionResult Logs() => Json(_logs.Get(MoskvorechieIstraHttpClient.ProviderKey)); |
| | | 20 | | [HttpGet] public async Task<IActionResult> Read(string operation, CancellationToken cancellationToken) |
| | | 21 | | { |
| | | 22 | | try |
| | | 23 | | { |
| | 0 | 24 | | var result = operation.ToLowerInvariant() switch |
| | 0 | 25 | | { |
| | 0 | 26 | | "brands" => await _api.FindBrandsAsync("KL2", cancellationToken), |
| | 0 | 27 | | "prices" => await _api.SearchPricesAsync("KL2", "Knecht", cancellationToken), |
| | 0 | 28 | | "basket" => await _api.GetBasketAsync(cancellationToken), _ => null |
| | 0 | 29 | | }; |
| | 0 | 30 | | return result is null ? BadRequest(new { error = true, message = "Недопустимая read-операция." }) : new Cont |
| | | 31 | | } |
| | 0 | 32 | | catch (MoskvorechieApiException ex) { return BadRequest(new { error = true, message = ex.Message }); } |
| | 0 | 33 | | } |
| | | 34 | | } |