2023-07-14 22:25:44 -07:00
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2023-07-09 22:10:51 -07:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Newsbot.Collector.Api.Authentication;
|
2023-07-23 22:55:20 -07:00
|
|
|
using Newsbot.Collector.Api.Middleware;
|
2023-07-09 22:10:51 -07:00
|
|
|
using Newsbot.Collector.Domain.Entities;
|
|
|
|
using Newsbot.Collector.Domain.Interfaces;
|
|
|
|
|
2023-07-14 22:25:44 -07:00
|
|
|
namespace Newsbot.Collector.Api.Controllers.v1;
|
2023-07-09 22:10:51 -07:00
|
|
|
|
2023-07-14 22:25:44 -07:00
|
|
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
2023-07-09 22:10:51 -07:00
|
|
|
[ApiController]
|
|
|
|
[Route("api/v1/user")]
|
|
|
|
public class UserController : Controller
|
|
|
|
{
|
2023-07-14 22:25:44 -07:00
|
|
|
private readonly ILogger<UserController> _logger;
|
|
|
|
private readonly IUserSourceSubscription _subscription;
|
2023-07-09 22:10:51 -07:00
|
|
|
|
|
|
|
public UserController(ILogger<UserController> logger, IUserSourceSubscription subscription)
|
|
|
|
{
|
|
|
|
_logger = logger;
|
|
|
|
_subscription = subscription;
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost("listSubscriptions")]
|
|
|
|
public ActionResult ListSubscriptions()
|
|
|
|
{
|
|
|
|
_logger.LogInformation("'/api/v1/user/listSubscriptions' was requested");
|
|
|
|
|
|
|
|
var userId = HttpContext.GetUserId();
|
|
|
|
if (userId.Equals(string.Empty))
|
|
|
|
{
|
|
|
|
_logger.LogWarning("Unable to find the user ID in the JWD Token");
|
|
|
|
return new BadRequestResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var results = _subscription.ListUserSubscriptions(Guid.Parse(userId));
|
|
|
|
return new OkObjectResult(results);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
_logger.LogError(ex, "Failed to pull subscriptions for userId \'{UserId}\'", userId);
|
|
|
|
return new NoContentResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|