diff --git a/Newsbot.Collector.Api/Controllers/ArticlesController.cs b/Newsbot.Collector.Api/Controllers/ArticlesController.cs deleted file mode 100644 index e4626ba..0000000 --- a/Newsbot.Collector.Api/Controllers/ArticlesController.cs +++ /dev/null @@ -1,60 +0,0 @@ -using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Options; -using Newsbot.Collector.Domain.Dto; -using Newsbot.Collector.Domain.Interfaces; -using Newsbot.Collector.Domain.Models; - -namespace Newsbot.Collector.Api.Controllers; - -[ApiController] -[Route("api/articles")] -[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] -public class ArticlesController : ControllerBase -{ - private readonly ILogger _logger; - private readonly IArticlesRepository _articles; - private readonly ISourcesRepository _sources; - - public ArticlesController(ILogger logger, IArticlesRepository articles, ISourcesRepository sources) - { - _logger = logger; - _articles = articles; - _sources = sources; - } - - [HttpGet(Name = "GetArticles")] - public IEnumerable Get() - { - var res = new List(); - var items = _articles.List(0, 25); - foreach (var item in items) res.Add(ArticleDto.Convert(item)); - return res; - } - - [HttpGet("{id:guid}")] - [EndpointDescription("Returns the article based on the Id value given.")] - public ArticleDto GetById(Guid id) - { - var item = _articles.GetById(id); - return ArticleDto.Convert(item); - } - - [HttpGet("{id:guid}/details")] - public ArticleDetailsDto GetDetailsById(Guid id) - { - var item = _articles.GetById(id); - var sourceItem = _sources.GetById(item.SourceId); - return ArticleDetailsDto.Convert(item, sourceItem); - } - - [HttpGet("by/{sourceId:guid}")] - public IEnumerable GetBySourceId(Guid sourceId, int page = 0, int count = 25) - { - var res = new List(); - var items = _articles.ListBySourceId(sourceId, page, count); - foreach (var item in items) res.Add(ArticleDto.Convert(item)); - return res; - } -} \ No newline at end of file diff --git a/Newsbot.Collector.Api/Controllers/DiscordNotificationController.cs b/Newsbot.Collector.Api/Controllers/DiscordNotificationController.cs deleted file mode 100644 index c2c8e55..0000000 --- a/Newsbot.Collector.Api/Controllers/DiscordNotificationController.cs +++ /dev/null @@ -1,130 +0,0 @@ -using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Newsbot.Collector.Domain.Dto; -using Newsbot.Collector.Domain.Entities; -using Newsbot.Collector.Domain.Interfaces; - -namespace Newsbot.Collector.Api.Controllers; - -[ApiController] -[Route("api/subscriptions")] -[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] -public class DiscordNotificationController : ControllerBase -{ - private readonly ILogger _logger; - private readonly IDiscordWebHooksRepository _discord; - private readonly ISourcesRepository _sources; - private readonly IDiscordNotificationRepository _discordNotification; - - public DiscordNotificationController(ILogger logger, IDiscordWebHooksRepository discord, ISourcesRepository sources, IDiscordNotificationRepository discordNotification) - { - _logger = logger; - _discord = discord; - _sources = sources; - _discordNotification = discordNotification; - } - - [HttpGet(Name = "ListSubscriptions")] - public IEnumerable List(int page) - { - var res = new List(); - var items = _discordNotification.List(page); - foreach (var item in items) res.Add(DiscordNotificationDto.Convert(item)); - return res; - } - - [HttpGet("{id}")] - public DiscordNotificationDto GetById(Guid id) - { - return DiscordNotificationDto.Convert(_discordNotification.GetById(id)); - } - - [HttpGet("{id}/details")] - public DiscordNotificationDetailsDto GetDetailsById(Guid id) - { - var sub = _discordNotification.GetById(id); - var webhook = _discord.GetById(sub.DiscordWebHookId); - var source = _sources.GetById(sub.SourceId); - - return DiscordNotificationDetailsDto.Convert(sub, source, webhook); - } - - [HttpPost("{id}/delete")] - public void DeleteById(Guid id) - { - _discordNotification.Delete(id); - } - - [HttpGet("by/discordId/{id}")] - public IEnumerable GetByDiscordId(Guid id) - { - var res = new List(); - var items = _discordNotification.ListByWebhook(id); - foreach (var item in items) res.Add(DiscordNotificationDto.Convert(item)); - return res; - } - - [HttpGet("by/sourceId/{id}")] - public IEnumerable GetBySourceId(Guid id) - { - var res = new List(); - var items = _discordNotification.ListBySourceId(id); - foreach (var item in items) res.Add(DiscordNotificationDto.Convert(item)); - return res; - } - - [HttpPost(Name = "New Subscription")] - public ActionResult New(Guid sourceId, Guid discordId) - { - if (sourceId == Guid.Empty) return new BadRequestResult(); - if (discordId == Guid.Empty) return new BadRequestResult(); - - var exists = _discordNotification.GetByWebhookAndSource(discordId, sourceId); - if (exists.Id != Guid.Empty) return DiscordNotificationDto.Convert(exists); - - var discord = _discord.GetById(discordId); - if (discord.Id == Guid.Empty) return new BadRequestResult(); - - var source = _sources.GetById(sourceId); - if (source.Id == Guid.Empty) return new BadRequestResult(); - - var item = _discordNotification.New(new DiscordNotificationEntity - { - Id = Guid.NewGuid(), - SourceId = sourceId, - DiscordWebHookId = discordId, - CodeAllowCommits = false, - CodeAllowReleases = false - }); - - return DiscordNotificationDto.Convert(item); - } - - [HttpPost("new/codeproject")] - public ActionResult NewCodeProjectSubscription(Guid sourceId, Guid discordId, bool allowReleases, - bool allowCommits) - { - if (sourceId == Guid.Empty) return new BadRequestResult(); - if (discordId == Guid.Empty) return new BadRequestResult(); - - var exists = _discordNotification.GetByWebhookAndSource(discordId, sourceId); - if (exists.Id != Guid.Empty) return DiscordNotificationDto.Convert(exists); - - var discord = _discord.GetById(discordId); - if (discord.Id == Guid.Empty) return new BadRequestResult(); - - var source = _sources.GetById(sourceId); - if (source.Id == Guid.Empty) return new BadRequestResult(); - - var sub = _discordNotification.New(new DiscordNotificationEntity - { - DiscordWebHookId = discordId, - SourceId = sourceId, - CodeAllowCommits = allowCommits, - CodeAllowReleases = allowReleases - }); - - return new DiscordNotificationDto(); - } -} \ No newline at end of file diff --git a/Newsbot.Collector.Api/Controllers/v1/ArticlesController.cs b/Newsbot.Collector.Api/Controllers/v1/ArticlesController.cs new file mode 100644 index 0000000..b8ed6d5 --- /dev/null +++ b/Newsbot.Collector.Api/Controllers/v1/ArticlesController.cs @@ -0,0 +1,84 @@ +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Newsbot.Collector.Domain.Dto; +using Newsbot.Collector.Domain.Interfaces; +using Newsbot.Collector.Domain.Results; + +namespace Newsbot.Collector.Api.Controllers.v1; + +[ApiController] +[Route("api/v1/articles")] +[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] +public class ArticlesController : ControllerBase +{ + //private readonly ILogger _logger; + private readonly IArticlesRepository _articles; + private readonly ISourcesRepository _sources; + + public ArticlesController(IArticlesRepository articles, ISourcesRepository sources) + { + _articles = articles; + _sources = sources; + } + + [HttpGet(Name = "GetArticles")] + public ActionResult Get() + { + var res = new List(); + var items = _articles.List(0); + foreach (var item in items) + { + res.Add(ArticleDto.Convert(item)); + } + + return new OkObjectResult(new ArticleResult + { + IsSuccessful = true, + Items = res + }); + } + + [HttpGet("{id:guid}")] + [EndpointDescription("Returns the article based on the Id value given.")] + public ActionResult GetById(Guid id) + { + var item = _articles.GetById(id); + return new OkObjectResult(new ArticleResult + { + IsSuccessful = true, + Items = new List + { + ArticleDto.Convert(item) + } + }); + } + + [HttpGet("{id:guid}/details")] + public ActionResult GetDetailsById(Guid id) + { + var item = _articles.GetById(id); + var sourceItem = _sources.GetById(item.SourceId); + + return new OkObjectResult(new ArticleDetailsResult + { + IsSuccessful = true, + Item = ArticleDetailsDto.Convert(item, sourceItem) + }); + } + + [HttpGet("by/{sourceId:guid}")] + public ActionResult GetBySourceId(Guid sourceId, int page = 0) + { + var res = new List(); + var items = _articles.ListBySourceId(sourceId, page); + foreach (var item in items) res.Add(ArticleDto.Convert(item)); + + return new OkObjectResult(new ArticleResult + { + IsSuccessful = true, + Items = res + }); + + } +} \ No newline at end of file diff --git a/Newsbot.Collector.Api/Controllers/CodeProjectController.cs b/Newsbot.Collector.Api/Controllers/v1/CodeProjectController.cs similarity index 88% rename from Newsbot.Collector.Api/Controllers/CodeProjectController.cs rename to Newsbot.Collector.Api/Controllers/v1/CodeProjectController.cs index 4929d39..d33cba1 100644 --- a/Newsbot.Collector.Api/Controllers/CodeProjectController.cs +++ b/Newsbot.Collector.Api/Controllers/v1/CodeProjectController.cs @@ -7,10 +7,10 @@ using Newsbot.Collector.Api.Domain; using Newsbot.Collector.Domain.Models.Config; using Newsbot.Collector.Services.Jobs; -namespace Newsbot.Collector.Api.Controllers; +namespace Newsbot.Collector.Api.Controllers.v1; [ApiController] -[Route("api/codeprojects")] +[Route("api/v1/codeprojects")] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] public class CodeProjectController { @@ -26,7 +26,7 @@ public class CodeProjectController [HttpPost("check")] [Authorize(Roles = Authorization.AdministratorsRole)] - public void PullNow() + public ActionResult PullNow() { BackgroundJob.Enqueue(x => x.InitAndExecute(new CodeProjectWatcherJobOptions { @@ -34,5 +34,7 @@ public class CodeProjectController FeaturePullReleases = true, FeaturePullCommits = true })); + + return new AcceptedResult(); } } \ No newline at end of file diff --git a/Newsbot.Collector.Api/Controllers/v1/DiscordNotificationController.cs b/Newsbot.Collector.Api/Controllers/v1/DiscordNotificationController.cs new file mode 100644 index 0000000..2d169ff --- /dev/null +++ b/Newsbot.Collector.Api/Controllers/v1/DiscordNotificationController.cs @@ -0,0 +1,239 @@ +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Newsbot.Collector.Api.Middleware; +using Newsbot.Collector.Domain.Dto; +using Newsbot.Collector.Domain.Entities; +using Newsbot.Collector.Domain.Interfaces; +using Newsbot.Collector.Domain.Requests; +using Newsbot.Collector.Domain.Results; + +namespace Newsbot.Collector.Api.Controllers.v1; + +[ApiController] +[Route("api/v1/subscriptions")] +[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] +public class DiscordNotificationController : ControllerBase +{ + private readonly ILogger _logger; + private readonly IDiscordWebHooksRepository _discord; + private readonly ISourcesRepository _sources; + private readonly IDiscordNotificationRepository _discordNotification; + + public DiscordNotificationController(ILogger logger, IDiscordWebHooksRepository discord, ISourcesRepository sources, IDiscordNotificationRepository discordNotification) + { + _logger = logger; + _discord = discord; + _sources = sources; + _discordNotification = discordNotification; + } + + [HttpGet(Name = "ListSubscriptions")] + public ActionResult List(int page) + { + var userId = HttpContext.GetUserId(); + if (userId.Equals(string.Empty)) + { + return new BadRequestObjectResult(new DiscordNotificationResult + { + IsSuccessful = false, + ErrorMessage = new List { "User Id is missing from the request." } + }); + } + + var res = new List(); + var items = _discordNotification.List(userId, page); + foreach (var item in items) res.Add(DiscordNotificationDto.Convert(item)); + + return new OkObjectResult(new DiscordNotificationResult + { + IsSuccessful = true, + Items = res + }); + } + + [HttpGet("{id}")] + public ActionResult GetById(Guid id) + { + var userId = HttpContext.GetUserId(); + if (userId.Equals(string.Empty)) + { + return new BadRequestObjectResult(new DiscordNotificationResult + { + IsSuccessful = false, + ErrorMessage = new List { "User Id is missing from the request." } + }); + } + + var res = DiscordNotificationDto.Convert(_discordNotification.GetById(userId, id)); + + return new OkObjectResult(new DiscordNotificationResult + { + IsSuccessful = true, + Items = new List + { + res + } + }); + } + + [HttpGet("{id}/details")] + public ActionResult GetDetailsById(Guid id) + { + var userId = HttpContext.GetUserId(); + if (userId.Equals(string.Empty)) + { + return new BadRequestObjectResult(new DiscordNotificationResult + { + IsSuccessful = false, + ErrorMessage = new List { "User Id is missing from the request." } + }); + } + + var sub = _discordNotification.GetById(userId, id); + var webhook = _discord.GetById(userId, sub.DiscordWebHookId); + var source = _sources.GetById(sub.SourceId); + + return new OkObjectResult(new DiscordNotificationDetailsResult + { + IsSuccessful = true, + Item = DiscordNotificationDetailsDto.Convert(sub, source, webhook) + }); + } + + [HttpPost("{id}/delete")] + public ActionResult DeleteById(Guid id) + { + var userId = HttpContext.GetUserId(); + if (userId.Equals(string.Empty)) + { + return new BadRequestObjectResult(new DiscordNotificationResult + { + IsSuccessful = false, + ErrorMessage = new List { "User Id is missing from the request." } + }); + } + + var rowsUpdated = _discordNotification.Delete(userId, id); + if (rowsUpdated == -1) + { + return new OkObjectResult(new DiscordNotificationResult + { + IsSuccessful = false, + ErrorMessage = new List { "Record was not own by requested user." } + }); + } + + return new OkObjectResult(new DiscordNotificationResult + { + IsSuccessful = true + }); + } + + [HttpGet("by/discordId/{id}")] + public ActionResult GetByDiscordId(Guid id) + { + var userId = HttpContext.GetUserId(); + if (userId.Equals(string.Empty)) + { + return new BadRequestObjectResult(new DiscordNotificationResult + { + IsSuccessful = false, + ErrorMessage = new List { "User Id is missing from the request." } + }); + } + + var res = new List(); + var items = _discordNotification.ListByWebhook(userId, id); + foreach (var item in items) res.Add(DiscordNotificationDto.Convert(item)); + + return new OkObjectResult(new DiscordNotificationResult + { + IsSuccessful = true, + Items = res + }); + } + + [HttpGet("by/sourceId/{id}")] + public ActionResult GetBySourceId(Guid id) + { + var userId = HttpContext.GetUserId(); + if (userId.Equals(string.Empty)) + { + return new BadRequestObjectResult(new DiscordNotificationResult + { + IsSuccessful = false, + ErrorMessage = new List { "User Id is missing from the request." } + }); + } + + var res = new List(); + var items = _discordNotification.ListBySourceId(userId, id); + foreach (var item in items) res.Add(DiscordNotificationDto.Convert(item)); + + return new OkObjectResult(new DiscordNotificationResult + { + IsSuccessful = true, + Items = res + }); + + } + + [HttpPost(Name = "New Subscription")] + public ActionResult New([FromBody] NewDiscordNotificationRequest request) + { + var userId = HttpContext.GetUserId(); + if (userId.Equals(string.Empty)) + { + return new BadRequestObjectResult(new DiscordNotificationResult + { + IsSuccessful = false, + ErrorMessage = new List { "User Id is missing from the request." } + }); + } + + if (request.SourceId == Guid.Empty) return new BadRequestObjectResult(new DiscordNotificationResult + { + IsSuccessful = false, + ErrorMessage = new List { "SourceId is missing from the request." } + }); + if (request.DiscordId == Guid.Empty) return new BadRequestObjectResult(new DiscordNotificationResult + { + IsSuccessful = false, + ErrorMessage = new List { "DiscordId is missing from the request." } + }); + + var exists = _discordNotification.GetByWebhookAndSource(userId, request.DiscordId, request.SourceId); + if (exists.Id != Guid.Empty) return DiscordNotificationDto.Convert(exists); + + var discord = _discord.GetById(userId, request.DiscordId); + if (discord.Id == Guid.Empty) return new BadRequestObjectResult(new DiscordNotificationResult + { + IsSuccessful = false, + ErrorMessage = new List { "Unable to find the requested DiscordId in the database." } + }); + + var source = _sources.GetById(request.SourceId); + if (source.Id == Guid.Empty) return new BadRequestObjectResult(new DiscordNotificationResult + { + IsSuccessful = false, + ErrorMessage = new List { "Unable to find the requested SourceId in the database." } + }); + + var item = _discordNotification.New(new DiscordNotificationEntity + { + Id = Guid.NewGuid(), + SourceId = request.SourceId, + DiscordWebHookId = request.DiscordId, + CodeAllowCommits = request.AllowCommits, + CodeAllowReleases = request.AllowReleases, + UserId = userId + }); + + return new OkObjectResult(new DiscordNotificationResult + { + IsSuccessful = true, + Items = new List { DiscordNotificationDto.Convert(item) } + }); + } +} \ No newline at end of file diff --git a/Newsbot.Collector.Api/Controllers/DiscordWebHooksController.cs b/Newsbot.Collector.Api/Controllers/v1/DiscordWebHooksController.cs similarity index 50% rename from Newsbot.Collector.Api/Controllers/DiscordWebHooksController.cs rename to Newsbot.Collector.Api/Controllers/v1/DiscordWebHooksController.cs index b33806d..28a1ebc 100644 --- a/Newsbot.Collector.Api/Controllers/DiscordWebHooksController.cs +++ b/Newsbot.Collector.Api/Controllers/v1/DiscordWebHooksController.cs @@ -1,18 +1,19 @@ -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; +using Newsbot.Collector.Api.Middleware; using Newsbot.Collector.Domain.Dto; using Newsbot.Collector.Domain.Entities; using Newsbot.Collector.Domain.Interfaces; using Newsbot.Collector.Domain.Models; +using Newsbot.Collector.Domain.Requests; +using Newsbot.Collector.Domain.Results; -namespace Newsbot.Collector.Api.Controllers; +namespace Newsbot.Collector.Api.Controllers.v1; [ApiController] -[Route("api/discord/webhooks")] +[Route("api/v1/discord/webhooks")] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] public class DiscordWebHookController : ControllerBase { @@ -26,43 +27,64 @@ public class DiscordWebHookController : ControllerBase } [HttpGet(Name = "GetDiscordWebhooks")] - public IEnumerable Get(int page) + public ActionResult> Get(int page) { + var userId = HttpContext.GetUserId(); + if (userId.Equals(string.Empty)) + { + _logger.LogWarning("Unable to find the user ID in the JWD Token"); + return new BadRequestResult(); + } + var items = new List(); - var res = _webhooks.List(page); + var res = _webhooks.ListByUserId(userId, page); foreach (var item in res) { items.Add(DiscordWebHookDto.Convert(item)); } - return items; + + return new OkObjectResult(items); } [HttpPost(Name = "New")] - public DiscordWebHookDto New(string url, string server, string channel) + public ActionResult New([FromBody] NewDiscordWebhookRequest request) { - var exists = _webhooks.GetByUrl(url); - // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract + var userId = HttpContext.GetUserId(); + + var exists = _webhooks.GetByUrl(request.Url ?? ""); if (exists.Id != Guid.Empty) { - return DiscordWebHookDto.Convert(exists); + return new BadRequestObjectResult(new DiscordWebhookResult + { + IsSuccessful = true, + Items = new List { DiscordWebHookDto.Convert(exists) } + }); } var res = _webhooks.New(new DiscordWebhookEntity { - Url = url, - Server = server, - Channel = channel, + UserId = userId, + Url = request.Url ?? "", + Server = request.Server ?? "", + Channel = request.Channel ?? "", Enabled = true, }); - return DiscordWebHookDto.Convert(res); + return new OkObjectResult(new DiscordWebhookResult + { + IsSuccessful = true, + Items = new List + { + DiscordWebHookDto.Convert(res) + } + }); } [HttpGet("by/serverAndChannel")] public IEnumerable GetByServerAndChannel(string server, string channel) { var items = new List(); - var res = _webhooks.ListByServerAndChannel(server, channel, 25); + var res = _webhooks.ListByServerAndChannel(HttpContext.GetUserId(), server, channel, 25); foreach (var item in res) { @@ -72,21 +94,21 @@ public class DiscordWebHookController : ControllerBase } [HttpGet("{id}")] - public DiscordWebHookDto GetById(Guid id) + public DiscordWebHookDto GetById(string userId, Guid id) { - var res = _webhooks.GetById(id); + var res = _webhooks.GetById(userId, id); return DiscordWebHookDto.Convert(res); } [HttpPost("{id}/disable")] public void DisableById(Guid id) { - _webhooks.Disable(id); + _webhooks.Disable(HttpContext.GetUserId(), id); } [HttpPost("{id}/enable")] public void EnableById(Guid id) { - _webhooks.Enable(id); + _webhooks.Enable(HttpContext.GetUserId(), id); } } \ No newline at end of file diff --git a/Newsbot.Collector.Api/Controllers/v1/IdentityController.cs b/Newsbot.Collector.Api/Controllers/v1/IdentityController.cs index ddfd6e7..b260be5 100644 --- a/Newsbot.Collector.Api/Controllers/v1/IdentityController.cs +++ b/Newsbot.Collector.Api/Controllers/v1/IdentityController.cs @@ -1,10 +1,10 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newsbot.Collector.Api.Domain; -using Newsbot.Collector.Api.Domain.Requests; -using Newsbot.Collector.Api.Domain.Response; -using Newsbot.Collector.Api.Domain.Results; -using Newsbot.Collector.Api.Services; +using Newsbot.Collector.Domain.Requests; +using Newsbot.Collector.Domain.Response; +using Newsbot.Collector.Domain.Results; +using Newsbot.Collector.Services; namespace Newsbot.Collector.Api.Controllers.v1; @@ -12,11 +12,13 @@ namespace Newsbot.Collector.Api.Controllers.v1; [Route("/api/v1/account")] public class IdentityController : ControllerBase { - private IIdentityService _identityService; + private readonly ILogger _logger; + private readonly IIdentityService _identityService; - public IdentityController(IIdentityService identityService) + public IdentityController(IIdentityService identityService, ILogger logger) { _identityService = identityService; + _logger = logger; } [HttpPost("register")] @@ -81,6 +83,7 @@ public class IdentityController : ControllerBase } catch (Exception ex) { + _logger.LogWarning(ex, "Failed to add role to user"); return new BadRequestResult(); } } diff --git a/Newsbot.Collector.Api/Controllers/RssController.cs b/Newsbot.Collector.Api/Controllers/v1/RssController.cs similarity index 95% rename from Newsbot.Collector.Api/Controllers/RssController.cs rename to Newsbot.Collector.Api/Controllers/v1/RssController.cs index bfaaa7d..9b31637 100644 --- a/Newsbot.Collector.Api/Controllers/RssController.cs +++ b/Newsbot.Collector.Api/Controllers/v1/RssController.cs @@ -8,10 +8,10 @@ using Newsbot.Collector.Domain.Models.Config; using Newsbot.Collector.Domain.Models.Config.Sources; using Newsbot.Collector.Services.Jobs; -namespace Newsbot.Collector.Api.Controllers; +namespace Newsbot.Collector.Api.Controllers.v1; [ApiController] -[Route("api/rss")] +[Route("api/v1/rss")] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] public class RssController { diff --git a/Newsbot.Collector.Api/Controllers/SourcesController.cs b/Newsbot.Collector.Api/Controllers/v1/SourcesController.cs similarity index 100% rename from Newsbot.Collector.Api/Controllers/SourcesController.cs rename to Newsbot.Collector.Api/Controllers/v1/SourcesController.cs diff --git a/Newsbot.Collector.Api/Controllers/v1/UserController.cs b/Newsbot.Collector.Api/Controllers/v1/UserController.cs index 9125463..04285b3 100644 --- a/Newsbot.Collector.Api/Controllers/v1/UserController.cs +++ b/Newsbot.Collector.Api/Controllers/v1/UserController.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newsbot.Collector.Api.Authentication; +using Newsbot.Collector.Api.Middleware; using Newsbot.Collector.Domain.Entities; using Newsbot.Collector.Domain.Interfaces; diff --git a/Newsbot.Collector.Api/Controllers/YoutubeController.cs b/Newsbot.Collector.Api/Controllers/v1/YoutubeController.cs similarity index 95% rename from Newsbot.Collector.Api/Controllers/YoutubeController.cs rename to Newsbot.Collector.Api/Controllers/v1/YoutubeController.cs index b3f34e1..66ea171 100644 --- a/Newsbot.Collector.Api/Controllers/YoutubeController.cs +++ b/Newsbot.Collector.Api/Controllers/v1/YoutubeController.cs @@ -9,10 +9,10 @@ using Newsbot.Collector.Domain.Models.Config.Sources; using Newsbot.Collector.Services.Jobs; using ILogger = Grpc.Core.Logging.ILogger; -namespace Newsbot.Collector.Api.Controllers; +namespace Newsbot.Collector.Api.Controllers.v1; [ApiController] -[Route("api/youtube")] +[Route("api/v1/youtube")] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] public class YoutubeController { diff --git a/Newsbot.Collector.Api/Domain/Results/AuthenticationResult.cs b/Newsbot.Collector.Api/Domain/Results/AuthenticationResult.cs deleted file mode 100644 index 4cd4516..0000000 --- a/Newsbot.Collector.Api/Domain/Results/AuthenticationResult.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Collections; - -namespace Newsbot.Collector.Api.Domain.Results; - -public class AuthenticationResult -{ - public string? Token { get; set; } - public string? RefreshToken { get; set; } - - public bool IsSuccessful { get; set; } - public IEnumerable? ErrorMessage { get; set; } -} \ No newline at end of file diff --git a/Newsbot.Collector.Api/Middleware/JwtUserIdExtension.cs b/Newsbot.Collector.Api/Middleware/JwtUserIdExtension.cs index 80c0e09..041440a 100644 --- a/Newsbot.Collector.Api/Middleware/JwtUserIdExtension.cs +++ b/Newsbot.Collector.Api/Middleware/JwtUserIdExtension.cs @@ -1,14 +1,9 @@ -namespace Newsbot.Collector.Api.Authentication; +namespace Newsbot.Collector.Api.Middleware; public static class JwtUserIdExtension { public static string GetUserId(this HttpContext context) { - if (context.User == null) - { - return string.Empty; - } - return context.User.Claims.Single(x => x.Type == "id").Value; } } \ No newline at end of file diff --git a/Newsbot.Collector.Api/Newsbot.Collector.Api.csproj b/Newsbot.Collector.Api/Newsbot.Collector.Api.csproj index 969a610..76badf8 100644 --- a/Newsbot.Collector.Api/Newsbot.Collector.Api.csproj +++ b/Newsbot.Collector.Api/Newsbot.Collector.Api.csproj @@ -4,6 +4,8 @@ net7.0 enable enable + + true diff --git a/Newsbot.Collector.Api/Program.cs b/Newsbot.Collector.Api/Program.cs index e3ae5fc..f35dbc3 100644 --- a/Newsbot.Collector.Api/Program.cs +++ b/Newsbot.Collector.Api/Program.cs @@ -35,7 +35,7 @@ GlobalConfiguration.Configuration.UseSerilogLogProvider(); // Build Health Checks builder.Services.AddHealthChecks() - .AddNpgSql(config.GetValue(ConfigConnectionStringConst.Database) ?? ""); + .AddNpgSql(config.GetValue(ConfigConst.ConnectionStringDatabase) ?? ""); builder.Services.AddControllers(); @@ -109,7 +109,7 @@ static IConfiguration GetConfiguration() static ILogger GetLogger(IConfiguration configuration) { - var otel = configuration.GetValue(ConfigConnectionStringConst.OpenTelemetry) ?? ""; + var otel = configuration.GetValue(ConfigConst.ConnectionStringOpenTelemetry) ?? ""; if (otel == "") return Log.Logger = new LoggerConfiguration() diff --git a/Newsbot.Collector.Api/Startup/DatabaseStartup.cs b/Newsbot.Collector.Api/Startup/DatabaseStartup.cs index 04495ae..f5f60c3 100644 --- a/Newsbot.Collector.Api/Startup/DatabaseStartup.cs +++ b/Newsbot.Collector.Api/Startup/DatabaseStartup.cs @@ -1,10 +1,10 @@ using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Newsbot.Collector.Api.Domain; -using Newsbot.Collector.Api.Services; using Newsbot.Collector.Database; using Newsbot.Collector.Database.Repositories; using Newsbot.Collector.Domain.Interfaces; +using Newsbot.Collector.Services; namespace Newsbot.Collector.Api.Startup; diff --git a/Newsbot.Collector.Database/DatabaseContext.cs b/Newsbot.Collector.Database/DatabaseContext.cs index a3e0fdc..338da9c 100644 --- a/Newsbot.Collector.Database/DatabaseContext.cs +++ b/Newsbot.Collector.Database/DatabaseContext.cs @@ -17,8 +17,8 @@ public class DatabaseContext : IdentityDbContext public DbSet Sources { get; set; } = null!; public DbSet UserSourceSubscription { get; set; } = null!; - - public DbSet RefreshTokens { get; set; } + + public DbSet RefreshTokens { get; set; } = null!; private string ConnectionString { get; set; } = ""; diff --git a/Newsbot.Collector.Database/Newsbot.Collector.Database.csproj b/Newsbot.Collector.Database/Newsbot.Collector.Database.csproj index 68f1436..47f2b44 100644 --- a/Newsbot.Collector.Database/Newsbot.Collector.Database.csproj +++ b/Newsbot.Collector.Database/Newsbot.Collector.Database.csproj @@ -21,6 +21,9 @@ net7.0 enable enable + + true + 8981 diff --git a/Newsbot.Collector.Database/Repositories/DiscordNotificationTable.cs b/Newsbot.Collector.Database/Repositories/DiscordNotificationTable.cs index 9132d8b..4b884a1 100644 --- a/Newsbot.Collector.Database/Repositories/DiscordNotificationTable.cs +++ b/Newsbot.Collector.Database/Repositories/DiscordNotificationTable.cs @@ -1,10 +1,5 @@ -using System.Data; -using Dapper; -using Microsoft.Extensions.Configuration; using Newsbot.Collector.Domain.Entities; using Newsbot.Collector.Domain.Interfaces; -using Newsbot.Collector.Domain.Models; -using Npgsql; namespace Newsbot.Collector.Database.Repositories; @@ -27,66 +22,76 @@ public class DiscordNotificationTable : IDiscordNotificationRepository public DiscordNotificationEntity New(DiscordNotificationEntity model) { model.Id = new Guid(); - //using var context = new DatabaseContext(_connectionString); + _context.DiscordNotification.Add(model); _context.SaveChanges(); + return model; } - public List List(int page = 0, int count = 25) + public List List(string userId, int page = 0, int count = 25) { - //using var context = new DatabaseContext(_connectionString); - return _context.DiscordNotification.Skip(page * count).Take(count).ToList(); + return _context.DiscordNotification + .Where(x => x.UserId != null && x.UserId.Equals(userId)) + .Skip(page * count) + .Take(count) + .ToList(); } + public List ListBySourceId(string userId, Guid id, int page = 0, int count = 25) + { + return _context.DiscordNotification + .Where(f => f.SourceId.Equals(id)) + .Where(f => f.UserId != null && f.UserId.Equals(userId)) + .Skip(page * count) + .ToList(); + } + public List ListBySourceId(Guid id, int page = 0, int count = 25) { - //using var context = new DatabaseContext(_connectionString); - return _context.DiscordNotification.Where(f => f.SourceId.Equals(id)) + return _context.DiscordNotification + .Where(f => f.SourceId.Equals(id)) .Skip(page * count) .ToList(); } - public List ListByWebhook(Guid id, int page = 0, int count = 25) + public List ListByWebhook(string userId, Guid id, int page = 0, int count = 25) { - //using var context = new DatabaseContext(_connectionString); - return _context.DiscordNotification.Where(f => f.DiscordWebHookId.Equals(id)).Skip(page * count).ToList(); + return _context.DiscordNotification + .Where(f => f.DiscordWebHookId.Equals(id)) + .Where(f => f.UserId != null && f.UserId.Equals(userId)) + .Skip(page * count) + .ToList(); } - public DiscordNotificationEntity GetById(Guid id) + public DiscordNotificationEntity GetById(string userId, Guid id) { - //using var context = new DatabaseContext(_connectionString); var res = _context.DiscordNotification + .Where(f => f.UserId != null && f.UserId.Equals(userId)) .FirstOrDefault(f => f.Id.Equals(id)); return res ??= new DiscordNotificationEntity(); } - public DiscordNotificationEntity GetByWebhookAndSource(Guid webhookId, Guid sourceId) + public DiscordNotificationEntity GetByWebhookAndSource(string userId, Guid webhookId, Guid sourceId) { - //using var context = new DatabaseContext(_connectionString); var res = _context.DiscordNotification + .Where(f => f.UserId != null && f.UserId.Equals(userId)) .Where(f => f.DiscordWebHookId.Equals(webhookId)) .FirstOrDefault(f => f.SourceId.Equals(sourceId)); return res ??= new DiscordNotificationEntity(); } - public void Delete(Guid id) + public int Delete(string userId, Guid id) { - //using var context = new DatabaseContext(_connectionString); - var res = _context.DiscordNotification.FirstOrDefault(f => f.Id.Equals(id)); + var res = _context.DiscordNotification + .Where(f => f.UserId != null && f.UserId.Equals(userId)) + .FirstOrDefault(f => f.Id.Equals(id)); if (res is null) { - return; + return -1; } _context.DiscordNotification.Remove(res); - _context.SaveChanges(); + return _context.SaveChanges(); } - - //private IDbConnection OpenConnection(string connectionString) - //{ - // var conn = new NpgsqlConnection(_connectionString); - // conn.Open(); - // return conn; - //} } \ No newline at end of file diff --git a/Newsbot.Collector.Database/Repositories/DiscordWebhooksTable.cs b/Newsbot.Collector.Database/Repositories/DiscordWebhooksTable.cs index c667d23..cf38100 100644 --- a/Newsbot.Collector.Database/Repositories/DiscordWebhooksTable.cs +++ b/Newsbot.Collector.Database/Repositories/DiscordWebhooksTable.cs @@ -1,5 +1,6 @@ using System.Data; using Dapper; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Newsbot.Collector.Domain.Interfaces; using Newsbot.Collector.Domain.Entities; @@ -33,10 +34,20 @@ public class DiscordWebhooksTable : IDiscordWebHooksRepository return model; } - public DiscordWebhookEntity GetById(Guid id) + public DiscordWebhookEntity GetById(string userId, Guid id) { //using var context = new DatabaseContext(_connectionString); - var res = _context.DiscordWebhooks.FirstOrDefault(d => d.Id.Equals(id)); + var res = _context.DiscordWebhooks + .Where(i => i.UserId != null && i.UserId.Equals(userId)) + .FirstOrDefault(d => d.Id.Equals(id)); + res ??= new DiscordWebhookEntity(); + return res; + } + + public DiscordWebhookEntity GetById(Guid id) + { + var res = _context.DiscordWebhooks + .FirstOrDefault(d => d.Id.Equals(id)); res ??= new DiscordWebhookEntity(); return res; } @@ -60,6 +71,16 @@ public class DiscordWebhooksTable : IDiscordWebHooksRepository return res; } + public List ListByUserId(string userId, int page) + { + var query = _context.DiscordWebhooks + .Where(p => p.UserId != null && p.UserId.Equals(userId)) + .Skip(page * 25) + .Take(25) + .ToList(); + return query; + } + public List ListByServer(string server, int limit = 25) { //using var context = new DatabaseContext(_connectionString); @@ -71,10 +92,11 @@ public class DiscordWebhooksTable : IDiscordWebHooksRepository return res; } - public List ListByServerAndChannel(string server, string channel, int limit = 25) + public List ListByServerAndChannel(string userId, string server, string channel, int limit = 25) { //using var context = new DatabaseContext(_connectionString); var res = _context.DiscordWebhooks + .Where(i => i.UserId != null && i.UserId.Equals(userId)) .Where(s => s.Server.Equals(server)) .Where(c => c.Channel.Equals(channel)) .Take(limit) @@ -83,9 +105,9 @@ public class DiscordWebhooksTable : IDiscordWebHooksRepository return res; } - public int Disable(Guid id) + public int Disable(string userId, Guid id) { - var res = GetById(id); + var res = GetById(userId, id); //using var context = new DatabaseContext(_connectionString); res.Enabled = true; @@ -103,9 +125,9 @@ public class DiscordWebhooksTable : IDiscordWebHooksRepository } } - public int Enable(Guid id) + public int Enable(string userId, Guid id) { - var res = GetById(id); + var res = GetById(userId, id); //using var context = new DatabaseContext(_connectionString); res.Enabled = false; diff --git a/Newsbot.Collector.Database/Repositories/UserSourceSubscriptionTable.cs b/Newsbot.Collector.Database/Repositories/UserSourceSubscriptionTable.cs index fcfb314..2feb020 100644 --- a/Newsbot.Collector.Database/Repositories/UserSourceSubscriptionTable.cs +++ b/Newsbot.Collector.Database/Repositories/UserSourceSubscriptionTable.cs @@ -19,7 +19,8 @@ public class UserSourceSubscriptionTable : IUserSourceSubscription public List ListUserSubscriptions(Guid userId) { - var results =_context.UserSourceSubscription.Where(i => i.UserId.Equals(userId)).ToList(); + var results =_context.UserSourceSubscription + .Where(i => i.UserId != null && i.UserId.Equals(userId)).ToList(); return results; } } diff --git a/Newsbot.Collector.Api/Domain/Authorization.cs b/Newsbot.Collector.Domain/Consts/Authorization.cs similarity index 100% rename from Newsbot.Collector.Api/Domain/Authorization.cs rename to Newsbot.Collector.Domain/Consts/Authorization.cs diff --git a/Newsbot.Collector.Domain/Consts/ConfigConnectionStringsConst.cs b/Newsbot.Collector.Domain/Consts/ConfigConnectionStringsConst.cs deleted file mode 100644 index 85f9db6..0000000 --- a/Newsbot.Collector.Domain/Consts/ConfigConnectionStringsConst.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Newsbot.Collector.Domain.Consts; - -/// -/// This class contains const entries to access keys within IConfiguration. -/// -public static class ConfigConnectionStringConst -{ - public const string Database = "ConnectionStrings:Database"; - public const string OpenTelemetry = "ConnectionStrings:OpenTelemetry"; -} \ No newline at end of file diff --git a/Newsbot.Collector.Domain/Consts/ConfigTwitchConst.cs b/Newsbot.Collector.Domain/Consts/ConfigTwitchConst.cs deleted file mode 100644 index 24b02fd..0000000 --- a/Newsbot.Collector.Domain/Consts/ConfigTwitchConst.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Newsbot.Collector.Domain.Consts; - -/// -/// This class contains const entries to access keys within IConfiguration. -/// -public class ConfigTwitchConst -{ - public const string IsEnabled = "Twitch:IsEnabled"; - public const string ClientID = "Twitch:ClientID"; - public const string ClientSecret = "Twitch:ClientSecret"; -} \ No newline at end of file diff --git a/Newsbot.Collector.Domain/Consts/ConfigYoutubeConst.cs b/Newsbot.Collector.Domain/Consts/ConfigYoutubeConst.cs deleted file mode 100644 index 41012f7..0000000 --- a/Newsbot.Collector.Domain/Consts/ConfigYoutubeConst.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Newsbot.Collector.Domain.Consts; - -/// -/// This class contains const entries to access keys within IConfiguration. -/// -public class ConfigYoutubeConst -{ - public const string IsEnable = "Youtube:IsEnabled"; - public const string Debug = "Youtube:Debug"; -} \ No newline at end of file diff --git a/Newsbot.Collector.Domain/Entities/DiscordWebhookEntity.cs b/Newsbot.Collector.Domain/Entities/DiscordWebhookEntity.cs index 7e7ec40..38758e2 100644 --- a/Newsbot.Collector.Domain/Entities/DiscordWebhookEntity.cs +++ b/Newsbot.Collector.Domain/Entities/DiscordWebhookEntity.cs @@ -1,3 +1,6 @@ +using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.AspNetCore.Identity; + namespace Newsbot.Collector.Domain.Entities; public class DiscordWebhookEntity @@ -7,4 +10,8 @@ public class DiscordWebhookEntity public string Server { get; set; } = ""; public string Channel { get; set; } = ""; public bool Enabled { get; set; } + + public string? UserId { get; set; } + [ForeignKey(nameof(UserId))] + public IdentityUser? User { get; set; } } \ No newline at end of file diff --git a/Newsbot.Collector.Domain/Interfaces/IArticlesRepository.cs b/Newsbot.Collector.Domain/Interfaces/IArticlesRepository.cs index 4cabce7..c9f86c6 100644 --- a/Newsbot.Collector.Domain/Interfaces/IArticlesRepository.cs +++ b/Newsbot.Collector.Domain/Interfaces/IArticlesRepository.cs @@ -5,7 +5,7 @@ namespace Newsbot.Collector.Domain.Interfaces; public interface IArticlesRepository : ITableRepository { - List List(int page, int count); + List List(int page, int count = 25); List ListBySourceId(Guid id, int page = 0, int count = 25); ArticlesEntity GetById(Guid id); ArticlesEntity GetByUrl(string url); diff --git a/Newsbot.Collector.Domain/Interfaces/IDiscordNotificationRepository.cs b/Newsbot.Collector.Domain/Interfaces/IDiscordNotificationRepository.cs index c71e137..f2dbf61 100644 --- a/Newsbot.Collector.Domain/Interfaces/IDiscordNotificationRepository.cs +++ b/Newsbot.Collector.Domain/Interfaces/IDiscordNotificationRepository.cs @@ -7,12 +7,22 @@ public interface IDiscordNotificationRepository { DiscordNotificationEntity New(DiscordNotificationEntity model); - List List(int page = 0, int count = 25); + List List(string userId, int page = 0, int count = 25); + List ListBySourceId(string userId, Guid id, int page = 0, int count = 25); + + /// + /// This will collect all the records based on the SourceId. + /// Background jobs can use this but user facing calls need to define UserId + /// + /// + /// + /// + /// List ListBySourceId(Guid id, int page = 0, int count = 25); - List ListByWebhook(Guid id, int page = 0, int count = 25); + List ListByWebhook(string userId, Guid id, int page = 0, int count = 25); - DiscordNotificationEntity GetById(Guid id); - DiscordNotificationEntity GetByWebhookAndSource(Guid webhookId, Guid sourceId); + DiscordNotificationEntity GetById(string userId, Guid id); + DiscordNotificationEntity GetByWebhookAndSource(string userId, Guid webhookId, Guid sourceId); - void Delete(Guid id); + int Delete(string userId, Guid id); } \ No newline at end of file diff --git a/Newsbot.Collector.Domain/Interfaces/IDiscordWebHooksRepository.cs b/Newsbot.Collector.Domain/Interfaces/IDiscordWebHooksRepository.cs index 2192371..39789fc 100644 --- a/Newsbot.Collector.Domain/Interfaces/IDiscordWebHooksRepository.cs +++ b/Newsbot.Collector.Domain/Interfaces/IDiscordWebHooksRepository.cs @@ -6,13 +6,16 @@ public interface IDiscordWebHooksRepository { DiscordWebhookEntity New(DiscordWebhookEntity model); + DiscordWebhookEntity GetById(string userId, Guid id); DiscordWebhookEntity GetById(Guid id); + DiscordWebhookEntity GetByUrl(string url); List List(int page, int count = 25); + List ListByUserId(string userId, int page); List ListByServer(string server, int limit); - List ListByServerAndChannel(string server, string channel, int limit); + List ListByServerAndChannel(string userId, string server, string channel, int limit); - int Disable(Guid id); - int Enable(Guid id); + int Disable(string userId, Guid id); + int Enable(string userId, Guid id); } \ No newline at end of file diff --git a/Newsbot.Collector.Domain/Models/Config.cs b/Newsbot.Collector.Domain/Models/Config.cs index 77dd469..f9e9cd4 100644 --- a/Newsbot.Collector.Domain/Models/Config.cs +++ b/Newsbot.Collector.Domain/Models/Config.cs @@ -1,13 +1,24 @@ +using Newsbot.Collector.Domain.Models.Config; + namespace Newsbot.Collector.Domain.Models; public class ConfigModel { - public string? ServerAddress { get; set; } - public string? SqlConnectionString { get; set; } - public RedditConfigModel? Reddit { get; set; } + public ConnectionStrings? ConnectionStrings { get; set; } + public RedditConfig? Reddit { get; set; } + public YoutubeConfig? Youtube { get; set; } + public TwitchConfig? Twitch { get; set; } + public BasicSourceConfig? FinalFantasyXiv { get; set; } + public BasicSourceConfig? Rss { get; set; } + public BasicSourceConfig? CodeProjects { get; set; } + public NotificationsConfig? Notifications { get; set; } + public bool EnableSwagger { get; set; } + public bool RunDatabaseMigrationsOnStartup { get; set; } + public List? ApiKeys { get; set; } + public JwtSettings? JwtSettings { get; set; } } -public class RedditConfigModel +public class RedditConfig { public bool IsEnabled { get; set; } public bool PullHot { get; set; } @@ -17,5 +28,29 @@ public class RedditConfigModel public class ConnectionStrings { - public string Database { get; set; } = ""; -} \ No newline at end of file + public string? Database { get; set; } + public string? OpenTelemetry { get; set; } +} + +public class BasicSourceConfig +{ + public bool IsEnabled { get; set; } +} + +public class YoutubeConfig +{ + public bool IsEnabled { get; set; } + public bool Debug { get; set; } +} + +public class TwitchConfig +{ + public bool IsEnabled { get; set; } + public string? ClientId { get; set; } + public string? ClientSecret { get; set; } +} + +public class NotificationsConfig +{ + public BasicSourceConfig? Discord { get; set; } +} diff --git a/Newsbot.Collector.Domain/Models/Config/Sources/ConfigSectionRedditModel.cs b/Newsbot.Collector.Domain/Models/Config/Sources/ConfigSectionRedditModel.cs deleted file mode 100644 index e647630..0000000 --- a/Newsbot.Collector.Domain/Models/Config/Sources/ConfigSectionRedditModel.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Newsbot.Collector.Domain.Models.Config.Sources; - -public class ConfigSectionRedditModel -{ - public bool IsEnabled { get; set; } - public bool PullHot { get; set; } - public bool PullNsfw { get; set; } - public bool PullTop { get; set; } -} \ No newline at end of file diff --git a/Newsbot.Collector.Domain/Newsbot.Collector.Domain.csproj b/Newsbot.Collector.Domain/Newsbot.Collector.Domain.csproj index b355dd0..462ff5b 100644 --- a/Newsbot.Collector.Domain/Newsbot.Collector.Domain.csproj +++ b/Newsbot.Collector.Domain/Newsbot.Collector.Domain.csproj @@ -4,6 +4,8 @@ net7.0 enable enable + + true diff --git a/Newsbot.Collector.Domain/Requests/NewDiscordNotificationRequest.cs b/Newsbot.Collector.Domain/Requests/NewDiscordNotificationRequest.cs new file mode 100644 index 0000000..0ba7f4d --- /dev/null +++ b/Newsbot.Collector.Domain/Requests/NewDiscordNotificationRequest.cs @@ -0,0 +1,10 @@ +namespace Newsbot.Collector.Domain.Requests; + +public class NewDiscordNotificationRequest +{ + public Guid SourceId { get; set; } + public Guid DiscordId { get; set; } + + public bool AllowReleases { get; set; } = false; + public bool AllowCommits { get; set; } = false; +} \ No newline at end of file diff --git a/Newsbot.Collector.Domain/Requests/NewDiscordWebhookRequest.cs b/Newsbot.Collector.Domain/Requests/NewDiscordWebhookRequest.cs new file mode 100644 index 0000000..37a71c1 --- /dev/null +++ b/Newsbot.Collector.Domain/Requests/NewDiscordWebhookRequest.cs @@ -0,0 +1,8 @@ +namespace Newsbot.Collector.Domain.Requests; + +public class NewDiscordWebhookRequest +{ + public string? Url { get; set; } + public string? Server { get; set; } + public string? Channel { get; set; } +} \ No newline at end of file diff --git a/Newsbot.Collector.Api/Domain/Requests/NewRoleRequest.cs b/Newsbot.Collector.Domain/Requests/NewRoleRequest.cs similarity index 69% rename from Newsbot.Collector.Api/Domain/Requests/NewRoleRequest.cs rename to Newsbot.Collector.Domain/Requests/NewRoleRequest.cs index 706ebef..b15867d 100644 --- a/Newsbot.Collector.Api/Domain/Requests/NewRoleRequest.cs +++ b/Newsbot.Collector.Domain/Requests/NewRoleRequest.cs @@ -1,4 +1,4 @@ -namespace Newsbot.Collector.Api.Domain.Requests; +namespace Newsbot.Collector.Domain.Requests; public class AddRoleRequest { diff --git a/Newsbot.Collector.Api/Domain/Requests/RegisterUserRequest.cs b/Newsbot.Collector.Domain/Requests/RegisterUserRequest.cs similarity index 81% rename from Newsbot.Collector.Api/Domain/Requests/RegisterUserRequest.cs rename to Newsbot.Collector.Domain/Requests/RegisterUserRequest.cs index 461615c..bde90c6 100644 --- a/Newsbot.Collector.Api/Domain/Requests/RegisterUserRequest.cs +++ b/Newsbot.Collector.Domain/Requests/RegisterUserRequest.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace Newsbot.Collector.Api.Domain.Requests; +namespace Newsbot.Collector.Domain.Requests; public class RegisterUserRequest { diff --git a/Newsbot.Collector.Api/Domain/Requests/UserLoginRequest.cs b/Newsbot.Collector.Domain/Requests/UserLoginRequest.cs similarity index 78% rename from Newsbot.Collector.Api/Domain/Requests/UserLoginRequest.cs rename to Newsbot.Collector.Domain/Requests/UserLoginRequest.cs index 8b34017..6386e4f 100644 --- a/Newsbot.Collector.Api/Domain/Requests/UserLoginRequest.cs +++ b/Newsbot.Collector.Domain/Requests/UserLoginRequest.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace Newsbot.Collector.Api.Domain.Requests; +namespace Newsbot.Collector.Domain.Requests; public class UserLoginRequest { diff --git a/Newsbot.Collector.Api/Domain/Requests/UserRefreshTokenRequest.cs b/Newsbot.Collector.Domain/Requests/UserRefreshTokenRequest.cs similarity index 71% rename from Newsbot.Collector.Api/Domain/Requests/UserRefreshTokenRequest.cs rename to Newsbot.Collector.Domain/Requests/UserRefreshTokenRequest.cs index 9556e49..9c20338 100644 --- a/Newsbot.Collector.Api/Domain/Requests/UserRefreshTokenRequest.cs +++ b/Newsbot.Collector.Domain/Requests/UserRefreshTokenRequest.cs @@ -1,4 +1,4 @@ -namespace Newsbot.Collector.Api.Domain.Requests; +namespace Newsbot.Collector.Domain.Requests; public class UserRefreshTokenRequest { diff --git a/Newsbot.Collector.Api/Domain/Response/AuthFailedResponse.cs b/Newsbot.Collector.Domain/Response/AuthFailedResponse.cs similarity index 64% rename from Newsbot.Collector.Api/Domain/Response/AuthFailedResponse.cs rename to Newsbot.Collector.Domain/Response/AuthFailedResponse.cs index 79ecf83..3c3e6f0 100644 --- a/Newsbot.Collector.Api/Domain/Response/AuthFailedResponse.cs +++ b/Newsbot.Collector.Domain/Response/AuthFailedResponse.cs @@ -1,4 +1,4 @@ -namespace Newsbot.Collector.Api.Domain.Response; +namespace Newsbot.Collector.Domain.Response; public class AuthFailedResponse { diff --git a/Newsbot.Collector.Api/Domain/Response/AuthSuccessfulResponse.cs b/Newsbot.Collector.Domain/Response/AuthSuccessfulResponse.cs similarity index 79% rename from Newsbot.Collector.Api/Domain/Response/AuthSuccessfulResponse.cs rename to Newsbot.Collector.Domain/Response/AuthSuccessfulResponse.cs index dcb42ef..ebdcf2a 100644 --- a/Newsbot.Collector.Api/Domain/Response/AuthSuccessfulResponse.cs +++ b/Newsbot.Collector.Domain/Response/AuthSuccessfulResponse.cs @@ -1,4 +1,4 @@ -namespace Newsbot.Collector.Api.Domain.Response; +namespace Newsbot.Collector.Domain.Response; public class AuthSuccessfulResponse { diff --git a/Newsbot.Collector.Domain/Results/ArticleDetailsResult.cs b/Newsbot.Collector.Domain/Results/ArticleDetailsResult.cs new file mode 100644 index 0000000..c97271f --- /dev/null +++ b/Newsbot.Collector.Domain/Results/ArticleDetailsResult.cs @@ -0,0 +1,8 @@ +using Newsbot.Collector.Domain.Dto; + +namespace Newsbot.Collector.Domain.Results; + +public class ArticleDetailsResult : BaseResult +{ + public ArticleDetailsDto? Item { get; set; } +} \ No newline at end of file diff --git a/Newsbot.Collector.Domain/Results/ArticleResult.cs b/Newsbot.Collector.Domain/Results/ArticleResult.cs new file mode 100644 index 0000000..0b5fb78 --- /dev/null +++ b/Newsbot.Collector.Domain/Results/ArticleResult.cs @@ -0,0 +1,8 @@ +using Newsbot.Collector.Domain.Dto; + +namespace Newsbot.Collector.Domain.Results; + +public class ArticleResult : BaseResult +{ + public IEnumerable? Items { get; set; } +} \ No newline at end of file diff --git a/Newsbot.Collector.Domain/Results/AuthenticationResult.cs b/Newsbot.Collector.Domain/Results/AuthenticationResult.cs new file mode 100644 index 0000000..127d4d5 --- /dev/null +++ b/Newsbot.Collector.Domain/Results/AuthenticationResult.cs @@ -0,0 +1,7 @@ +namespace Newsbot.Collector.Domain.Results; + +public class AuthenticationResult : BaseResult +{ + public string? Token { get; set; } + public string? RefreshToken { get; set; } +} \ No newline at end of file diff --git a/Newsbot.Collector.Domain/Results/BaseResult.cs b/Newsbot.Collector.Domain/Results/BaseResult.cs new file mode 100644 index 0000000..d9e22e1 --- /dev/null +++ b/Newsbot.Collector.Domain/Results/BaseResult.cs @@ -0,0 +1,7 @@ +namespace Newsbot.Collector.Domain.Results; + +public class BaseResult +{ + public bool IsSuccessful { get; set; } + public IEnumerable? ErrorMessage { get; set; } +} \ No newline at end of file diff --git a/Newsbot.Collector.Domain/Results/DiscordNotificationDetailsResult.cs b/Newsbot.Collector.Domain/Results/DiscordNotificationDetailsResult.cs new file mode 100644 index 0000000..0d8d40f --- /dev/null +++ b/Newsbot.Collector.Domain/Results/DiscordNotificationDetailsResult.cs @@ -0,0 +1,8 @@ +using Newsbot.Collector.Domain.Dto; + +namespace Newsbot.Collector.Domain.Results; + +public class DiscordNotificationDetailsResult : BaseResult +{ + public DiscordNotificationDetailsDto? Item { get; set; } +} \ No newline at end of file diff --git a/Newsbot.Collector.Domain/Results/DiscordNotificationResult.cs b/Newsbot.Collector.Domain/Results/DiscordNotificationResult.cs new file mode 100644 index 0000000..9cb27da --- /dev/null +++ b/Newsbot.Collector.Domain/Results/DiscordNotificationResult.cs @@ -0,0 +1,8 @@ +using Newsbot.Collector.Domain.Dto; + +namespace Newsbot.Collector.Domain.Results; + +public class DiscordNotificationResult : BaseResult +{ + public IEnumerable? Items { get; set; } +} \ No newline at end of file diff --git a/Newsbot.Collector.Domain/Results/DiscordWebhookResult.cs b/Newsbot.Collector.Domain/Results/DiscordWebhookResult.cs new file mode 100644 index 0000000..7173168 --- /dev/null +++ b/Newsbot.Collector.Domain/Results/DiscordWebhookResult.cs @@ -0,0 +1,8 @@ +using Newsbot.Collector.Domain.Dto; + +namespace Newsbot.Collector.Domain.Results; + +public class DiscordWebhookResult : BaseResult +{ + public List? Items { get; set; } +} \ No newline at end of file diff --git a/Newsbot.Collector.Api/Services/IdentityService.cs b/Newsbot.Collector.Services/IdentityService.cs similarity index 96% rename from Newsbot.Collector.Api/Services/IdentityService.cs rename to Newsbot.Collector.Services/IdentityService.cs index bd84b33..3d587de 100644 --- a/Newsbot.Collector.Api/Services/IdentityService.cs +++ b/Newsbot.Collector.Services/IdentityService.cs @@ -3,13 +3,13 @@ using System.Security.Claims; using System.Text; using Microsoft.AspNetCore.Identity; using Microsoft.IdentityModel.Tokens; -using Newsbot.Collector.Api.Domain.Results; -using Newsbot.Collector.Database; +using Newsbot.Collector.Domain.Results; using Newsbot.Collector.Domain.Entities; using Newsbot.Collector.Domain.Interfaces; using Newsbot.Collector.Domain.Models.Config; +using JwtRegisteredClaimNames = Microsoft.IdentityModel.JsonWebTokens.JwtRegisteredClaimNames; -namespace Newsbot.Collector.Api.Services; +namespace Newsbot.Collector.Services; public interface IIdentityService { @@ -60,7 +60,7 @@ public class IdentityService : IIdentityService { return new AuthenticationResult { - ErrorMessage = new[] { createdUser.Result.Errors.Select(x => x.Description).ToString() } + ErrorMessage = new List(createdUser.Result.Errors.Select(x => x.Description)) }; } diff --git a/Newsbot.Collector.Services/Newsbot.Collector.Services.csproj b/Newsbot.Collector.Services/Newsbot.Collector.Services.csproj index 132e6a8..3081955 100644 --- a/Newsbot.Collector.Services/Newsbot.Collector.Services.csproj +++ b/Newsbot.Collector.Services/Newsbot.Collector.Services.csproj @@ -11,11 +11,14 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + + + @@ -23,6 +26,8 @@ net7.0 enable enable + + true