| | | 1 | | using Microsoft.AspNetCore.Authorization; |
| | | 2 | | using Microsoft.AspNetCore.Mvc; |
| | | 3 | | using Services.ApiServices.ApiSupplierRequestLog; |
| | | 4 | | using Services.ApiServices.BergApi; |
| | | 5 | | |
| | | 6 | | namespace OzonOrdersWeb.Areas.Studio2.Controllers.Directories; |
| | | 7 | | |
| | | 8 | | [Area("Studio2")] |
| | | 9 | | [Authorize(Roles = "User,Admin")] |
| | | 10 | | [Route("Berg/[action]")] |
| | | 11 | | public sealed class BergController : Controller |
| | | 12 | | { |
| | | 13 | | private readonly BergDataManager _berg; |
| | | 14 | | private readonly ApiSupplierRequestLogStore _logs; |
| | | 15 | | |
| | 0 | 16 | | public BergController(BergDataManager berg, ApiSupplierRequestLogStore logs) |
| | | 17 | | { |
| | 0 | 18 | | _berg = berg; |
| | 0 | 19 | | _logs = logs; |
| | 0 | 20 | | } |
| | | 21 | | |
| | | 22 | | [HttpGet, Route("~/Berg")] |
| | 0 | 23 | | public IActionResult Index() => View(); |
| | | 24 | | |
| | | 25 | | [HttpGet] |
| | 0 | 26 | | public IActionResult Logs() => Json(_logs.Get("Berg")); |
| | | 27 | | |
| | | 28 | | [HttpGet] |
| | 0 | 29 | | public Task<IActionResult> Brands(CancellationToken ct) => JsonAsync(() => _berg.GetBrandsAsync(ct)); |
| | | 30 | | |
| | | 31 | | [HttpGet] |
| | 0 | 32 | | public Task<IActionResult> ShipmentAddresses(CancellationToken ct) => JsonAsync(() => _berg.GetActiveShipmentAddress |
| | | 33 | | |
| | | 34 | | [HttpGet] |
| | 0 | 35 | | public Task<IActionResult> States(string? orderIds, CancellationToken ct) => JsonAsync(() => _berg.GetStatesAsync( |
| | 0 | 36 | | (orderIds ?? string.Empty).Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries), c |
| | | 37 | | |
| | | 38 | | [HttpGet] |
| | 0 | 39 | | public Task<IActionResult> ActiveStates(CancellationToken ct) => JsonAsync(() => _berg.GetActiveOrderStatesAsync(ct) |
| | | 40 | | |
| | | 41 | | [HttpGet] |
| | 0 | 42 | | public Task<IActionResult> Stock(string article, string? brand, bool includeAnalogs, long? addressId, CancellationTo |
| | 0 | 43 | | () => _berg.GetStockAsync(article, brand, includeAnalogs, addressId, ct)); |
| | | 44 | | |
| | | 45 | | private async Task<IActionResult> JsonAsync(Func<Task<Newtonsoft.Json.Linq.JToken>> call) |
| | | 46 | | { |
| | | 47 | | try |
| | | 48 | | { |
| | 0 | 49 | | var response = await call(); |
| | 0 | 50 | | return Content(response.ToString(Newtonsoft.Json.Formatting.Indented), "application/json"); |
| | | 51 | | } |
| | 0 | 52 | | catch (BergApiException ex) { return BadRequest(new { error = true, message = ex.Message }); } |
| | 0 | 53 | | } |
| | | 54 | | } |