Skip to content

Commit

Permalink
Merge pull request #110 from AngeloDotNet/develop
Browse files Browse the repository at this point in the history
Sync Main from Develop
  • Loading branch information
AngeloDotNet authored Feb 5, 2025
2 parents b414075 + 2441c13 commit 46a0477
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 20 deletions.
17 changes: 17 additions & 0 deletions src/GSWCloudApp.Common/Polly/DependencyInjection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Microsoft.Extensions.Logging;
using Polly;
using Polly.Retry;

namespace GSWCloudApp.Common.Polly;

public static class DependencyInjection
{
public static AsyncRetryPolicy GetRetryPolicy(ILogger logger)
{
return Policy.Handle<Exception>().WaitAndRetryAsync(
retryCount: 3, // Numero di tentativi
sleepDurationProvider: attempt => TimeSpan.FromSeconds(Math.Pow(5, attempt)), // Intervallo esponenziale
onRetry: (exc, timespan, attempt, context)
=> logger.LogWarning(exc, "Tentativo {Attempt} fallito. Riprovo tra {TimespanSeconds} secondi.", attempt, timespan.TotalSeconds));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Options;

namespace GSWCloudApp.Common.RedisCache;
namespace GSWCloudApp.Common.RedisCache.Services;

/// <summary>
/// Provides methods for interacting with the distributed cache.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GSWCloudApp.Common.RedisCache;
namespace GSWCloudApp.Common.RedisCache.Services;

/// <summary>
/// Defines methods for interacting with the cache.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ public async Task<Results<Ok<TDto>, NotFound>> GetByIdAsync<TEntity, TDto>([From
return TypedResults.Ok(mapper.Map<TDto>(entity));
}

entity = await dbContext.Set<TEntity>()
.AsNoTracking()
entity = await dbContext.Set<TEntity>().AsNoTracking()
.FirstOrDefaultAsync(e => EF.Property<Guid>(e, "Id") == id);

if (entity is null)
Expand Down Expand Up @@ -180,8 +179,7 @@ public async Task<Results<Ok<TDto>, NotFound, BadRequest<string>>> UpdateAsync<T
public async Task<Results<NoContent, NotFound>> DeleteAsync<TEntity>(Guid id, DbContext dbContext)
where TEntity : class
{
var entity = await dbContext.Set<TEntity>()
.AsNoTracking()
var entity = await dbContext.Set<TEntity>().AsNoTracking()
.FirstOrDefaultAsync(e => EF.Property<Guid>(e, "Id") == id);

if (entity is null)
Expand Down
17 changes: 17 additions & 0 deletions src/GSWCloudApp.Common/Settings/SendEmail/SenderSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace GSWCloudApp.Common.Settings.SendEmail;

/// <summary>
/// Represents the settings for the email sender.
/// </summary>
public class SenderSettings
{
/// <summary>
/// Gets or sets the name of the sender.
/// </summary>
public string Name { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the email address of the sender.
/// </summary>
public string Email { get; set; } = string.Empty;
}
34 changes: 34 additions & 0 deletions src/GSWCloudApp.Common/Settings/SendEmail/SmtpSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using MailKit.Security;

namespace GSWCloudApp.Common.Settings.SendEmail;

/// <summary>
/// Represents the settings required to configure an SMTP client.
/// </summary>
public class SmtpSettings
{
/// <summary>
/// Gets or sets the SMTP server host.
/// </summary>
public string Host { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the port number to use for the SMTP server.
/// </summary>
public int Port { get; set; }

/// <summary>
/// Gets or sets the security options for the SMTP connection.
/// </summary>
public SecureSocketOptions Security { get; set; }

/// <summary>
/// Gets or sets the username for the SMTP server authentication.
/// </summary>
public string? Username { get; set; }

/// <summary>
/// Gets or sets the password for the SMTP server authentication.
/// </summary>
public string? Password { get; set; }
}
43 changes: 33 additions & 10 deletions src/GSWCloudApp.Common/Swagger/ConfigureSwaggerGenOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Text;
using Asp.Versioning.ApiExplorer;
using Asp.Versioning.ApiExplorer;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
Expand Down Expand Up @@ -33,11 +32,42 @@ public void Configure(SwaggerGenOptions options)
/// <returns>The OpenAPI information for the specified API version.</returns>
private static OpenApiInfo CreateInfoForApiVersion(ApiVersionDescription description)
{
var text = new StringBuilder("API endpoints that enable the use of this microservice.");
//var text = new StringBuilder("API endpoints that enable the use of this microservice.");
//var info = new OpenApiInfo()
//{
// Title = "API endpoints",
// Version = description.ApiVersion.ToString(),
// Contact = new OpenApiContact()
// {
// Name = "Angelo Pirola",
// Email = "angelo@aepserver.it",
// Url = new Uri("https://angelo.aepserver.it/")
// },
// License = new OpenApiLicense()
// {
// Name = "MIT License",
// Url = new Uri("https://opensource.org/licenses/MIT")
// }
//};

//if (description.IsDeprecated)
//{
// text.Append(" This API version has been deprecated.");
//}

//info.Description = text.ToString();

//return info;

var descriptionText = description.IsDeprecated
? "API endpoints that enable the use of this microservice. This API version has been deprecated."
: "API endpoints that enable the use of this microservice.";

var info = new OpenApiInfo()
{
Title = "API endpoints",
Version = description.ApiVersion.ToString(),
Description = descriptionText,
Contact = new OpenApiContact()
{
Name = "Angelo Pirola",
Expand All @@ -51,13 +81,6 @@ private static OpenApiInfo CreateInfoForApiVersion(ApiVersionDescription descrip
}
};

if (description.IsDeprecated)
{
text.Append(" This API version has been deprecated.");
}

info.Description = text.ToString();

return info;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@ public static class RouteHandlerBuilderExtensions
/// <param name="builder">The route handler builder.</param>
/// <returns>The route handler builder with validation added.</returns>
public static RouteHandlerBuilder WithValidation<T>(this RouteHandlerBuilder builder) where T : class
{
return builder.AddEndpointFilter<ValidatorFilter<T>>().ProducesValidationProblem();
}
}
=> builder.AddEndpointFilter<ValidatorFilter<T>>().ProducesValidationProblem();
}

0 comments on commit 46a0477

Please sign in to comment.