erp-platform/api/modules/Kurs.Notifications/Kurs.Notifications.Domain/NotificationIdentifierProvider.cs

50 lines
1.5 KiB
C#
Raw Normal View History

2025-05-06 06:45:49 +00:00
using System;
using System.Threading.Tasks;
using Kurs.Notifications.Enums;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Identity;
namespace Kurs.Notifications.Domain;
public interface INotificationIdentifierProvider : ITransientDependency
{
Task<string?> GetIdentifier(Guid UserId, string NotificationChannel);
}
public class NotificationIdentifierProvider : INotificationIdentifierProvider
{
private readonly IIdentityUserRepository userRepository;
public NotificationIdentifierProvider(IIdentityUserRepository userRepository)
{
this.userRepository = userRepository;
}
public async Task<string?> GetIdentifier(Guid UserId, string NotificationChannel)
{
var user = await userRepository.FindAsync(UserId);
if (user == null)
{
return null;
}
var identifier = NotificationChannel switch
{
NotificationChannels.Sms => user.PhoneNumber,
NotificationChannels.Mail => user.Email,
NotificationChannels.Rocket => user.GetProperty<string?>("RocketUsername"),
NotificationChannels.Desktop => user.Id.ToString(),
NotificationChannels.UiActivity => user.Id.ToString(),
NotificationChannels.UiToast => user.Id.ToString(),
NotificationChannels.WhatsApp => user.PhoneNumber,
NotificationChannels.Telegram => user.PhoneNumber,
_ => null,
};
return identifier;
}
}