diff --git a/Marco.Pms.Services/Controllers/AuthController.cs b/Marco.Pms.Services/Controllers/AuthController.cs index a222f38..9d9c864 100644 --- a/Marco.Pms.Services/Controllers/AuthController.cs +++ b/Marco.Pms.Services/Controllers/AuthController.cs @@ -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.SuccessResponse(responseData, "User logged in successfully.", 200)); diff --git a/Marco.Pms.Services/Service/FirebaseService.cs b/Marco.Pms.Services/Service/FirebaseService.cs index 43b7255..4fa531d 100644 --- a/Marco.Pms.Services/Service/FirebaseService.cs +++ b/Marco.Pms.Services/Service/FirebaseService.cs @@ -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) diff --git a/Marco.Pms.Services/Service/ServiceInterfaces/IFirebaseService.cs b/Marco.Pms.Services/Service/ServiceInterfaces/IFirebaseService.cs index 66d8532..6b7d151 100644 --- a/Marco.Pms.Services/Service/ServiceInterfaces/IFirebaseService.cs +++ b/Marco.Pms.Services/Service/ServiceInterfaces/IFirebaseService.cs @@ -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); } }