Newsbot.Collector/Newsbot.Collector.Api/Controllers/v1/YoutubeController.cs

41 lines
1.5 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;
using Newsbot.Collector.Domain.Models.Config;
using Newsbot.Collector.Domain.Models.Config.Sources;
using Newsbot.Collector.Services.Jobs;
using ILogger = Grpc.Core.Logging.ILogger;
namespace Newsbot.Collector.Api.Controllers.v1;
[ApiController]
[Route("api/v1/youtube")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public class YoutubeController
{
private readonly ILogger<YoutubeController> _logger;
private readonly ConfigSectionConnectionStrings _connectionStrings;
private readonly ConfigSectionYoutubeModel _config;
public YoutubeController(ILogger<YoutubeController> logger, IOptions<ConfigSectionYoutubeModel> config, IOptions<ConfigSectionConnectionStrings> connectionStrings)
{
_logger = logger;
_connectionStrings = connectionStrings.Value;
_config = config.Value;
}
[HttpPost("check")]
[Authorize(Policy = Authorization.AdministratorsRole)]
public void CheckYoutube()
{
BackgroundJob.Enqueue<YoutubeWatcherJob>(x => x.InitAndExecute(new YoutubeWatcherJobOptions
{
DatabaseConnectionString = _connectionStrings.Database,
OpenTelemetryConnectionString = _connectionStrings.OpenTelemetry,
IsEnabled = _config.IsEnabled
}));
}
}