From 6e0884b93504e1c1cf63c9eb56bfe95dbc1c3093 Mon Sep 17 00:00:00 2001 From: Palash Biswas Date: Fri, 13 Jan 2023 16:09:49 +0530 Subject: [PATCH] Bmc: Validation message for Login and Registration --- .../Dto/FirebaseResponseModel.cs | 5 +++++ .../FirebaseNotificationAppService.cs | 21 ++++++++++++++++++- .../IFirebaseNotificationAppService.cs | 3 ++- .../Controllers/TokenAuthController.cs | 2 +- .../Models/TokenAuth/ResponseMessageModel.cs | 1 - .../Controllers/NotificationController.cs | 16 ++++++++------ 6 files changed, 38 insertions(+), 10 deletions(-) diff --git a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FirebaseResponseModel.cs b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FirebaseResponseModel.cs index b790d2e..737fae5 100755 --- a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FirebaseResponseModel.cs +++ b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FirebaseResponseModel.cs @@ -15,4 +15,9 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto public BmcMessageStatusInput getResponseData { get; set; } } + public class FireBaseResponseModelForBmc + { + public Notification notification { get; set; } + public List FcmToken { get; set; } + } } diff --git a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/FirebaseNotificationAppService.cs b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/FirebaseNotificationAppService.cs index 20a6b56..8ab4169 100644 --- a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/FirebaseNotificationAppService.cs +++ b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/FirebaseNotificationAppService.cs @@ -25,7 +25,26 @@ namespace BCS.BMC.FirebaseCloudMessaging } - public async Task SendNotification(FireBaseResponseModel notification) + public async Task SendNotification(FireBaseResponseModelForBmc notification) + { + try + { + var message = new MulticastMessage() + { + Notification = notification.notification, + Tokens = notification.FcmToken, + }; + + var response = await FirebaseMessaging.DefaultInstance.SendMulticastAsync(message); + return response; + } + catch (Exception ex) + { + throw ex; + } + } + + public async Task SendNotificationBwac(FireBaseResponseModel notification) { try { diff --git a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/IFirebaseNotificationAppService.cs b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/IFirebaseNotificationAppService.cs index 154bb8e..1e8b124 100644 --- a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/IFirebaseNotificationAppService.cs +++ b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/IFirebaseNotificationAppService.cs @@ -7,7 +7,8 @@ namespace BCS.BMC.FirebaseCloudMessaging { public interface IFirebaseNotificationAppService : IApplicationService { - Task SendNotification(FireBaseResponseModel notification); + Task SendNotification(FireBaseResponseModelForBmc notification); Task GetNotification(NotificationModel notification); + Task SendNotificationBwac(FireBaseResponseModel notification); } } diff --git a/BCS.BMC/src/BCS.BMC.Web.Core/Controllers/TokenAuthController.cs b/BCS.BMC/src/BCS.BMC.Web.Core/Controllers/TokenAuthController.cs index f09d849..d2a4c5b 100644 --- a/BCS.BMC/src/BCS.BMC.Web.Core/Controllers/TokenAuthController.cs +++ b/BCS.BMC/src/BCS.BMC.Web.Core/Controllers/TokenAuthController.cs @@ -405,7 +405,7 @@ namespace BCS.BMC.Controllers { var contents = await response.Content.ReadAsStringAsync(); ResponseMessageModel result = JsonConvert.DeserializeObject(contents); - return BadRequest(result); + return BadRequest(result.error.message.ToString()); } } return BadRequest(); diff --git a/BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/ResponseMessageModel.cs b/BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/ResponseMessageModel.cs index 87b7488..b049886 100644 --- a/BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/ResponseMessageModel.cs +++ b/BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/ResponseMessageModel.cs @@ -14,6 +14,5 @@ namespace BCS.BMC.Models.TokenAuth public class Error { public string message { get; set; } - } } diff --git a/BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/NotificationController.cs b/BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/NotificationController.cs index 3f6b1d4..f9cd9eb 100644 --- a/BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/NotificationController.cs +++ b/BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/NotificationController.cs @@ -24,6 +24,7 @@ using Abp.EntityFrameworkCore.Repositories; using System.Security.Cryptography; using Abp.Domain.Uow; using Google.Type; +using Microsoft.AspNetCore.Http; namespace BCS.BMC.Web.Controllers { @@ -58,12 +59,18 @@ namespace BCS.BMC.Web.Controllers [HttpPost] - public async Task SendNotification([FromBody] List notifications) + public async Task SendNotification([FromBody] FireBaseResponseModelForBmc notification) + { + var result = await _notificationService.SendNotification(notification); + return result.Responses[0]; + } + + public async Task SendNotificationForBwac([FromBody] List notifications) { List bmcMessageStatusInputs = new List(); foreach (var notification in notifications) { - var result = await _notificationService.SendNotification(notification); + var result = await _notificationService.SendNotificationBwac(notification); if (result.SuccessCount > 0) { @@ -72,8 +79,6 @@ namespace BCS.BMC.Web.Controllers notification.getResponseData.IsSuccess = true; notification.getResponseData.Status = "Delivered"; } - - // return Ok(result); } if (result.FailureCount > 0) { @@ -83,7 +88,6 @@ namespace BCS.BMC.Web.Controllers notification.getResponseData.Status = result.Responses[0].Exception.Message; } //await UpdateBmcMessageStatus(notification.getResponseData); - return BadRequest(result.Responses); } bmcMessageStatusInputs.Add(notification.getResponseData); } @@ -189,7 +193,7 @@ namespace BCS.BMC.Web.Controllers } await uow.CompleteAsync(); } - await SendNotification(sendNotificationInfoList); + await SendNotificationForBwac(sendNotificationInfoList); } catch (Exception ex) {