| | | 1 | | using Microsoft.AspNetCore.Authorization; |
| | | 2 | | using Microsoft.AspNetCore.Mvc; |
| | | 3 | | using Services.ApiServices.ApiSupplierRequestLog; |
| | | 4 | | using Services.ApiServices.ArmtekApi; |
| | | 5 | | |
| | | 6 | | namespace OzonOrdersWeb.Areas.Studio2.Controllers.Directories; |
| | | 7 | | |
| | | 8 | | [Area("Studio2")] |
| | | 9 | | [Authorize(Roles = "User,Admin")] |
| | | 10 | | [Route("ArmtekBy/[action]")] |
| | | 11 | | public sealed class ArmtekByController : Controller |
| | | 12 | | { |
| | | 13 | | private readonly ArmtekByDataManager _armtek; |
| | | 14 | | private readonly ApiSupplierRequestLogStore _logs; |
| | | 15 | | |
| | 0 | 16 | | public ArmtekByController(ArmtekByDataManager armtek, ApiSupplierRequestLogStore logs) |
| | | 17 | | { |
| | 0 | 18 | | _armtek = armtek; |
| | 0 | 19 | | _logs = logs; |
| | 0 | 20 | | } |
| | | 21 | | |
| | | 22 | | [HttpGet, Route("~/ArmtekBy")] |
| | | 23 | | public IActionResult Index() |
| | | 24 | | { |
| | 0 | 25 | | ViewData["Title"] = "Армтек BY — API"; |
| | 0 | 26 | | ViewData["ConsoleTitle"] = "Армтек BY — API"; |
| | 0 | 27 | | ViewData["ConsoleSubtitle"] = "Консоль ручных read-only вызовов беларусского аккаунта: проценка, заказы, фактуры |
| | 0 | 28 | | ViewData["ConsoleNote"] = "Каждая карточка — реальный вызов к ws.armtek.ru под беларусскими учётными данными. VK |
| | 0 | 29 | | ViewData["ConsoleLogUrl"] = "/ArmtekBy/Logs"; |
| | 0 | 30 | | ViewData["ArmtekConsolePrefix"] = "/ArmtekBy"; |
| | 0 | 31 | | ViewData["ArmtekConsoleDefaultVkorg"] = "2000"; |
| | 0 | 32 | | return View("~/Areas/Studio2/Views/Armtek/Index.cshtml"); |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | [HttpGet] |
| | 0 | 36 | | public IActionResult Logs() => Json(_logs.Get("ArmtekBy")); |
| | | 37 | | |
| | | 38 | | [HttpGet] |
| | 0 | 39 | | public async Task<IActionResult> Ping() => await ExecuteAsync(() => _armtek.PingAsync()); |
| | | 40 | | |
| | | 41 | | [HttpGet] |
| | 0 | 42 | | public async Task<IActionResult> GetUserVkorgList() => await ExecuteAsync(() => _armtek.GetUserVkorgListAsync()); |
| | | 43 | | |
| | | 44 | | [HttpGet] |
| | | 45 | | public async Task<IActionResult> GetUserInfo(string? vkorg, string? structure) => |
| | 0 | 46 | | await ExecuteAsync(() => _armtek.GetUserInfoAsync(vkorg, structure != "false")); |
| | | 47 | | |
| | | 48 | | [HttpGet] |
| | 0 | 49 | | public async Task<IActionResult> GetBrandList() => await ExecuteAsync(() => _armtek.GetBrandListAsync()); |
| | | 50 | | |
| | | 51 | | [HttpGet] |
| | 0 | 52 | | public async Task<IActionResult> GetStoreList(string? vkorg) => await ExecuteAsync(() => _armtek.GetStoreListAsync(v |
| | | 53 | | |
| | | 54 | | [HttpGet] |
| | | 55 | | public async Task<IActionResult> Search(string kunnrRg, string pin, string? brand, string? vkorg, string? queryType) |
| | 0 | 56 | | await ExecuteAsync(() => _armtek.SearchAsync(kunnrRg, pin, brand, vkorg, |
| | 0 | 57 | | int.TryParse(queryType, out var parsed) ? parsed : null)); |
| | | 58 | | |
| | | 59 | | [HttpGet] |
| | | 60 | | public async Task<IActionResult> AssortmentSearch(string pin, string? vkorg, string? program) => |
| | 0 | 61 | | await ExecuteAsync(() => _armtek.AssortmentSearchAsync(pin, vkorg, program)); |
| | | 62 | | |
| | | 63 | | [HttpGet] |
| | | 64 | | public async Task<IActionResult> GetOrder(string kunrg, string order, string? vkorg, string? edit) => |
| | 0 | 65 | | await ExecuteAsync(() => _armtek.GetOrderAsync(kunrg, order, vkorg, edit == "true")); |
| | | 66 | | |
| | | 67 | | [HttpGet] |
| | | 68 | | public async Task<IActionResult> GetOrder2(string kunrg, string order, string? vkorg, string? detailedStatus) => |
| | 0 | 69 | | await ExecuteAsync(() => _armtek.GetOrder2Async(kunrg, order, vkorg, detailedStatus != "false")); |
| | | 70 | | |
| | | 71 | | [HttpGet] |
| | | 72 | | public async Task<IActionResult> GetRefund(string kunrg, string returnNumber, string? vkorg) => |
| | 0 | 73 | | await ExecuteAsync(() => _armtek.GetRefundAsync(kunrg, returnNumber, vkorg)); |
| | | 74 | | |
| | | 75 | | [HttpGet] |
| | | 76 | | public async Task<IActionResult> GetInvoice(string kunrg, string? invoice, string? zzsf, string? vkorg) => |
| | 0 | 77 | | await ExecuteAsync(() => _armtek.GetInvoiceAsync(kunrg, invoice, zzsf, vkorg)); |
| | | 78 | | |
| | | 79 | | [HttpGet] |
| | | 80 | | public async Task<IActionResult> GetOrderReportByDate(string kunnrRg, string? vkorg, DateTime? createdFrom, DateTime |
| | | 81 | | DateTime? deliveryFrom, DateTime? deliveryTo, string? includeSales, string? includeReturns, string? currentLogin |
| | 0 | 82 | | await ExecuteAsync(() => _armtek.GetOrderReportByDateAsync(kunnrRg, vkorg, createdFrom, createdTo, deliveryFrom, |
| | 0 | 83 | | ParseBool(includeSales), ParseBool(includeReturns), ParseBool(currentLoginOnly))); |
| | | 84 | | |
| | | 85 | | [HttpGet] |
| | | 86 | | public async Task<IActionResult> GetOrderPositionsReportByDate(string kunnrRg, string? vkorg, DateTime? createdFrom, |
| | | 87 | | DateTime? deliveryFrom, DateTime? deliveryTo, string? includeSales, string? includeReturns, string? currentLogin |
| | 0 | 88 | | await ExecuteAsync(() => _armtek.GetOrderPositionsReportByDateAsync(kunnrRg, vkorg, createdFrom, createdTo, deli |
| | 0 | 89 | | ParseBool(includeSales), ParseBool(includeReturns), ParseBool(currentLoginOnly))); |
| | | 90 | | |
| | | 91 | | [HttpGet] |
| | | 92 | | public async Task<IActionResult> GetOrderPositionsReportByDate2(string kunnrRg, string? vkorg, DateTime? createdFrom |
| | | 93 | | DateTime? deliveryFrom, DateTime? deliveryTo, string? includeSales, string? includeReturns, string? currentLogin |
| | 0 | 94 | | await ExecuteAsync(() => _armtek.GetOrderPositionsReportByDate2Async(kunnrRg, vkorg, createdFrom, createdTo, del |
| | 0 | 95 | | ParseBool(includeSales), ParseBool(includeReturns), ParseBool(currentLoginOnly), ParseBool(rejectedOnly))); |
| | | 96 | | |
| | 0 | 97 | | private static bool? ParseBool(string? value) => string.IsNullOrEmpty(value) ? null : value == "true"; |
| | | 98 | | |
| | | 99 | | private async Task<IActionResult> ExecuteAsync<T>(Func<Task<T>> operation) |
| | | 100 | | { |
| | 0 | 101 | | try { return Json(await operation()); } |
| | 0 | 102 | | catch (ArmtekApiException exception) { return StatusCode(502, new { error = true, message = exception.Message }) |
| | 0 | 103 | | catch (ArgumentException exception) { return BadRequest(new { error = true, message = exception.Message }); } |
| | 0 | 104 | | } |
| | | 105 | | } |