Added proper logs in firebase service
This commit is contained in:
parent
9a9876b7ca
commit
990b928a63
@ -4,6 +4,12 @@
|
||||
{
|
||||
public required string Username { get; set; }
|
||||
public required string Password { get; set; }
|
||||
public string? FcmToken { get; set; }
|
||||
}
|
||||
|
||||
public class MobileLoginDto
|
||||
{
|
||||
public required string Username { get; set; }
|
||||
public required string Password { get; set; }
|
||||
public required string FcmToken { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
/// <returns>An IActionResult containing the authentication tokens or an error response.</returns>
|
||||
|
||||
[HttpPost("login-mobile")]
|
||||
public async Task<IActionResult> LoginMobile([FromBody] LoginDto loginDto)
|
||||
public async Task<IActionResult> LoginMobile([FromBody] MobileLoginDto loginDto)
|
||||
{
|
||||
// Log the start of the login attempt for traceability.
|
||||
_logger.LogInfo("Login attempt initiated for user: {Username}", loginDto.Username ?? "N/A");
|
||||
|
@ -11,12 +11,12 @@ namespace Marco.Pms.Services.Service
|
||||
public class FirebaseService : IFirebaseService
|
||||
{
|
||||
private readonly IDbContextFactory<ApplicationDbContext> _dbContextFactory;
|
||||
private readonly ILoggingService _logger;
|
||||
private readonly IServiceScopeFactory _serviceScopeFactory;
|
||||
public FirebaseService(IDbContextFactory<ApplicationDbContext> dbContextFactory,
|
||||
ILoggingService logger)
|
||||
IServiceScopeFactory serviceScopeFactory)
|
||||
{
|
||||
_dbContextFactory = dbContextFactory ?? throw new ArgumentNullException(nameof(dbContextFactory));
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
_serviceScopeFactory = serviceScopeFactory ?? throw new ArgumentNullException(nameof(serviceScopeFactory));
|
||||
}
|
||||
|
||||
public async Task SendLoginMessageAsync(string name)
|
||||
@ -37,7 +37,6 @@ namespace Marco.Pms.Services.Service
|
||||
public async Task SendAttendanceMessageAsync(Guid projectId, string Name, ATTENDANCE_MARK_TYPE markType, Guid tenantId)
|
||||
{
|
||||
await using var _context = await _dbContextFactory.CreateDbContextAsync();
|
||||
|
||||
var projectTask = Task.Run(async () =>
|
||||
{
|
||||
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||
@ -143,7 +142,8 @@ namespace Marco.Pms.Services.Service
|
||||
}
|
||||
public async Task SendMessageToMultipleDevicesWithDataAsync(List<string> registrationTokens, Notification notificationFirebase, Dictionary<string, string> data)
|
||||
{
|
||||
|
||||
using var scope = _serviceScopeFactory.CreateScope();
|
||||
var _logger = scope.ServiceProvider.GetRequiredService<ILoggingService>();
|
||||
try
|
||||
{
|
||||
var message = new MulticastMessage()
|
||||
@ -154,6 +154,7 @@ namespace Marco.Pms.Services.Service
|
||||
};
|
||||
// Send the multicast message
|
||||
var response = await FirebaseMessaging.DefaultInstance.SendEachForMulticastAsync(message);
|
||||
|
||||
_logger.LogInfo("{SuccessCount} messages were sent successfully.", response.SuccessCount);
|
||||
|
||||
if (response.FailureCount > 0)
|
||||
@ -184,11 +185,16 @@ namespace Marco.Pms.Services.Service
|
||||
// Example: await YourTokenService.DeleteTokenAsync(loginDto.DeviceToken);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception Occured while sending notification to firebase");
|
||||
}
|
||||
|
||||
}
|
||||
public async Task SendMessageToMultipleDevicesAsync(List<string> registrationTokens, Notification notificationFirebase)
|
||||
{
|
||||
|
||||
using var scope = _serviceScopeFactory.CreateScope();
|
||||
var _logger = scope.ServiceProvider.GetRequiredService<ILoggingService>();
|
||||
try
|
||||
{
|
||||
var message = new MulticastMessage()
|
||||
|
Loading…
x
Reference in New Issue
Block a user