BMC: Add GetNotification Method

This commit is contained in:
Palash Biswas 2022-12-01 16:52:39 +05:30
parent 9938bbabc7
commit c38e4e6599
4 changed files with 37 additions and 23 deletions

View File

@ -9,11 +9,11 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto
{ {
public class NotificationModel public class NotificationModel
{ {
[JsonProperty("deviceId")] //[JsonProperty("deviceId")]
public string DeviceId { get; set; } //public string DeviceId { get; set; }
[JsonProperty("isAndroidDevice")] //[JsonProperty("isAndroidDevice")]
public bool IsAndroidDevice { get; set; } //public bool IsAndroidDevice { get; set; }
[JsonProperty("title")] //[JsonProperty("title")]
public string Title { get; set; } public string Title { get; set; }
[JsonProperty("body")] [JsonProperty("body")]
public string Body { get; set; } public string Body { get; set; }

View File

@ -6,13 +6,15 @@ using System;
using BCS.BMC.FirebaseCloudMessaging.Dto; using BCS.BMC.FirebaseCloudMessaging.Dto;
using System.Collections.Generic; using System.Collections.Generic;
using Abp.Json; using Abp.Json;
using Microsoft.Extensions.Logging;
namespace BCS.BMC.FirebaseCloudMessaging namespace BCS.BMC.FirebaseCloudMessaging
{ {
public class FirebaseNotificationAppService : IFirebaseNotificationAppService public class FirebaseNotificationAppService : IFirebaseNotificationAppService
{ {
private readonly ILogger _logger;
public FirebaseNotificationAppService() public FirebaseNotificationAppService(ILogger logger)
{ {
if (FirebaseApp.DefaultInstance is null) if (FirebaseApp.DefaultInstance is null)
{ {
@ -21,14 +23,14 @@ namespace BCS.BMC.FirebaseCloudMessaging
Credential = GoogleCredential.FromFile("firechat-57601-firebase-adminsdk-anscp-e04366c4d4.json") Credential = GoogleCredential.FromFile("firechat-57601-firebase-adminsdk-anscp-e04366c4d4.json")
}); });
} }
_logger = logger;
} }
public static async Task<BatchResponse> SendNotification( FireBaseResponseModel notification) public async Task<BatchResponse> SendNotification(FireBaseResponseModel notification)
{ {
try try
{ {
var message = new MulticastMessage() var message = new MulticastMessage()
{ {
Notification = notification.notification, Notification = notification.notification,
@ -38,10 +40,14 @@ namespace BCS.BMC.FirebaseCloudMessaging
var response = await FirebaseMessaging.DefaultInstance.SendMulticastAsync(message); var response = await FirebaseMessaging.DefaultInstance.SendMulticastAsync(message);
return response; return response;
} }
catch(Exception ex) catch (Exception ex)
{ {
throw ex; throw ex;
} }
} }
public async Task GetNotification(NotificationModel notification)
{
_logger.LogInformation("Bwac Notifications" + notification);
}
} }
} }

View File

@ -1,4 +1,5 @@
using Abp.Application.Services; using Abp.Application.Services;
using BCS.BMC.FirebaseCloudMessaging.Dto;
using FirebaseAdmin.Messaging; using FirebaseAdmin.Messaging;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -6,6 +7,7 @@ namespace BCS.BMC.FirebaseCloudMessaging
{ {
public interface IFirebaseNotificationAppService : IApplicationService public interface IFirebaseNotificationAppService : IApplicationService
{ {
// Task<string> SendNotification(string fcmToken, Notification notification); Task<BatchResponse> SendNotification(FireBaseResponseModel notification);
Task GetNotification(NotificationModel notification);
} }
} }

View File

@ -12,23 +12,29 @@ using System.Threading.Tasks;
namespace BCS.BMC.Web.Controllers namespace BCS.BMC.Web.Controllers
{ {
[Route("api/[controller]/SendNotification")] [Route("api/[controller]/[action]")]
public class FirebaseNotificationController : BMCControllerBase public class FirebaseNotificationController : BMCControllerBase
{ {
private readonly FirebaseNotificationAppService _notificationService; private readonly IFirebaseNotificationAppService _notificationService;
public FirebaseNotificationController(FirebaseNotificationAppService notificationService) public FirebaseNotificationController(IFirebaseNotificationAppService notificationService)
{ {
_notificationService = notificationService; _notificationService = notificationService;
} }
//[Route("SendNotification")]
[HttpPost] [HttpPost]
public async Task<IActionResult> Notification( [FromBody] FireBaseResponseModel notification) public async Task<IActionResult> SendNotification([FromBody] FireBaseResponseModel notification)
{ {
var result = await FirebaseNotificationAppService.SendNotification(notification); var result = await _notificationService.SendNotification(notification);
// FcmTokenResponseModel results = JsonConvert.DeserializeObject<FcmTokenResponseModel>(result).ToJsonString();
return Ok(result.Responses); return Ok(result.Responses);
} }
[HttpPost]
public async Task<IActionResult> GetNotifications(NotificationModel notification)
{
var result = _notificationService.GetNotification(notification);
return Ok();
}
} }
} }