Skip to content

Commit

Permalink
Merge pull request #29 from eduardo-paes:development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
eduardo-paes authored Oct 25, 2023
2 parents a327cb6 + ef6a3ce commit a4ca9ea
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
10 changes: 6 additions & 4 deletions src/Application/UseCases/Project/OpenProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public async Task<ResumedReadProjectOutput> ExecuteAsync(OpenProjectInput input)
EProjectStatus.Opened,
EProjectStatus.Opened.GetDescription(),
null,
DateTime.UtcNow,
null,
null,
null,
null);
Expand Down Expand Up @@ -90,9 +90,11 @@ public async Task<ResumedReadProjectOutput> ExecuteAsync(OpenProjectInput input)
?? throw UseCaseException.NotFoundEntityById(nameof(Domain.Entities.Professor));

// Verifica se o professor está suspenso
UseCaseException.BusinessRuleViolation(
professor.SuspensionEndDate != null && professor.SuspensionEndDate > DateTime.UtcNow,
$"O acesso ao professor está suspenso até {professor.SuspensionEndDate!.Value:dd/MM/yyyy}, devido à pendência na entrega do relatório final em outro projeto.");
if (professor.SuspensionEndDate.HasValue)
{
UseCaseException.BusinessRuleViolation(professor.SuspensionEndDate! > DateTime.UtcNow,
$"O acesso ao professor está suspenso até {professor.SuspensionEndDate!.Value:dd/MM/yyyy}, devido à pendência na entrega do relatório final em outro projeto.");
}

// Caso tenha sido informado algum aluno no processo de abertura do projeto
if (project.StudentId.HasValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public async Task<IEnumerable<Project>> GetProfessorProjectsAsync(int skip, int
.Include(x => x.Notice)
.IgnoreQueryFilters()
.AsAsyncEnumerable()
.Where(x => x.StudentId == id
.Where(x => x.ProfessorId == id
&& (x.Status == EProjectStatus.Closed
|| x.Status == EProjectStatus.Canceled))
.OrderByDescending(x => x.Notice?.RegistrationStartDate) // Traz os projetos mais recentes primeiro.
Expand All @@ -78,7 +78,7 @@ public async Task<IEnumerable<Project>> GetProfessorProjectsAsync(int skip, int
.Include(x => x.Notice)
.IgnoreQueryFilters()
.AsAsyncEnumerable()
.Where(x => x.StudentId == id
.Where(x => x.ProfessorId == id
&& x.Status != EProjectStatus.Closed
&& x.Status != EProjectStatus.Canceled)
.OrderByDescending(x => x.Notice?.RegistrationStartDate) // Traz os projetos mais recentes primeiro.
Expand Down Expand Up @@ -132,7 +132,7 @@ public async Task<IEnumerable<Project>> GetStudentProjectsAsync(int skip, int ta
.Include(x => x.Notice)
.IgnoreQueryFilters()
.AsAsyncEnumerable()
.Where(x => x.ProfessorId == id
.Where(x => x.StudentId == id
&& (x.Status == EProjectStatus.Closed
|| x.Status == EProjectStatus.Canceled))
.OrderByDescending(x => x.Notice?.RegistrationStartDate) // Traz os projetos mais recentes primeiro.
Expand Down
50 changes: 33 additions & 17 deletions src/Infrastructure/WebAPI/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,41 @@ public void ConfigureServices(IServiceCollection services)
// Definição de política de CORS
services.AddCors(options =>
{
options.AddPolicy(name: CORS_POLICY_NAME,
policy =>
{
// Busca os valores de ALLOW_ORIGINS do arquivo .env
policy.WithOrigins(
origins: Environment.GetEnvironmentVariable("ALLOW_ORIGINS").Split(',')!)
.AllowAnyHeader()
.AllowAnyMethod();
});
// Permite qualquer origem, cabeçalho e método
options.AddDefaultPolicy(
builder =>
{
builder.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});

// // Busca os valores de ALLOW_ORIGINS do arquivo .env
// var allowedOrigins = Environment.GetEnvironmentVariable("ALLOW_ORIGINS")
// ?? throw new Exception("ALLOW_ORIGINS não definido nas variáveis de ambiente.");

// // Permite apenas as origens definidas no arquivo .env
// options.AddPolicy(name: CORS_POLICY_NAME,
// policy =>
// {
// // Busca os valores de ALLOW_ORIGINS do arquivo .env
// policy.WithOrigins(
// origins: allowedOrigins.Split(',')!)
// .AllowAnyHeader()
// .AllowAnyMethod();
// });
});
#endregion CORS

#region Rate Limit
services.AddMemoryCache();
services.AddInMemoryRateLimiting();
services.Configure<ClientRateLimitOptions>(_configuration.GetSection("IpRateLimiting"));
services.AddSingleton<IClientPolicyStore, MemoryCacheClientPolicyStore>();
services.AddSingleton<IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>();
services.AddSingleton<IProcessingStrategy, AsyncKeyLockProcessingStrategy>();
services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>();
// Definido através do API Gateway
// services.AddMemoryCache();
// services.AddInMemoryRateLimiting();
// services.Configure<ClientRateLimitOptions>(_configuration.GetSection("IpRateLimiting"));
// services.AddSingleton<IClientPolicyStore, MemoryCacheClientPolicyStore>();
// services.AddSingleton<IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>();
// services.AddSingleton<IProcessingStrategy, AsyncKeyLockProcessingStrategy>();
// services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>();
#endregion Rate Limit
}

Expand Down Expand Up @@ -95,7 +110,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseHttpsRedirection();

// Enable CORS
app.UseCors(CORS_POLICY_NAME);
app.UseCors();
// app.UseCors(CORS_POLICY_NAME);

// Enable routing for incoming requests
app.UseRouting();
Expand Down

0 comments on commit a4ca9ea

Please sign in to comment.