< Summary

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

Metrics

MethodLine coverage Branch coverage
.ctor(...)0%100%
GetFeedForYandex()0%0%
GetFeedForGoogle()0%100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Web;
 3using System.Collections.Generic;
 4using System.Linq;
 5using System.Threading.Tasks;
 6using Microsoft.AspNetCore.Mvc;
 7using Microsoft.Extensions.Logging;
 8using WinSolutions.Sveta.Server.Data.DataModel.Entities;
 9using WinSolutions.Sveta.Server.Services.Interfaces;
 10using Swashbuckle.AspNetCore.Annotations;
 11using Microsoft.Extensions.Options;
 12using SVETA.Api.Data.DTO;
 13using Microsoft.AspNetCore.Authorization;
 14using SVETA.Api.Data.Domain;
 15using SVETA.Api.Services.Interfaces;
 16
 17
 18namespace SVETA.Api.Controllers
 19{
 20    [Route("api/v1/Feeds")]
 21    [ApiController]
 22    public class FeedsController : SvetaController
 23    {
 24        private readonly ILogger<FeedsController> _logger;
 25        private readonly IFeedsWorker _feedWorker;
 26        private readonly FeedsSettings _feedSettings;
 27        private readonly ConfigurationsSettings _confsSettings;
 28
 29        public FeedsController( ILogger<FeedsController> logger, IFeedsWorker feedWorker,
 030            IOptions<FeedsSettings> feedSettings, IOptions<ConfigurationsSettings> confsSettings) : base(logger)
 031        {
 032            _feedSettings = feedSettings.Value;
 033            _confsSettings = confsSettings.Value;
 034            _logger = logger;
 035            _feedWorker = feedWorker;
 036        }
 37
 38        /// <summary>
 39        /// Возвращает фид по товарам для Яндекса
 40        /// </summary>
 41        /// <remarks>author: i.rebenok</remarks>
 42        /// <returns>xml файл</returns>
 43        [HttpGet("Yandex")]
 44        [SwaggerResponse(302, "Успешно", typeof(RedirectResult))]
 45        [SwaggerResponse(429, "Слишком много запросов", typeof(EmptyResult))]
 46        [SwaggerResponse(403, "Не разрешено для этого пользователя", typeof(ErrorDTO))]
 47        [SwaggerResponse(500, "Ошибка на стороне сервера", typeof(ErrorDTO))]
 48        public IActionResult GetFeedForYandex()
 049        {
 050            string filename = "YandexFeed.xml";
 051            if (DateTime.UtcNow.Subtract(
 052                DateTime.TryParse(_confsSettings.GetConfValue("FeedsSettings", "YandexTimestamp"), out DateTime dt) ? dt
 053                .TotalMinutes < (int.TryParse(_confsSettings.GetConfValue("FeedsSettings", "FrequencyTime"), out int res
 054                return StatusCode(429);
 055            var result = _feedWorker.CreateFeedForYandex(filename).Result;
 056            _confsSettings.SetConfValue("FeedsSettings", "YandexTimestamp",DateTime.UtcNow.ToString());
 057            return Redirect(result);
 058        }
 59
 60        /// <summary>
 61        /// Возвращает фид по товарам для Гугла
 62        /// </summary>
 63        /// <remarks>author: i.rebenok</remarks>
 64        /// <returns>xml файл</returns>
 65        [HttpGet("Google")]
 66        [SwaggerResponse(200, "Успешно", typeof(FileResult))]
 67        [SwaggerResponse(429, "Слишком много запросов", typeof(EmptyResult))]
 68        [SwaggerResponse(403, "Не разрешено для этого пользователя", typeof(ErrorDTO))]
 69        [SwaggerResponse(500, "Ошибка на стороне сервера", typeof(ErrorDTO))]
 70        public IActionResult GetFeedForGoogle()
 071        {
 072            string filename = "GoogleFeed.txt";
 073            var result = _feedWorker.CreateFeedForGoogle(filename).Result;
 074            Response.Headers.Add("Content-Disposition", $"attachment;filename={filename}.gz");
 075            return File(result, System.Net.Mime.MediaTypeNames.Application.Zip);
 076        }
 77    }
 78}