45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
|
using Microsoft.AspNetCore.Mvc;
|
||
|
using Newsbot.Collector.Api.Authentication;
|
||
|
using Newsbot.Collector.Domain.Entities;
|
||
|
using Newsbot.Collector.Domain.Interfaces;
|
||
|
|
||
|
namespace Newsbot.Collector.Api.Controllers;
|
||
|
|
||
|
[ApiController]
|
||
|
[Route("api/v1/user")]
|
||
|
public class UserController : Controller
|
||
|
{
|
||
|
private ILogger<UserController> _logger;
|
||
|
private IUserSourceSubscription _subscription;
|
||
|
|
||
|
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();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|