| | | 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.FavoritPartsApi; |
| | | 7 | | |
| | | 8 | | namespace OzonOrdersWeb.Areas.Studio2.Controllers.Directories; |
| | | 9 | | |
| | | 10 | | [Authorize(Roles = "User,Admin")] |
| | | 11 | | [Area("Studio2")] |
| | | 12 | | [Route("FavoritPartsRostov/[action]")] |
| | | 13 | | public sealed class FavoritPartsRostovController : Controller |
| | | 14 | | { |
| | | 15 | | private const string TestArticle = "01089"; |
| | | 16 | | private readonly FavoritPartsRostovDataManager _favoritParts; |
| | | 17 | | private readonly ApiSupplierRequestLogStore _logs; |
| | 0 | 18 | | public FavoritPartsRostovController(FavoritPartsRostovDataManager favoritParts, ApiSupplierRequestLogStore logs) => |
| | 0 | 19 | | [HttpGet, Route("~/FavoritPartsRostov")] public IActionResult Index() => View(); |
| | 0 | 20 | | [HttpGet] public IActionResult Logs() => Json(_logs.Get("FavoritPartsRostov")); |
| | 0 | 21 | | [HttpGet] public async Task<IActionResult> Ping(CancellationToken cancellationToken) { try { return JsonToken(await |
| | | 22 | | [HttpGet] public async Task<IActionResult> Read(string operation, CancellationToken cancellationToken) |
| | | 23 | | { |
| | | 24 | | try |
| | | 25 | | { |
| | 0 | 26 | | var result = operation.ToLowerInvariant() switch |
| | 0 | 27 | | { |
| | 0 | 28 | | "profile" => await _favoritParts.GetProfileAsync(cancellationToken), "status" => await _favoritParts.Get |
| | 0 | 29 | | "price-search" => await _favoritParts.SearchGoodsAsync(TestArticle, null, false, cancellationToken), "ca |
| | 0 | 30 | | }; |
| | 0 | 31 | | return result is null ? BadRequest(new { error = true, message = "Недопустимая read-операция." }) : JsonToke |
| | | 32 | | } |
| | 0 | 33 | | catch (Exception ex) { return Error(ex); } |
| | 0 | 34 | | } |
| | 0 | 35 | | private static IActionResult Error(Exception ex) => ex switch { FavoritPartsApiException api => new ObjectResult(new |
| | 0 | 36 | | private static ContentResult JsonToken(JToken token) => new() { Content = token.ToString(Formatting.None), ContentTy |
| | | 37 | | } |