public IActionResult CreateRssFeed([FromBody] RssFeedDomainObj feedToBeCreated)
 {
     if (feedToBeCreated == null)
     {
         return(BadRequest());
     }
     if (feedToBeCreated.Source == feedToBeCreated.Description)
     {
         ModelState.AddModelError("Data", "The provided Data cannot be same as source");
     }
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         var feedToBeCreatedDto = Mapper.Map <Models.RssFeedDto>(feedToBeCreated);
         _rssFeedService.CreateRssFeed(feedToBeCreatedDto);
         return(Ok());
     }
     catch (Exception exception)
     {
         _logger.LogCritical($"Exception while saving Rss Feed", exception);
         return(StatusCode(500, "A problem happened while handling your request."));
     }
 }
Esempio n. 2
0
        public FileStreamResult Index()
        {
            var rssPath = String.Join('/', configuration["PostsLocalPath"], configuration["RssFeedFile"]);

            if (!System.IO.File.Exists(rssPath))
            {
                rssFeedService.CreateRssFeed();
            }

            var stream = System.IO.File.OpenRead(rssPath);

            return(File(stream, "application/rss+xml; charset=utf-8"));
        }
Esempio n. 3
0
        public async Task <IActionResult> UpdatePostsAsync()
        {
            var signature = Request.Headers["X-Hub-Signature"];

            using (var reader = new StreamReader(Request.Body))
            {
                var payload = await reader.ReadToEndAsync();

                if (_gitRepository.IsSecretValid(signature, payload))
                {
                    _gitRepository.Pull();
                    _fileParserService.ParseExistingFiles();
                    _rssFeedService.CreateRssFeed();
                    return(Ok());
                }
            }

            return(Unauthorized());
        }