using GB5Shared.DTO.PushNotification; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using Microsoft.AspNetCore.Mvc; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Controllers.PushNotification { [ApiController] [Route("[controller]")] public class PushNotificationService : ControllerBase { private readonly GB5Shared.PushNotification.IPushNotificationBLL _PushNotificationBLL; public PushNotificationService(GB5Shared.PushNotification.IPushNotificationBLL PushNotificationBLL) { _PushNotificationBLL = PushNotificationBLL; } [HttpPost("SubscribeUserToTopic")] public async Task> SubscribeUserToTopic(string Token, string Topic) { //var LoginDTO = Newtonsoft.Json.JsonConvert.DeserializeObject(loginDtoJson); try { var result = await _PushNotificationBLL.SubscribeUserToTopic(Token, Topic!); if (result == null || !result.Any()) { return await GB5Shared.ResponseStandard.Response.CreateEmptyResponse(CacheKeyLevel.NOT_REQUIRED, "Subscription failed", 404); } return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.NOT_REQUIRED, null!); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, null!, ex.Message, 500); } } [HttpPost("SendNotificationToTopic")] public async Task> SendNotificationToTopic(PushNotificationDTO PushNotificationDTO, [FromHeader(Name = "LoginDTO")] string loginDtoJson) { var LoginDTO = Newtonsoft.Json.JsonConvert.DeserializeObject(loginDtoJson); try { var result = await _PushNotificationBLL.SendNotificationToTopic(PushNotificationDTO); if (result == null || !result.Any()) { return await GB5Shared.ResponseStandard.Response.CreateEmptyResponse( CacheKeyLevel.NOT_REQUIRED,"PushNotification failed", 404 ); } return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.NOT_REQUIRED, LoginDTO!); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, LoginDTO!,ex.Message, 500); } } } }