Moved controllers to v1 namespace and updated routes
This commit is contained in:
parent
5df2996947
commit
2bc99afe63
@ -1,18 +1,17 @@
|
|||||||
using System.Net;
|
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Newsbot.Collector.Database.Repositories;
|
using Newsbot.Collector.Api.Middleware;
|
||||||
using Newsbot.Collector.Domain.Dto;
|
using Newsbot.Collector.Domain.Dto;
|
||||||
using Newsbot.Collector.Domain.Entities;
|
using Newsbot.Collector.Domain.Entities;
|
||||||
using Newsbot.Collector.Domain.Interfaces;
|
using Newsbot.Collector.Domain.Interfaces;
|
||||||
using Newsbot.Collector.Domain.Models;
|
using Newsbot.Collector.Domain.Models;
|
||||||
|
|
||||||
namespace Newsbot.Collector.Api.Controllers;
|
namespace Newsbot.Collector.Api.Controllers.v1;
|
||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/discord/webhooks")]
|
[Route("api/v1/discord/webhooks")]
|
||||||
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
||||||
public class DiscordWebHookController : ControllerBase
|
public class DiscordWebHookController : ControllerBase
|
||||||
{
|
{
|
||||||
@ -26,22 +25,29 @@ public class DiscordWebHookController : ControllerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet(Name = "GetDiscordWebhooks")]
|
[HttpGet(Name = "GetDiscordWebhooks")]
|
||||||
public IEnumerable<DiscordWebHookDto> Get(int page)
|
public ActionResult<IEnumerable<DiscordWebHookDto>> 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<DiscordWebHookDto>();
|
var items = new List<DiscordWebHookDto>();
|
||||||
var res = _webhooks.List(page);
|
var res = _webhooks.ListByUserId(userId, page);
|
||||||
foreach (var item in res)
|
foreach (var item in res)
|
||||||
{
|
{
|
||||||
items.Add(DiscordWebHookDto.Convert(item));
|
items.Add(DiscordWebHookDto.Convert(item));
|
||||||
}
|
}
|
||||||
return items;
|
|
||||||
|
return new OkObjectResult(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost(Name = "New")]
|
[HttpPost(Name = "New")]
|
||||||
public DiscordWebHookDto New(string url, string server, string channel)
|
public DiscordWebHookDto New(string url, string server, string channel)
|
||||||
{
|
{
|
||||||
var exists = _webhooks.GetByUrl(url);
|
var exists = _webhooks.GetByUrl(url);
|
||||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
|
|
||||||
if (exists.Id != Guid.Empty)
|
if (exists.Id != Guid.Empty)
|
||||||
{
|
{
|
||||||
return DiscordWebHookDto.Convert(exists);
|
return DiscordWebHookDto.Convert(exists);
|
@ -8,10 +8,10 @@ using Newsbot.Collector.Domain.Models.Config;
|
|||||||
using Newsbot.Collector.Domain.Models.Config.Sources;
|
using Newsbot.Collector.Domain.Models.Config.Sources;
|
||||||
using Newsbot.Collector.Services.Jobs;
|
using Newsbot.Collector.Services.Jobs;
|
||||||
|
|
||||||
namespace Newsbot.Collector.Api.Controllers;
|
namespace Newsbot.Collector.Api.Controllers.v1;
|
||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/rss")]
|
[Route("api/v1/rss")]
|
||||||
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
||||||
public class RssController
|
public class RssController
|
||||||
{
|
{
|
@ -9,10 +9,10 @@ using Newsbot.Collector.Domain.Models.Config.Sources;
|
|||||||
using Newsbot.Collector.Services.Jobs;
|
using Newsbot.Collector.Services.Jobs;
|
||||||
using ILogger = Grpc.Core.Logging.ILogger;
|
using ILogger = Grpc.Core.Logging.ILogger;
|
||||||
|
|
||||||
namespace Newsbot.Collector.Api.Controllers;
|
namespace Newsbot.Collector.Api.Controllers.v1;
|
||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/youtube")]
|
[Route("api/v1/youtube")]
|
||||||
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
||||||
public class YoutubeController
|
public class YoutubeController
|
||||||
{
|
{
|
Loading…
Reference in New Issue
Block a user