2023-04-10 22:59:13 -07:00
|
|
|
using Hangfire;
|
2023-07-06 22:26:19 -07:00
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2023-04-10 22:59:13 -07:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.Extensions.Options;
|
2023-07-14 22:25:44 -07:00
|
|
|
using Newsbot.Collector.Api.Domain;
|
2023-04-10 22:59:13 -07:00
|
|
|
using Newsbot.Collector.Domain.Models.Config;
|
|
|
|
using Newsbot.Collector.Services.Jobs;
|
|
|
|
|
2023-07-23 22:56:26 -07:00
|
|
|
namespace Newsbot.Collector.Api.Controllers.v1;
|
2023-04-10 22:59:13 -07:00
|
|
|
|
|
|
|
[ApiController]
|
2023-07-23 22:56:26 -07:00
|
|
|
[Route("api/v1/codeprojects")]
|
2023-07-06 22:26:19 -07:00
|
|
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
2023-04-10 22:59:13 -07:00
|
|
|
public class CodeProjectController
|
|
|
|
{
|
|
|
|
private readonly ConfigSectionConnectionStrings _connectionStrings;
|
|
|
|
private readonly ILogger<CodeProjectController> _logger;
|
|
|
|
|
|
|
|
public CodeProjectController(ILogger<CodeProjectController> logger,
|
|
|
|
IOptions<ConfigSectionConnectionStrings> settings)
|
|
|
|
{
|
|
|
|
_logger = logger;
|
|
|
|
_connectionStrings = settings.Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost("check")]
|
2023-07-23 16:22:11 -07:00
|
|
|
[Authorize(Roles = Authorization.AdministratorsRole)]
|
2023-07-23 22:56:26 -07:00
|
|
|
public ActionResult PullNow()
|
2023-04-10 22:59:13 -07:00
|
|
|
{
|
|
|
|
BackgroundJob.Enqueue<CodeProjectWatcherJob>(x => x.InitAndExecute(new CodeProjectWatcherJobOptions
|
|
|
|
{
|
|
|
|
ConnectionStrings = _connectionStrings,
|
|
|
|
FeaturePullReleases = true,
|
|
|
|
FeaturePullCommits = true
|
|
|
|
}));
|
2023-07-23 22:56:26 -07:00
|
|
|
|
|
|
|
return new AcceptedResult();
|
2023-04-10 22:59:13 -07:00
|
|
|
}
|
|
|
|
}
|