| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Linq; |
| | | 4 | | using System.Threading.Tasks; |
| | | 5 | | using Microsoft.AspNetCore.Http; |
| | | 6 | | using Microsoft.AspNetCore.Mvc; |
| | | 7 | | using Microsoft.Extensions.Logging; |
| | | 8 | | using WinSolutions.Sveta.Server.Data.DataModel.Entities; |
| | | 9 | | using WinSolutions.Sveta.Server.Services.Interfaces; |
| | | 10 | | using WinSolutions.Sveta.Server.Data.DataModel.Kinds; |
| | | 11 | | using Swashbuckle.AspNetCore.Annotations; |
| | | 12 | | using System.Net; |
| | | 13 | | using System.Net.Http; |
| | | 14 | | using System.Net.Http.Headers; |
| | | 15 | | |
| | | 16 | | namespace SVETA.Api.Controllers |
| | | 17 | | { |
| | | 18 | | //Контроллер для генерации и удаления данных для ручных тестов |
| | | 19 | | [Route("api/v1/TestDatasets")] |
| | | 20 | | [ApiController] |
| | | 21 | | public class TestDatasets : SvetaController |
| | | 22 | | { |
| | | 23 | | private readonly IContragentService _contragentService; |
| | | 24 | | private readonly ISupplyContractService _supplyContractService; |
| | | 25 | | private readonly IDepartmentService _departmentService; |
| | | 26 | | private readonly IClusterService _clusterService; |
| | | 27 | | private readonly ICategoryService _categoryService; |
| | | 28 | | private readonly IBrandService _brandService; |
| | | 29 | | private readonly IGoodService _goodService; |
| | | 30 | | private readonly IDirectoriesService _dirService; |
| | | 31 | | private readonly ITaxSystemService _taxSystemService; |
| | | 32 | | private readonly IAddressService _addressService; |
| | | 33 | | private readonly IGoodSettingService _serviceGoodSetting; |
| | | 34 | | private readonly ICategoryRatioService _serviceCategoryRatio; |
| | | 35 | | |
| | | 36 | | |
| | | 37 | | List<Contragent> _contragentList; |
| | | 38 | | List<Department> _departmentList; |
| | | 39 | | List<Category> _categoriesList; |
| | | 40 | | List<Good> _goodList; |
| | | 41 | | RecordsState _activeState; |
| | | 42 | | |
| | | 43 | | |
| | | 44 | | public TestDatasets( |
| | | 45 | | IContragentService contragentService, |
| | | 46 | | ISupplyContractService supplyContractService, |
| | | 47 | | IDepartmentService departmentService, |
| | | 48 | | IClusterService clusterService, |
| | | 49 | | ICategoryService categoryService, |
| | | 50 | | IBrandService brandService, |
| | | 51 | | IGoodService goodService, |
| | | 52 | | IDirectoriesService dirService, |
| | | 53 | | ITaxSystemService taxSystemService, |
| | | 54 | | IAddressService addressService, |
| | | 55 | | IGoodSettingService serviceGoodSetting, |
| | | 56 | | ICategoryRatioService serviceCategoryRatio, |
| | | 57 | | ILogger<GoodsController> logger |
| | 0 | 58 | | ): base(logger) |
| | 0 | 59 | | { |
| | 0 | 60 | | _contragentService = contragentService; |
| | 0 | 61 | | _supplyContractService = supplyContractService; |
| | 0 | 62 | | _departmentService = departmentService; |
| | 0 | 63 | | _clusterService = clusterService; |
| | 0 | 64 | | _categoryService = categoryService; |
| | 0 | 65 | | _brandService = brandService; |
| | 0 | 66 | | _goodService = goodService; |
| | 0 | 67 | | _dirService = dirService; |
| | 0 | 68 | | _taxSystemService = taxSystemService; |
| | 0 | 69 | | _addressService = addressService; |
| | 0 | 70 | | _serviceGoodSetting = serviceGoodSetting; |
| | 0 | 71 | | _serviceCategoryRatio = serviceCategoryRatio; |
| | | 72 | | |
| | 0 | 73 | | _contragentList = new List<Contragent>(); |
| | 0 | 74 | | _departmentList = new List<Department>(); |
| | 0 | 75 | | _categoriesList = new List<Category>(); |
| | 0 | 76 | | _goodList = new List<Good>(); |
| | 0 | 77 | | } |
| | | 78 | | |
| | | 79 | | |
| | | 80 | | |
| | | 81 | | /// <summary> |
| | | 82 | | /// Создаёт запрос на user-info к ВТБК |
| | | 83 | | /// </summary> |
| | | 84 | | /// <remarks>author: nko</remarks> |
| | | 85 | | /// <param name="token">access_token для доступа к сервису</param> |
| | | 86 | | [HttpGet("{token}")] |
| | | 87 | | [SwaggerResponse(200, "Успешно")] |
| | | 88 | | [SwaggerResponse(500, "Ошибка на стороне сервера", typeof(string))] |
| | | 89 | | public async Task<IActionResult> GetUserInfo(string token) |
| | 0 | 90 | | { |
| | | 91 | | try |
| | 0 | 92 | | { |
| | 0 | 93 | | HttpClient client = new HttpClient(); |
| | 0 | 94 | | string res = "Error"; |
| | | 95 | | |
| | 0 | 96 | | client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); |
| | 0 | 97 | | HttpResponseMessage response = await client.GetAsync("https://stage.id.vtbconnect.ru/connect/userinfo"); |
| | 0 | 98 | | if (response.IsSuccessStatusCode) |
| | 0 | 99 | | { |
| | 0 | 100 | | res = await response.Content.ReadAsStringAsync(); |
| | 0 | 101 | | } |
| | 0 | 102 | | return Ok(res); |
| | | 103 | | } |
| | 0 | 104 | | catch(Exception e) |
| | 0 | 105 | | { |
| | 0 | 106 | | return ServerError(e); |
| | | 107 | | } |
| | 0 | 108 | | } |
| | | 109 | | /// <summary> |
| | | 110 | | /// Возвращает ошибку с соответствующим статус кодом |
| | | 111 | | /// </summary> |
| | | 112 | | /// <remarks>author: nko</remarks> |
| | | 113 | | /// <param name="code">Код желаемого кода ответа</param> |
| | | 114 | | [HttpGet("StatusCode/{code}")] |
| | | 115 | | [SwaggerResponse(200, "Успешно")] |
| | | 116 | | [SwaggerResponse(500, "Ошибка на стороне сервера", typeof(string))] |
| | | 117 | | public async Task<IActionResult> ReturnStatusCode(int code) |
| | 0 | 118 | | { |
| | | 119 | | try |
| | 0 | 120 | | { |
| | 0 | 121 | | return StatusCode(code); |
| | | 122 | | } |
| | 0 | 123 | | catch(Exception e) |
| | 0 | 124 | | { |
| | 0 | 125 | | return ServerError(e); |
| | | 126 | | } |
| | 0 | 127 | | } |
| | | 128 | | } |
| | | 129 | | } |