Added training reminder worker

This commit is contained in:
Chase Tucker
2024-04-10 09:59:55 -07:00
parent 156dee0751
commit ed89f25dad
9 changed files with 394 additions and 9 deletions

View File

@ -19,6 +19,7 @@ public interface IUserService {
Task<bool> SetOOOTempProcessed(OOOTemp oOOTemp);
Task<List<User>> GetAllExpiredOOOUsersAsync();
Task<string> GetUserEmail(int userId);
Task<User> GetUserById(int userId);
}
public class UserService : IUserService {
@ -355,7 +356,7 @@ public class UserService : IUserService {
string sql = $"select Email from Users where UserID = {userId}";
string? userEmail = (await _dalService.QueryAsync<string>(sql)).ToList().FirstOrDefault();
string? userEmail = (await _dalService.QueryAsync<string>(sql)).FirstOrDefault();
if (userEmail is null)
throw new Exception($"No email found for user {userId}");
@ -369,4 +370,27 @@ public class UserService : IUserService {
throw;
}
}
public async Task<User> GetUserById(int userId) {
if (userId <= 0) throw new ArgumentException($"{userId} not a valid UserID");
try {
_logger.LogInformation($"Attempting to get user {userId}");
string sql = $"select * from Users where UserID = {userId}";
User? user = (await _dalService.QueryAsync<User>(sql)).FirstOrDefault();
if (user is null)
throw new Exception($"No user found for id {userId}");
return user;
} 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;
}
}
}