2023-04-08 09:30:59 -07:00
|
|
|
using Hangfire;
|
2023-07-06 22:26:19 -07:00
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2023-04-08 09:30:59 -07:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.Extensions.Options;
|
2023-08-06 13:33:45 -07:00
|
|
|
using Newsbot.Collector.Api.Domain.Consts;
|
2023-04-08 09:30:59 -07:00
|
|
|
using Newsbot.Collector.Domain.Models.Config;
|
2023-07-06 22:26:19 -07:00
|
|
|
using Newsbot.Collector.Domain.Models.Config.Sources;
|
2023-04-08 09:30:59 -07:00
|
|
|
using Newsbot.Collector.Services.Jobs;
|
|
|
|
|
2023-07-23 22:54:00 -07:00
|
|
|
namespace Newsbot.Collector.Api.Controllers.v1;
|
2023-04-08 09:30:59 -07:00
|
|
|
|
|
|
|
[ApiController]
|
2023-07-23 22:54:00 -07:00
|
|
|
[Route("api/v1/youtube")]
|
2023-07-06 22:26:19 -07:00
|
|
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
2023-04-08 09:30:59 -07:00
|
|
|
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")]
|
2023-07-23 16:22:11 -07:00
|
|
|
[Authorize(Policy = Authorization.AdministratorsRole)]
|
2023-04-08 09:30:59 -07:00
|
|
|
public void CheckYoutube()
|
|
|
|
{
|
|
|
|
BackgroundJob.Enqueue<YoutubeWatcherJob>(x => x.InitAndExecute(new YoutubeWatcherJobOptions
|
|
|
|
{
|
|
|
|
DatabaseConnectionString = _connectionStrings.Database,
|
|
|
|
OpenTelemetryConnectionString = _connectionStrings.OpenTelemetry,
|
|
|
|
IsEnabled = _config.IsEnabled
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|