| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Linq; |
| | | 4 | | using System.Threading.Tasks; |
| | | 5 | | using AutoMapper; |
| | | 6 | | using Microsoft.AspNetCore.Authorization; |
| | | 7 | | using Microsoft.AspNetCore.Http; |
| | | 8 | | using Microsoft.AspNetCore.Mvc; |
| | | 9 | | using Microsoft.Extensions.Logging; |
| | | 10 | | using SVETA.Api.Data.DTO; |
| | | 11 | | using SVETA.Api.Data.DTO.BankAccount; |
| | | 12 | | using SVETA.Api.Helpers.Authorize; |
| | | 13 | | using Swashbuckle.AspNetCore.Annotations; |
| | | 14 | | using WinSolutions.Sveta.Server.Data.DataModel.Entities; |
| | | 15 | | using WinSolutions.Sveta.Server.Services.Interfaces; |
| | | 16 | | using WinSolutions.Sveta.Common; |
| | | 17 | | using System.Net; |
| | | 18 | | using Microsoft.Extensions.Options; |
| | | 19 | | using SVETA.Api.Data.Domain; |
| | | 20 | | |
| | | 21 | | namespace SVETA.Api.Controllers |
| | | 22 | | { |
| | | 23 | | [Route("api/v1/DaData")] |
| | | 24 | | [ApiController] |
| | | 25 | | [Authorize] |
| | | 26 | | public class DaDataController : SvetaController |
| | | 27 | | { |
| | | 28 | | DaDataSettings _daDataSettings; |
| | | 29 | | |
| | 0 | 30 | | public DaDataController(ILogger<DaDataController> logger, IOptions<DaDataSettings> daDataSettings) : base(logger |
| | 0 | 31 | | { |
| | 0 | 32 | | _daDataSettings = daDataSettings.Value; |
| | 0 | 33 | | } |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Ищет варианты адресов на сервере DaData |
| | | 37 | | /// </summary> |
| | | 38 | | /// <param name="query">образец для поиска</param> |
| | | 39 | | /// <returns></returns> |
| | | 40 | | [HttpGet("suggest/address")] |
| | | 41 | | [SwaggerResponse(200, "Успешно", typeof(string))] |
| | | 42 | | [SwaggerResponse(401, "Пользователь не авторизован", typeof(ErrorDTO))] |
| | | 43 | | [SwaggerResponse(500, "Ошибка на стороне сервера", typeof(ErrorDTO))] |
| | | 44 | | public async Task<IActionResult> SuggestAddress(string query) |
| | 0 | 45 | | { |
| | 0 | 46 | | WebClient client = new WebClient(); |
| | 0 | 47 | | client.Headers.Add("Content-Type", "application/json"); |
| | 0 | 48 | | client.Headers.Add("Accept", "application/json"); |
| | 0 | 49 | | client.Headers.Add("Authorization", "Token " + _daDataSettings.ApiKey); |
| | 0 | 50 | | client.QueryString.Add("query", query); |
| | 0 | 51 | | client.QueryString.Add("count", 10.ToString()); |
| | 0 | 52 | | string response = client.DownloadString("https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/addres |
| | | 53 | | |
| | 0 | 54 | | return Ok(response); |
| | 0 | 55 | | } |
| | | 56 | | } |
| | | 57 | | } |