|
|
@ -1,9 +1,16 @@ |
|
|
|
using Abp.Json; |
|
|
|
using Abp.AutoMapper; |
|
|
|
using Abp.Domain.Repositories; |
|
|
|
using Abp.Json; |
|
|
|
using BCS.BMC.BMC.CompanyMasters; |
|
|
|
using BCS.BMC.BMC.FirebaseCloudMessages; |
|
|
|
using BCS.BMC.Controllers; |
|
|
|
using BCS.BMC.FirebaseCloudMessaging; |
|
|
|
using BCS.BMC.FirebaseCloudMessaging.Dto; |
|
|
|
using BCS.BMC.Models.TokenAuth; |
|
|
|
using FirebaseAdmin.Messaging; |
|
|
|
using FireSharp.Config; |
|
|
|
using FireSharp.Interfaces; |
|
|
|
using FireSharp.Response; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using System.Collections.Generic; |
|
|
@ -16,10 +23,20 @@ namespace BCS.BMC.Web.Controllers |
|
|
|
public class NotificationController : BMCControllerBase |
|
|
|
{ |
|
|
|
private readonly IFirebaseNotificationAppService _notificationService; |
|
|
|
|
|
|
|
public NotificationController(IFirebaseNotificationAppService notificationService) |
|
|
|
private readonly IRepository<FirebaseCloudMessageDetails> _firebaseCloudMessageDetails; |
|
|
|
IFirebaseConfig config = new FirebaseConfig |
|
|
|
{ |
|
|
|
AuthSecret = "n6DTPQEbpnLahrrk2EYu4bJ2Wd3jCk2N8kocazdI", |
|
|
|
BasePath = "https://firechat-57601-default-rtdb.europe-west1.firebasedatabase.app/" |
|
|
|
}; |
|
|
|
IFirebaseClient client; |
|
|
|
public NotificationController(IFirebaseNotificationAppService notificationService, |
|
|
|
IRepository<FirebaseCloudMessageDetails> firebaseCloudMessageDetails) |
|
|
|
{ |
|
|
|
_notificationService = notificationService; |
|
|
|
_firebaseCloudMessageDetails = firebaseCloudMessageDetails; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -31,8 +48,24 @@ namespace BCS.BMC.Web.Controllers |
|
|
|
} |
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
public async Task<IActionResult> GetNotifications([FromBody] NotificationModel notification) |
|
|
|
public async Task<IActionResult> GetNotifications([FromBody]NotificationModel notification) |
|
|
|
{ |
|
|
|
client = new FireSharp.FirebaseClient(config); |
|
|
|
var data = notification; |
|
|
|
PushResponse response = client.Push("notification/", data); |
|
|
|
data.Id = response.Result.name; |
|
|
|
SetResponse setResponse = client.Set("notification/" + data.Id, data); |
|
|
|
if (setResponse.StatusCode == System.Net.HttpStatusCode.OK) |
|
|
|
{ |
|
|
|
ModelState.AddModelError(string.Empty, "Added Succesfully"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
ModelState.AddModelError(string.Empty, "Something went wrong!!"); |
|
|
|
} |
|
|
|
|
|
|
|
var entity = notification.MapTo<FirebaseCloudMessageDetails>(); |
|
|
|
await _firebaseCloudMessageDetails.InsertAndGetIdAsync(entity); |
|
|
|
// var result = _notificationService.GetNotification(notification);
|
|
|
|
return Ok(); |
|
|
|
} |
|
|
|