-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ReportDeadlineNotificationFunction
- Loading branch information
eduardo
committed
Sep 4, 2023
1 parent
5b1348e
commit b9401ba
Showing
25 changed files
with
1,358 additions
and
18 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/Application/Interfaces/UseCases/Notice/IReportDeadlineNotification.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Application.Interfaces.UseCases.Notice | ||
{ | ||
public interface IReportDeadlineNotification | ||
{ | ||
/// <summary> | ||
/// Envia notificação para os professores de que está próximo o prazo de entrega dos relatórios. | ||
/// </summary> | ||
/// <returns>Resultado do processo de notificação</returns> | ||
Task<string> ExecuteAsync(); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/Application/UseCases/Notice/ReportDeadlineNotification.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using Application.Interfaces.UseCases.Notice; | ||
using Domain.Interfaces.Repositories; | ||
using Domain.Interfaces.Services; | ||
|
||
namespace Application.UseCases.Notice | ||
{ | ||
public class ReportDeadlineNotification : IReportDeadlineNotification | ||
{ | ||
#region Global Scope | ||
private readonly IProjectRepository _projectRepository; | ||
private readonly IEmailService _emailService; | ||
public ReportDeadlineNotification( | ||
IProjectRepository projectRepository, | ||
IEmailService emailService) | ||
{ | ||
_projectRepository = projectRepository; | ||
_emailService = emailService; | ||
} | ||
#endregion | ||
|
||
public async Task<string> ExecuteAsync() | ||
{ | ||
// Verifica se o há projetos que estejam no status Iniciado | ||
var projects = await _projectRepository.GetProjectsWithCloseReportDueDateAsync(); | ||
if (!projects.Any()) | ||
return "Nenhum projeto com prazo de entrega de relatório próxima."; | ||
|
||
// Define datas de comparação | ||
DateTime nextMonth = DateTime.UtcNow.AddMonths(1).Date; | ||
DateTime nextWeek = DateTime.UtcNow.AddDays(7).Date; | ||
|
||
// Envia notificação para cada projeto | ||
foreach (var project in projects) | ||
{ | ||
// Verifica qual o relatório com data de entrega mais próxima | ||
DateTime reportDeadline = project.Notice!.PartialReportDeadline!.Value.Date; | ||
string reportType; | ||
if (reportDeadline == nextWeek || reportDeadline == nextMonth) | ||
{ | ||
reportType = "Relatório Parcial"; | ||
} | ||
else | ||
{ | ||
reportType = "Relatório Final"; | ||
reportDeadline = project.Notice!.FinalReportDeadline!.Value.Date; | ||
} | ||
|
||
// Envia notificação para o professor | ||
await _emailService.SendNotificationOfReportDeadlineEmailAsync( | ||
project.Professor!.User!.Email, | ||
project.Professor.User.Name, | ||
project.Title, | ||
reportType, | ||
reportDeadline | ||
); | ||
} | ||
|
||
return "Notificação de prazo de entrega de relatório enviada com sucesso."; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+12.6 KB
src/Infrastructure/Services/Email/Templates/Imgs/icon-gpic-original.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.