< Summary

Class:SVETA.Api.Controllers.CountriesController
Assembly:SVETA.Api
File(s):/opt/dev/sveta_api_build/SVETA.Api/Controllers/CountriesController.cs
Covered lines:0
Uncovered lines:21
Coverable lines:21
Total lines:69
Line coverage:0% (0 of 21)
Covered branches:0
Total branches:6
Branch coverage:0% (0 of 6)

Metrics

MethodLine coverage Branch coverage
.ctor(...)0%100%
GetCountries()0%0%
GetCountry()0%0%

File(s)

/opt/dev/sveta_api_build/SVETA.Api/Controllers/CountriesController.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Threading.Tasks;
 5using Microsoft.AspNetCore.Http;
 6using Microsoft.AspNetCore.Mvc;
 7using Microsoft.Extensions.Logging;
 8using WinSolutions.Sveta.Server.Data.DataModel.Entities;
 9using WinSolutions.Sveta.Server.Services.Interfaces;
 10using DTO = SVETA.Api.Data.DTO.Countries;
 11using Swashbuckle.AspNetCore.Annotations;
 12using SVETA.Api.Data.DTO;
 13
 14namespace 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
 027        public CountriesController(ILogger<PromoOfferJournalController> logger, ICountryService countryService) : base(l
 028        {
 029            _logger = logger;
 030            _countryService = countryService;
 031        }
 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()
 040        {
 041            var result = await _countryService.GetCountries();
 042            var totalCount = await _countryService.GetCountriesCount();
 43
 044            var response = new BaseResponseDTO<DTO.CountryOutput>(_routeUrl, 1, totalCount, totalCount, totalCount)
 045            {
 046                Data = result.Select(x => new DTO.CountryOutput(x)).ToList(),
 047            };
 048            return Ok(response);
 049        }
 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)
 060        {
 061            var result = await _countryService.GetCountry(id);
 062            if(result == null)
 063            {
 064                return NotFoundResult("Страна не найдена");
 65            }
 066            return Ok(new DTO.CountryOutput(result));
 067        }
 68    }
 69}