Firebase_Implementation #135
@ -1,5 +1,4 @@
|
||||
using FirebaseAdmin.Messaging;
|
||||
using Marco.Pms.DataAccess.Data;
|
||||
using Marco.Pms.DataAccess.Data;
|
||||
using Marco.Pms.Model.Authentication;
|
||||
using Marco.Pms.Model.Dtos.Authentication;
|
||||
using Marco.Pms.Model.Dtos.Util;
|
||||
@ -257,14 +256,8 @@ namespace MarcoBMS.Services.Controllers
|
||||
// --- Push Notification Section ---
|
||||
// This section attempts to send a test push notification to the user's device.
|
||||
// It's designed to fail gracefully and handle invalid Firebase Cloud Messaging (FCM) tokens.
|
||||
|
||||
var notification = new Notification
|
||||
{
|
||||
Title = "Testing from API",
|
||||
Body = "This messages comes from FireBase Services"
|
||||
};
|
||||
|
||||
await _firebase.SendLoginMessageAsync(notification);
|
||||
var name = $"{emp.FirstName} {emp.LastName}";
|
||||
await _firebase.SendLoginMessageAsync(name);
|
||||
|
||||
});
|
||||
return Ok(ApiResponse<object>.SuccessResponse(responseData, "User logged in successfully.", 200));
|
||||
|
@ -19,24 +19,19 @@ namespace Marco.Pms.Services.Service
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
public async Task SendDemoMessages(Notification notificationFirebase)
|
||||
{
|
||||
string deviceToken = "";
|
||||
var message = new Message()
|
||||
{
|
||||
Token = deviceToken,
|
||||
Notification = notificationFirebase
|
||||
};
|
||||
string response = await FirebaseMessaging.DefaultInstance.SendAsync(message);
|
||||
}
|
||||
|
||||
public async Task SendLoginMessageAsync(Notification notificationFirebase)
|
||||
public async Task SendLoginMessageAsync(string name)
|
||||
{
|
||||
await using var _context = await _dbContextFactory.CreateDbContextAsync();
|
||||
|
||||
// List of device registration tokens to send the message to
|
||||
var registrationTokens = await _context.FCMTokenMappings.Select(ft => ft.FcmToken).ToListAsync();
|
||||
|
||||
var notificationFirebase = new Notification
|
||||
{
|
||||
Title = "Login Alert",
|
||||
Body = $"{name} has successfully logged in to the application"
|
||||
};
|
||||
|
||||
await SendMessageToMultipleDevicesAsync(registrationTokens, notificationFirebase);
|
||||
}
|
||||
public async Task SendAttendanceMessageAsync(Guid projectId, string Name, ATTENDANCE_MARK_TYPE markType, Guid tenantId)
|
||||
|
@ -1,11 +1,10 @@
|
||||
using FirebaseAdmin.Messaging;
|
||||
using Marco.Pms.Model.Dtos.Attendance;
|
||||
using Marco.Pms.Model.Dtos.Attendance;
|
||||
|
||||
namespace Marco.Pms.Services.Service.ServiceInterfaces
|
||||
{
|
||||
public interface IFirebaseService
|
||||
{
|
||||
Task SendLoginMessageAsync(Notification notificationFirebase);
|
||||
Task SendLoginMessageAsync(string name);
|
||||
Task SendAttendanceMessageAsync(Guid projectId, string Name, ATTENDANCE_MARK_TYPE markType, Guid tenantId);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user