From c38e4e6599cc697a9d0d6d6accf8697f39f335fd Mon Sep 17 00:00:00 2001 From: Palash Biswas Date: Thu, 1 Dec 2022 16:52:39 +0530 Subject: [PATCH] BMC: Add GetNotification Method --- .../Dto/NotificationModel.cs | 10 +++---- .../FirebaseNotificationAppService.cs | 26 ++++++++++++------- .../IFirebaseNotificationAppService.cs | 4 ++- .../FirebaseNotificationController.cs | 20 +++++++++----- 4 files changed, 37 insertions(+), 23 deletions(-) diff --git a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs index cada993..e149d2d 100644 --- a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs +++ b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs @@ -9,11 +9,11 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto { public class NotificationModel { - [JsonProperty("deviceId")] - public string DeviceId { get; set; } - [JsonProperty("isAndroidDevice")] - public bool IsAndroidDevice { get; set; } - [JsonProperty("title")] + //[JsonProperty("deviceId")] + //public string DeviceId { get; set; } + //[JsonProperty("isAndroidDevice")] + //public bool IsAndroidDevice { get; set; } + //[JsonProperty("title")] public string Title { get; set; } [JsonProperty("body")] public string Body { 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 29b3bfc..ae777fa 100644 --- a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/FirebaseNotificationAppService.cs +++ b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/FirebaseNotificationAppService.cs @@ -6,13 +6,15 @@ using System; using BCS.BMC.FirebaseCloudMessaging.Dto; using System.Collections.Generic; using Abp.Json; +using Microsoft.Extensions.Logging; namespace BCS.BMC.FirebaseCloudMessaging { public class FirebaseNotificationAppService : IFirebaseNotificationAppService { + private readonly ILogger _logger; - public FirebaseNotificationAppService() + public FirebaseNotificationAppService(ILogger logger) { if (FirebaseApp.DefaultInstance is null) { @@ -21,27 +23,31 @@ namespace BCS.BMC.FirebaseCloudMessaging Credential = GoogleCredential.FromFile("firechat-57601-firebase-adminsdk-anscp-e04366c4d4.json") }); } + _logger = logger; } - public static async Task SendNotification( FireBaseResponseModel notification) + public async Task SendNotification(FireBaseResponseModel notification) { try { - - var message = new MulticastMessage() - { - Notification = notification.notification, - Tokens = notification.FcmToken, - }; + var message = new MulticastMessage() + { + Notification = notification.notification, + Tokens = notification.FcmToken, + }; var response = await FirebaseMessaging.DefaultInstance.SendMulticastAsync(message); return response; } - catch(Exception ex) + catch (Exception ex) { throw ex; } - } + } + public async Task GetNotification(NotificationModel notification) + { + _logger.LogInformation("Bwac Notifications" + notification); + } } } diff --git a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/IFirebaseNotificationAppService.cs b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/IFirebaseNotificationAppService.cs index 24716f9..154bb8e 100644 --- a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/IFirebaseNotificationAppService.cs +++ b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/IFirebaseNotificationAppService.cs @@ -1,4 +1,5 @@ using Abp.Application.Services; +using BCS.BMC.FirebaseCloudMessaging.Dto; using FirebaseAdmin.Messaging; using System.Threading.Tasks; @@ -6,6 +7,7 @@ namespace BCS.BMC.FirebaseCloudMessaging { public interface IFirebaseNotificationAppService : IApplicationService { - // Task SendNotification(string fcmToken, Notification notification); + Task SendNotification(FireBaseResponseModel notification); + Task GetNotification(NotificationModel notification); } } diff --git a/BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/FirebaseNotificationController.cs b/BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/FirebaseNotificationController.cs index c4afdd5..5d0ede8 100644 --- a/BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/FirebaseNotificationController.cs +++ b/BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/FirebaseNotificationController.cs @@ -12,23 +12,29 @@ using System.Threading.Tasks; namespace BCS.BMC.Web.Controllers { - [Route("api/[controller]/SendNotification")] + [Route("api/[controller]/[action]")] public class FirebaseNotificationController : BMCControllerBase { - private readonly FirebaseNotificationAppService _notificationService; + private readonly IFirebaseNotificationAppService _notificationService; - public FirebaseNotificationController(FirebaseNotificationAppService notificationService) + public FirebaseNotificationController(IFirebaseNotificationAppService notificationService) { _notificationService = notificationService; } - //[Route("SendNotification")] + [HttpPost] - public async Task Notification( [FromBody] FireBaseResponseModel notification) + public async Task SendNotification([FromBody] FireBaseResponseModel notification) { - var result = await FirebaseNotificationAppService.SendNotification(notification); - // FcmTokenResponseModel results = JsonConvert.DeserializeObject(result).ToJsonString(); + var result = await _notificationService.SendNotification(notification); return Ok(result.Responses); } + + [HttpPost] + public async Task GetNotifications(NotificationModel notification) + { + var result = _notificationService.GetNotification(notification); + return Ok(); + } } }