Newsbot.Collector/Newsbot.Collector.Api/Controllers/v1/RssController.cs
2023-08-06 13:32:35 -07:00

41 lines
1.4 KiB
C#

using Hangfire;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Newsbot.Collector.Api.Domain.Consts;
using Newsbot.Collector.Domain.Models.Config;
using Newsbot.Collector.Domain.Models.Config.Sources;
using Newsbot.Collector.Services.Jobs;
namespace Newsbot.Collector.Api.Controllers.v1;
[ApiController]
[Route("api/v1/rss")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public class RssController
{
private readonly ConfigSectionConnectionStrings _connectionStrings;
private readonly ILogger<RssController> _logger;
private readonly ConfigSectionRssModel _rssConfig;
public RssController(ILogger<RssController> logger, IOptions<ConfigSectionConnectionStrings> connectionStrings,
IOptions<ConfigSectionRssModel> rss)
{
_logger = logger;
_connectionStrings = connectionStrings.Value;
_rssConfig = rss.Value;
}
[HttpPost("check")]
[Authorize(Roles = Authorization.AdministratorsRole)]
public void CheckReddit()
{
BackgroundJob.Enqueue<RssWatcherJob>(x => x.InitAndExecute(new RssWatcherJobOptions
{
ConnectionString = _connectionStrings.Database,
OpenTelemetry = _connectionStrings.OpenTelemetry,
IsEnabled = _rssConfig.IsEnabled
}));
}
}