diff --git a/Newsbot.Collector.Api/Controllers/ArticlesController.cs b/Newsbot.Collector.Api/Controllers/ArticlesController.cs index 502d04a..e4626ba 100644 --- a/Newsbot.Collector.Api/Controllers/ArticlesController.cs +++ b/Newsbot.Collector.Api/Controllers/ArticlesController.cs @@ -1,6 +1,7 @@ +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; -using Newsbot.Collector.Database.Repositories; using Newsbot.Collector.Domain.Dto; using Newsbot.Collector.Domain.Interfaces; using Newsbot.Collector.Domain.Models; @@ -9,17 +10,18 @@ namespace Newsbot.Collector.Api.Controllers; [ApiController] [Route("api/articles")] +[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] public class ArticlesController : ControllerBase { - private readonly IArticlesRepository _articles; private readonly ILogger _logger; + private readonly IArticlesRepository _articles; private readonly ISourcesRepository _sources; - public ArticlesController(ILogger logger, IOptions settings) + public ArticlesController(ILogger logger, IArticlesRepository articles, ISourcesRepository sources) { _logger = logger; - _articles = new ArticlesTable(settings.Value.Database); - _sources = new SourcesTable(settings.Value.Database); + _articles = articles; + _sources = sources; } [HttpGet(Name = "GetArticles")] diff --git a/Newsbot.Collector.Api/Controllers/CodeProjectController.cs b/Newsbot.Collector.Api/Controllers/CodeProjectController.cs index 491d5ef..11033db 100644 --- a/Newsbot.Collector.Api/Controllers/CodeProjectController.cs +++ b/Newsbot.Collector.Api/Controllers/CodeProjectController.cs @@ -1,4 +1,6 @@ using Hangfire; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using Newsbot.Collector.Domain.Models.Config; @@ -8,6 +10,7 @@ namespace Newsbot.Collector.Api.Controllers; [ApiController] [Route("api/codeprojects")] +[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] public class CodeProjectController { private readonly ConfigSectionConnectionStrings _connectionStrings; diff --git a/Newsbot.Collector.Api/Controllers/DiscordWebHooksController.cs b/Newsbot.Collector.Api/Controllers/DiscordWebHooksController.cs index 194c6ff..b33806d 100644 --- a/Newsbot.Collector.Api/Controllers/DiscordWebHooksController.cs +++ b/Newsbot.Collector.Api/Controllers/DiscordWebHooksController.cs @@ -1,4 +1,6 @@ using System.Net; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using Newsbot.Collector.Database.Repositories; @@ -11,17 +13,16 @@ namespace Newsbot.Collector.Api.Controllers; [ApiController] [Route("api/discord/webhooks")] +[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] public class DiscordWebHookController : ControllerBase { private readonly ILogger _logger; - private readonly ConnectionStrings _settings; private readonly IDiscordWebHooksRepository _webhooks; - public DiscordWebHookController(ILogger logger, IOptions settings) + public DiscordWebHookController(ILogger logger, IOptions settings, IDiscordWebHooksRepository webhooks) { _logger = logger; - _settings = settings.Value; - _webhooks = new DiscordWebhooksTable(_settings.Database); + _webhooks = webhooks; } [HttpGet(Name = "GetDiscordWebhooks")] diff --git a/Newsbot.Collector.Api/Controllers/RssController.cs b/Newsbot.Collector.Api/Controllers/RssController.cs index 68ab76d..c97acad 100644 --- a/Newsbot.Collector.Api/Controllers/RssController.cs +++ b/Newsbot.Collector.Api/Controllers/RssController.cs @@ -1,13 +1,17 @@ using Hangfire; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using Newsbot.Collector.Domain.Models.Config; +using Newsbot.Collector.Domain.Models.Config.Sources; using Newsbot.Collector.Services.Jobs; namespace Newsbot.Collector.Api.Controllers; [ApiController] [Route("api/rss")] +[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] public class RssController { private readonly ConfigSectionConnectionStrings _connectionStrings; diff --git a/Newsbot.Collector.Api/Controllers/SourcesController.cs b/Newsbot.Collector.Api/Controllers/SourcesController.cs index 41bd859..e6cd0f2 100644 --- a/Newsbot.Collector.Api/Controllers/SourcesController.cs +++ b/Newsbot.Collector.Api/Controllers/SourcesController.cs @@ -1,3 +1,5 @@ +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using Newsbot.Collector.Database.Repositories; @@ -12,22 +14,18 @@ namespace Newsbot.Collector.Api.Controllers; [ApiController] [Route("api/sources")] +[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] public class SourcesController : ControllerBase { - private readonly IArticlesRepository _articles; - - //private readonly ConnectionStrings _settings; - private readonly IIconsRepository _icons; private readonly ILogger _logger; + private readonly IIconsRepository _icons; private readonly ISourcesRepository _sources; - public SourcesController(ILogger logger, IOptions settings) + public SourcesController(ILogger logger, IIconsRepository icons, ISourcesRepository sources) { _logger = logger; - //_settings = settings.Value; - _sources = new SourcesTable(settings.Value.Database); - _icons = new IconsTable(settings.Value.Database); - _articles = new ArticlesTable(settings.Value.Database); + _icons = icons; + _sources = sources; } [HttpGet(Name = "GetSources")] diff --git a/Newsbot.Collector.Api/Controllers/SubscriptionsController.cs b/Newsbot.Collector.Api/Controllers/SubscriptionsController.cs index 981a6b2..e8dafdd 100644 --- a/Newsbot.Collector.Api/Controllers/SubscriptionsController.cs +++ b/Newsbot.Collector.Api/Controllers/SubscriptionsController.cs @@ -1,3 +1,5 @@ +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using Newsbot.Collector.Database.Repositories; @@ -10,19 +12,20 @@ namespace Newsbot.Collector.Api.Controllers; [ApiController] [Route("api/subscriptions")] +[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] public class SubscriptionsController : ControllerBase { - private readonly IDiscordWebHooksRepository _discord; private readonly ILogger _logger; + private readonly IDiscordWebHooksRepository _discord; private readonly ISourcesRepository _sources; private readonly ISubscriptionRepository _subscription; - public SubscriptionsController(ILogger logger, IOptions settings) + public SubscriptionsController(ILogger logger, IDiscordWebHooksRepository discord, ISourcesRepository sources, ISubscriptionRepository subscription) { _logger = logger; - _subscription = new SubscriptionsTable(settings.Value.Database); - _discord = new DiscordWebhooksTable(settings.Value.Database); - _sources = new SourcesTable(settings.Value.Database); + _discord = discord; + _sources = sources; + _subscription = subscription; } [HttpGet(Name = "ListSubscriptions")] diff --git a/Newsbot.Collector.Api/Controllers/YoutubeController.cs b/Newsbot.Collector.Api/Controllers/YoutubeController.cs index b569481..6767c79 100644 --- a/Newsbot.Collector.Api/Controllers/YoutubeController.cs +++ b/Newsbot.Collector.Api/Controllers/YoutubeController.cs @@ -1,7 +1,10 @@ using Hangfire; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using Newsbot.Collector.Domain.Models.Config; +using Newsbot.Collector.Domain.Models.Config.Sources; using Newsbot.Collector.Services.Jobs; using ILogger = Grpc.Core.Logging.ILogger; @@ -9,6 +12,7 @@ namespace Newsbot.Collector.Api.Controllers; [ApiController] [Route("api/youtube")] +[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] public class YoutubeController { private readonly ILogger _logger;