using Dapr; using Dapr.Client; using GB5Shared.DTO.Framework.Logging; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using System; using System.Net.Http; using System.Text.Json; using System.Threading.Tasks; using static Dapr.Client.Autogen.Grpc.v1.Dapr; using static GB5Shared.GB5Constant.Constant; namespace AdminSL.Controllers.UserService { [ApiController] [Route("[controller]")] public class User : ControllerBase { private readonly Dapr.Client.DaprClient _daprClient; private readonly ILogger _logger; public User(Dapr.Client.DaprClient daprClient, ILogger logger) { _daprClient = daprClient; _logger = logger; } [HttpGet("GetUserData")] public async Task> GetUserData(int UserId , LoginDTO LoginDTO) { try { var daprClient = new DaprClientBuilder().Build(); var response = await daprClient.InvokeMethodAsync( HttpMethod.Get, "gb5framework", $"UserService/GetUserId?UserId={UserId}", LoginDTO ); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(response, CacheKeyLevel.NOT_REQUIRED, LoginDTO); } catch (InvocationException ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.NOT_REQUIRED, LoginDTO, $"Dapr Invocation Error: {ex.Message}", 500 ); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.NOT_REQUIRED, LoginDTO, $"Internal Server Error: {ex.Message}", 500 ); } } [HttpPost("PostPubSub")] [Topic("pubsub-redis", "GB5Framework")] public void HandleMessage(string message) { _logger.LogDebug("UserService received message: {MessageLength} chars", message?.Length ?? 0); } } }