Browse Source

BMC: Add GetNotification Method

feature/ModificationForSentNotificationAPI
Palash Biswas 2 years ago
parent
commit
c38e4e6599
4 changed files with 37 additions and 23 deletions
  1. +5
    -5
      BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs
  2. +16
    -10
      BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/FirebaseNotificationAppService.cs
  3. +3
    -1
      BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/IFirebaseNotificationAppService.cs
  4. +13
    -7
      BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/FirebaseNotificationController.cs

+ 5
- 5
BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs View File

@ -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; }


+ 16
- 10
BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/FirebaseNotificationAppService.cs View File

@ -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<BatchResponse> SendNotification( FireBaseResponseModel notification)
public async Task<BatchResponse> 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);
}
}
}

+ 3
- 1
BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/IFirebaseNotificationAppService.cs View File

@ -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<string> SendNotification(string fcmToken, Notification notification);
Task<BatchResponse> SendNotification(FireBaseResponseModel notification);
Task GetNotification(NotificationModel notification);
}
}

+ 13
- 7
BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/FirebaseNotificationController.cs View File

@ -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<IActionResult> Notification( [FromBody] FireBaseResponseModel notification)
public async Task<IActionResult> SendNotification([FromBody] FireBaseResponseModel notification)
{
var result = await FirebaseNotificationAppService.SendNotification(notification);
// FcmTokenResponseModel results = JsonConvert.DeserializeObject<FcmTokenResponseModel>(result).ToJsonString();
var result = await _notificationService.SendNotification(notification);
return Ok(result.Responses);
}
[HttpPost]
public async Task<IActionResult> GetNotifications(NotificationModel notification)
{
var result = _notificationService.GetNotification(notification);
return Ok();
}
}
}

Loading…
Cancel
Save