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; namespace Newsbot.Collector.Api.Controllers.v1; [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] [ApiController] [Route("api/v1/user")] public class UserController : Controller { private readonly ILogger _logger; private readonly IUserSourceSubscription _subscription; public UserController(ILogger 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(); } } }