Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Haik committed Mar 18, 2024
1 parent f6fde58 commit 0e4c213
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<PackageVersion Include="PandaTech.IEnumerableFilters" Version="4.0.19" />
<PackageVersion Include="Pandatech.Communicator" Version="1.0.2" />
<PackageVersion Include="Pandatech.Crypto" Version="2.3.1" />
<PackageVersion Include="Pandatech.PandaVaultClient" Version="3.0.6" />
<PackageVersion Include="Pandatech.PandaVaultClient" Version="3.1.0" />
<PackageVersion Include="Pandatech.RegexBox" Version="1.2.4" />
<PackageVersion Include="Pandatech.ResponseCrafter" Version="1.0.4" />
<PackageVersion Include="Respawn" Version="6.2.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using PandaTech.IEnumerableFilters.Converters;
using Pandatech.VerticalSlices.Domain.Entities;
using Pandatech.VerticalSlices.Domain.Enums;
using Pandatech.VerticalSlices.DTOs.User;
using Pandatech.VerticalSlices.z._Old_way.DTOs;

namespace Pandatech.VerticalSlices.Domain.EntityFilters;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Pandatech.VerticalSlices.DTOs.Inner;
namespace Pandatech.VerticalSlices.Features.Auth.Contracts.Authenticate;

public class IdentityCookies
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Pandatech.VerticalSlices.DTOs.Inner;
using Pandatech.VerticalSlices.Features.Auth.Contracts.Authenticate;
using Pandatech.VerticalSlices.Features.Auth.Contracts.Login;
using Pandatech.VerticalSlices.Features.Auth.Contracts.RefreshToken;
using Pandatech.VerticalSlices.SharedKernel.Extensions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,70 +6,70 @@ namespace Pandatech.VerticalSlices.Infrastructure.Extensions;

public static class SerilogExtension
{
public static WebApplicationBuilder AddSerilog(this WebApplicationBuilder builder)
{
var configuration = builder.Configuration;
var indexName = configuration["ElasticIndexName"]!;
var elasticSearchUrl = configuration.GetConnectionString("ElasticSearch")!;
public static WebApplicationBuilder AddSerilog(this WebApplicationBuilder builder)
{
var configuration = builder.Configuration;
var indexName = configuration["ElasticIndexName"]!;
var elasticSearchUrl = configuration.GetConnectionString("ElasticSearch")!;

var loggerConfig = new LoggerConfiguration()
.Enrich.FromLogContext()
.Enrich.WithMachineName()
.Filter.ByExcluding(logEvent => logEvent.ShouldExcludeHangfireDashboardLogs())
.ReadFrom.Configuration(configuration);
var loggerConfig = new LoggerConfiguration()
.Enrich.FromLogContext()
.Enrich.WithMachineName()
.Filter.ByExcluding(logEvent => logEvent.ShouldExcludeHangfireDashboardLogs())
.ReadFrom.Configuration(configuration);

ConfigureEnvironmentSpecificSettings(builder.Environment, loggerConfig, elasticSearchUrl, indexName);
ConfigureEnvironmentSpecificSettings(builder.Environment, loggerConfig, elasticSearchUrl, indexName);

Log.Logger = loggerConfig.CreateLogger();
builder.Logging.ClearProviders();
builder.Logging.AddSerilog();
builder.Services.AddSingleton(Log.Logger);
return builder;
}
Log.Logger = loggerConfig.CreateLogger();
builder.Logging.ClearProviders();
builder.Logging.AddSerilog();
builder.Services.AddSingleton(Log.Logger);
return builder;
}

private static void ConfigureEnvironmentSpecificSettings(IHostEnvironment environment,
LoggerConfiguration loggerConfig, string elasticSearchUrl, string indexName)
{
if (environment.IsLocal())
{
loggerConfig.WriteTo.Console();
}
private static void ConfigureEnvironmentSpecificSettings(IHostEnvironment environment,
LoggerConfiguration loggerConfig, string elasticSearchUrl, string indexName)
{
if (environment.IsLocal())
{
loggerConfig.WriteTo.Console();
}

else if (environment.IsDevelopment())
else if (environment.IsDevelopment())

{
loggerConfig.WriteTo.Console();
ConfigureElasticsearch(loggerConfig, elasticSearchUrl, indexName, environment);
}
else
{
ConfigureElasticsearch(loggerConfig, elasticSearchUrl, indexName, environment);
}
}
{
loggerConfig.WriteTo.Console();
ConfigureElasticsearch(loggerConfig, elasticSearchUrl, indexName, environment);
}
else
{
ConfigureElasticsearch(loggerConfig, elasticSearchUrl, indexName, environment);
}
}

private static void ConfigureElasticsearch(LoggerConfiguration loggerConfig, string elasticSearchUrl,
string indexName, IHostEnvironment environment)
{
var envName = environment.GetShortEnvironmentName();
private static void ConfigureElasticsearch(LoggerConfiguration loggerConfig, string elasticSearchUrl,
string indexName, IHostEnvironment environment)
{
var envName = environment.GetShortEnvironmentName();

var formattedIndexName = !string.IsNullOrEmpty(envName)
? $"{indexName}-{envName}-logs-{DateTime.UtcNow:yyyy.MM}"
: $"{indexName}-logs-{DateTime.UtcNow:yyyy.MM}";
var formattedIndexName = !string.IsNullOrEmpty(envName)
? $"{indexName}-{envName}-logs-{DateTime.UtcNow:yyyy.MM}"
: $"{indexName}-logs-{DateTime.UtcNow:yyyy.MM}";

loggerConfig.WriteTo.Elasticsearch(elasticSearchUrl,
indexFormat: formattedIndexName,
autoRegisterTemplate: true,
detectElasticsearchVersion: true,
numberOfShards: 5,
numberOfReplicas: 1,
bufferBaseFilename: "./logs/elastic-buffer",
bufferFileSizeLimitBytes: 1024 * 1024 * 16); // 16 MB each buffer file
}
loggerConfig.WriteTo.Elasticsearch(elasticSearchUrl,
indexFormat: formattedIndexName,
autoRegisterTemplate: true,
detectElasticsearchVersion: true,
numberOfShards: 5,
numberOfReplicas: 1,
bufferBaseFilename: "./logs/elastic-buffer",
bufferFileSizeLimitBytes: 1024 * 1024 * 16); // 16 MB each buffer file
}

private static bool ShouldExcludeHangfireDashboardLogs(this LogEvent logEvent)
{
return logEvent.Properties.TryGetValue("RequestPath", out var requestPathValue)
&& requestPathValue is ScalarValue requestPath
&& requestPath.Value?.ToString()?.Contains("/hangfire") == true;
}
private static bool ShouldExcludeHangfireDashboardLogs(this LogEvent logEvent)
{
return logEvent.Properties.TryGetValue("RequestPath", out var requestPathValue)
&& requestPathValue is ScalarValue requestPath
&& requestPath.Value?.ToString()?.Contains("/hangfire") == true;
}
}
4 changes: 2 additions & 2 deletions src/Pandatech.VerticalSlices/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
.RegisterAllServices()
.AddSwagger()
.AddResponseCrafter()
.AddMediatrWithValidatorBehaviors()
.AddMediatrWithBehaviors()
.RegisterPandaVaultEndpoint(); //optional

builder.Services.AddCarter();
Expand Down Expand Up @@ -48,7 +48,7 @@
//todo Delete health checks and other configs of unrelated services. For example you might not need RMQ or Redis in this project.

Check warning on line 48 in src/Pandatech.VerticalSlices/Program.cs

View workflow job for this annotation

GitHub Actions / build-and-deploy

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)
//todo Update all Nuget packages.
//todo Include all required configurations in appsettings{environment}.json.
//todo Update ReadMe.md file.
//todo Update ReadMm.md file.

//Delete below rows if you have no integration Pandatech.VerticalSlices.Tests in your solution.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Pandatech.VerticalSlices.SharedKernel.Extensions;

public static class MediatrExtension
{
public static WebApplicationBuilder AddMediatrWithValidatorBehaviors(this WebApplicationBuilder builder)
public static WebApplicationBuilder AddMediatrWithBehaviors(this WebApplicationBuilder builder)
{
var assembly = typeof(Program).Assembly;
builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(assembly));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ namespace Pandatech.VerticalSlices.SharedKernel.SharedEndpoints;
public static class OptionalEndpoints
{
private const string TagName = "above-board";

public static void MapPandaOptionalEndpoints(this WebApplication app)
{
if (!app.Environment.IsProduction())
{
app.MapPandaVaultApi(TagName);
app.MapPandaVaultApi($"/{TagName}/configuration", TagName, ApiHelper.GroupNameMain);
}

if (app.Environment.IsLocal())
Expand All @@ -26,7 +27,8 @@ private static WebApplication MapDatabaseResetApi(this WebApplication app)
{
app.MapGet("/above-board/reset-database",
([FromServices] DatabaseHelper helper) => helper.ResetDatabase<PostgresContext>())
.WithTags("above-board");
.WithTags("above-board")
.WithGroupName(ApiHelper.GroupNameMain);


return app;
Expand Down
2 changes: 1 addition & 1 deletion src/Pandatech.VerticalSlices/z. Old way/DTOs/GetUserDto.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using BaseConverter.Attributes;
using Pandatech.VerticalSlices.Domain.Enums;

namespace Pandatech.VerticalSlices.DTOs.User
namespace Pandatech.VerticalSlices.z._Old_way.DTOs
{
public class GetUserDto
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Pandatech.VerticalSlices.Domain.Enums;

namespace Pandatech.VerticalSlices.DTOs.User
namespace Pandatech.VerticalSlices.z._Old_way.DTOs
{
public class RolesSelect
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using BaseConverter.Attributes;

namespace Pandatech.VerticalSlices.DTOs.User
namespace Pandatech.VerticalSlices.z._Old_way.DTOs
{
public class UpdatePasswordDto
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using BaseConverter.Attributes;
using Pandatech.VerticalSlices.Domain.Enums;

namespace Pandatech.VerticalSlices.DTOs.User
namespace Pandatech.VerticalSlices.z._Old_way.DTOs
{
public class UpdateStatusDto
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using BaseConverter.Attributes;
using Pandatech.VerticalSlices.Domain.Enums;

namespace Pandatech.VerticalSlices.DTOs.User
namespace Pandatech.VerticalSlices.z._Old_way.DTOs
{
public class UpdateUserDto
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using BaseConverter.Attributes;
using Pandatech.VerticalSlices.Domain.Enums;

namespace Pandatech.VerticalSlices.DTOs.User
namespace Pandatech.VerticalSlices.z._Old_way.DTOs
{
public class UpdateUserStatusDto
{
Expand Down
4 changes: 2 additions & 2 deletions src/Pandatech.VerticalSlices/z. Old way/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
using PandaTech.IEnumerableFilters.Extensions;
using Pandatech.VerticalSlices.Domain.EntityFilters;
using Pandatech.VerticalSlices.Domain.Enums;
using Pandatech.VerticalSlices.DTOs.User;
using Pandatech.VerticalSlices.Infrastructure.Contexts;
using Pandatech.VerticalSlices.z._Old_way.DTOs;
using ResponseCrafter.Dtos;
using ResponseCrafter.StandardHttpExceptions;

namespace Pandatech.VerticalSlices.Services.Implementations;
namespace Pandatech.VerticalSlices.z._Old_way;

public class UserService(
Argon2Id argon2Id,
Expand Down

0 comments on commit 0e4c213

Please sign in to comment.