| | | 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.ForumAutoApi; |
| | | 7 | | |
| | | 8 | | namespace OzonOrdersWeb.Areas.Studio2.Controllers.Directories; |
| | | 9 | | |
| | | 10 | | [Authorize(Roles = "User,Admin")] |
| | | 11 | | [Area("Studio2")] |
| | | 12 | | [Route("ForumAutoIstra/[action]")] |
| | | 13 | | public sealed class ForumAutoIstraController : Controller |
| | | 14 | | { |
| | | 15 | | private readonly ForumAutoIstraDataManager _forumAuto; |
| | | 16 | | private readonly ApiSupplierRequestLogStore _logs; |
| | 0 | 17 | | public ForumAutoIstraController(ForumAutoIstraDataManager forumAuto, ApiSupplierRequestLogStore logs) { _forumAuto = |
| | 0 | 18 | | [HttpGet, Route("~/ForumAutoIstra")] public IActionResult Index() => View(); |
| | 0 | 19 | | [HttpGet] public IActionResult Logs() => Json(_logs.Get("ForumAutoIstra")); |
| | 0 | 20 | | [HttpGet] public async Task<IActionResult> Ping(CancellationToken cancellationToken) { try { return JsonToken(await |
| | | 21 | | [HttpGet] public async Task<IActionResult> Read(string operation, CancellationToken cancellationToken) |
| | | 22 | | { |
| | | 23 | | try |
| | | 24 | | { |
| | 0 | 25 | | var result = operation.ToLowerInvariant() switch |
| | 0 | 26 | | { |
| | 0 | 27 | | "client-info" => await _forumAuto.GetClientInfoAsync(cancellationToken), |
| | 0 | 28 | | "list-brands" => await _forumAuto.GetBrandsAsync(cancellationToken), |
| | 0 | 29 | | "list-goods" => await _forumAuto.ListGoodsAsync("OC47", null, cross: false, ct: cancellationToken), |
| | 0 | 30 | | _ => null |
| | 0 | 31 | | }; |
| | 0 | 32 | | return result is null ? BadRequest(new { error = true, message = "Недопустимая read-операция." }) : JsonToke |
| | | 33 | | } |
| | 0 | 34 | | catch (Exception ex) { return Error(ex); } |
| | 0 | 35 | | } |
| | 0 | 36 | | private static IActionResult Error(Exception ex) => ex switch |
| | 0 | 37 | | { |
| | 0 | 38 | | ForumAutoApiException api => new ObjectResult(new { error = true, message = api.Message }) { StatusCode = api.St |
| | 0 | 39 | | _ => new ObjectResult(new { error = true, message = "Не удалось выполнить запрос к Forum-Auto." }) { StatusCode |
| | 0 | 40 | | }; |
| | 0 | 41 | | private static ContentResult JsonToken(JToken token) => new() { Content = token.ToString(Formatting.None), ContentTy |
| | | 42 | | } |