Firebird Cloud Message API előkészítése

This commit is contained in:
2025-05-15 14:41:34 +02:00
parent 0a36544dce
commit b6ffcca996
12 changed files with 1380 additions and 6 deletions
@@ -9,5 +9,7 @@ namespace WorkFlowCheck.BL.Services.Interfaces
public interface IMessageService
{
Task<bool> SendMailAsync(List<string> recipients, string subject, string htmlBody);
Task<bool> SendFCMTokenAsync(string token);
Task<string> GetLastFCMTokensAsync();
}
}
@@ -4,14 +4,21 @@ using MimeKit;
using Microsoft.Extensions.Configuration;
using WorkFlowCheck.BL.Models;
using WorkFlowCheck.BL.Services.Interfaces;
using Serilog;
using WorkFlowCheck.DL.Entities;
using AutoMapper;
using Microsoft.EntityFrameworkCore;
using WorkFlowCheck.DL;
namespace WorkFlowCheck.BL.Services
{
public class MessageService : IMessageService
public class MessageService : BaseService, IMessageService
{
private readonly EmailSettings _settings;
public MessageService(IConfiguration configuration)
public MessageService(AppDbContext dbContext,
IMapper mapper,
IConfiguration configuration) : base(dbContext, mapper)
{
_settings = configuration.GetSection("EmailSettings").Get<EmailSettings>()!;
}
@@ -41,6 +48,51 @@ namespace WorkFlowCheck.BL.Services
return true;
}
public async Task<bool> SendFCMTokenAsync(string token)
{
var retVal = true;
try
{
if (string.IsNullOrEmpty(token))
{
var FCMToken = new FCMToken()
{
Token = token
};
await _dbContext.FCMTokens.AddAsync(FCMToken);
await _dbContext.SaveChangesAsync();
}
}
catch (Exception ex)
{
retVal = false;
Log.ForContext("TAG", "BusinessFlow").Error(ex.Message);
}
return retVal;
}
public async Task<string> GetLastFCMTokensAsync()
{
var retVal = "";
try
{
var FCMToken = await _dbContext.FCMTokens
.AsNoTracking()
.OrderByDescending(x => x.CreatedAt)
.Take(1)
.FirstOrDefaultAsync();
if (FCMToken != null && !string.IsNullOrEmpty(FCMToken.Token))
{
retVal += FCMToken.Token;
}
}
catch (Exception ex)
{
retVal = "";
Log.ForContext("TAG", "BusinessFlow").Error(ex.Message);
}
return retVal;
}
}
}