| | | 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 DTO = SVETA.Api.Data.DTO.Countries; |
| | | 11 | | using Swashbuckle.AspNetCore.Annotations; |
| | | 12 | | using SVETA.Api.Data.DTO; |
| | | 13 | | |
| | | 14 | | namespace SVETA.Api.Controllers |
| | | 15 | | { |
| | | 16 | | /// <summary> |
| | | 17 | | /// Контроллер для работы со справочником стран |
| | | 18 | | /// </summary> |
| | | 19 | | [Route("api/v1/Countries")] |
| | | 20 | | [ApiController] |
| | | 21 | | public class CountriesController : SvetaController |
| | | 22 | | { |
| | | 23 | | const string _routeUrl = "api/v1/Countries"; |
| | | 24 | | private readonly ICountryService _countryService; |
| | | 25 | | private readonly ILogger<PromoOfferJournalController> _logger; |
| | | 26 | | |
| | 0 | 27 | | public CountriesController(ILogger<PromoOfferJournalController> logger, ICountryService countryService) : base(l |
| | 0 | 28 | | { |
| | 0 | 29 | | _logger = logger; |
| | 0 | 30 | | _countryService = countryService; |
| | 0 | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Возвращает список стран |
| | | 35 | | /// </summary> |
| | | 36 | | [HttpGet()] |
| | | 37 | | [SwaggerResponse(200, "Успешно", typeof(IEnumerable<DTO.CountryOutput>))] |
| | | 38 | | [SwaggerResponse(500, "Ошибка на стороне сервера", typeof(ErrorDTO))] |
| | | 39 | | public async Task<IActionResult> GetCountries() |
| | 0 | 40 | | { |
| | 0 | 41 | | var result = await _countryService.GetCountries(); |
| | 0 | 42 | | var totalCount = await _countryService.GetCountriesCount(); |
| | | 43 | | |
| | 0 | 44 | | var response = new BaseResponseDTO<DTO.CountryOutput>(_routeUrl, 1, totalCount, totalCount, totalCount) |
| | 0 | 45 | | { |
| | 0 | 46 | | Data = result.Select(x => new DTO.CountryOutput(x)).ToList(), |
| | 0 | 47 | | }; |
| | 0 | 48 | | return Ok(response); |
| | 0 | 49 | | } |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Возаращает страну по ее id |
| | | 53 | | /// </summary> |
| | | 54 | | /// <param name="id">Id страны</param> |
| | | 55 | | [HttpGet("{id}")] |
| | | 56 | | [SwaggerResponse(200, "Успешно", typeof(DTO.CountryOutput))] |
| | | 57 | | [SwaggerResponse(404, "Запись не найдена", typeof(ErrorDTO))] |
| | | 58 | | [SwaggerResponse(500, "Ошибка на стороне сервера", typeof(ErrorDTO))] |
| | | 59 | | public async Task<IActionResult> GetCountry(long id) |
| | 0 | 60 | | { |
| | 0 | 61 | | var result = await _countryService.GetCountry(id); |
| | 0 | 62 | | if(result == null) |
| | 0 | 63 | | { |
| | 0 | 64 | | return NotFoundResult("Страна не найдена"); |
| | | 65 | | } |
| | 0 | 66 | | return Ok(new DTO.CountryOutput(result)); |
| | 0 | 67 | | } |
| | | 68 | | } |
| | | 69 | | } |