From 2bc99afe6360d0a6adeaff2143829fedfa73face Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Sun, 23 Jul 2023 22:54:00 -0700 Subject: [PATCH] Moved controllers to v1 namespace and updated routes --- .../{ => v1}/DiscordWebHooksController.cs | 22 ++++++++++++------- .../Controllers/{ => v1}/RssController.cs | 4 ++-- .../Controllers/{ => v1}/SourcesController.cs | 0 .../Controllers/{ => v1}/YoutubeController.cs | 4 ++-- 4 files changed, 18 insertions(+), 12 deletions(-) rename Newsbot.Collector.Api/Controllers/{ => v1}/DiscordWebHooksController.cs (81%) rename Newsbot.Collector.Api/Controllers/{ => v1}/RssController.cs (95%) rename Newsbot.Collector.Api/Controllers/{ => v1}/SourcesController.cs (100%) rename Newsbot.Collector.Api/Controllers/{ => v1}/YoutubeController.cs (95%) diff --git a/Newsbot.Collector.Api/Controllers/DiscordWebHooksController.cs b/Newsbot.Collector.Api/Controllers/v1/DiscordWebHooksController.cs similarity index 81% rename from Newsbot.Collector.Api/Controllers/DiscordWebHooksController.cs rename to Newsbot.Collector.Api/Controllers/v1/DiscordWebHooksController.cs index b33806d..a0d745d 100644 --- a/Newsbot.Collector.Api/Controllers/DiscordWebHooksController.cs +++ b/Newsbot.Collector.Api/Controllers/v1/DiscordWebHooksController.cs @@ -1,18 +1,17 @@ -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; -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,22 +25,29 @@ 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) { var exists = _webhooks.GetByUrl(url); - // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract if (exists.Id != Guid.Empty) { return DiscordWebHookDto.Convert(exists); 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/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 {