Created ExpiringTECNWorker

This commit is contained in:
Chase Tucker
2024-03-29 15:01:39 -07:00
parent 830c8576e3
commit a86fbbbea0
5 changed files with 185 additions and 3 deletions

View File

@ -7,6 +7,7 @@ namespace FabApprovalWorkerService.Services;
public interface IECNService {
Task<IEnumerable<ECN>> GetExpiringTECNs();
Task<IEnumerable<ECN>> GetExpiredTECNs();
Task<IEnumerable<string>> GetTECNNotificationUserEmails();
}
public class ECNService : IECNService {
@ -75,4 +76,24 @@ public class ECNService : IECNService {
throw;
}
}
public async Task<IEnumerable<string>> GetTECNNotificationUserEmails() {
try {
_logger.LogInformation("Attempting to get TECN notification user emails");
string sql = "select u.Email from TECNNotificationsUsers t join Users u on t.UserId = u.UserID;";
IEnumerable<string> tecnNotificationUserEmails = (await _dalService.QueryAsync<string>(sql)).ToList();
_logger.LogInformation($"Found {tecnNotificationUserEmails.Count()} TECN notification user emails");
return tecnNotificationUserEmails;
} catch (Exception ex) {
StringBuilder errMsgBuilder = new();
errMsgBuilder.Append("An exception occurred when attempting to get TECN notification user emails. ");
errMsgBuilder.Append($"Exception: {ex.Message}");
_logger.LogError(errMsgBuilder.ToString());
throw;
}
}
}

View File

@ -1,7 +1,5 @@
using FabApprovalWorkerService.Models;
using NLog.Filters;
using System.Text;
namespace FabApprovalWorkerService.Services;
@ -20,6 +18,7 @@ public interface IUserService {
Task<bool> RemoveOOOFlagForUser(int userId);
Task<bool> SetOOOTempProcessed(OOOTemp oOOTemp);
Task<List<User>> GetAllExpiredOOOUsersAsync();
Task<string> GetUserEmail(int userId);
}
public class UserService : IUserService {
@ -341,4 +340,27 @@ public class UserService : IUserService {
throw;
}
}
public async Task<string> GetUserEmail(int userId) {
try {
if (userId <= 0) throw new ArgumentException($"User Id {userId} is not a valid user Id");
_logger.LogInformation($"Attempting to get email for user {userId}");
string sql = $"select Email from Users where UserID = {userId}";
string? userEmail = (await _dalService.QueryAsync<string>(sql)).ToList().FirstOrDefault();
if (userEmail is null)
throw new Exception($"No email found for user {userId}");
return userEmail;
} catch (Exception ex) {
StringBuilder errMsgBuilder = new();
errMsgBuilder.Append($"An exception occurred when attempting to get email for user {userId}. ");
errMsgBuilder.Append($"Exception: {ex.Message}");
_logger.LogError(errMsgBuilder.ToString());
throw;
}
}
}