From e570a484b287eaa032810607d8ee4ba1e90731c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Recep=20G=C3=BCne=C5=9F?= Date: Fri, 1 Sep 2023 13:17:05 +0300 Subject: [PATCH] bug fixes --- .gitignore | 2 +- external-services.yml | 4 +-- internal-services.yml | 2 ++ .../GetAllUrlsFromBufferQueryHandler.cs | 4 ++- .../Commands/ReachUrlCommandHandler.cs | 4 +-- .../Infrastructure/Services/OutboxWorker.cs | 1 - .../Shared/Extensions/SharedExtensions.cs | 34 ------------------- src/Utils/Shared/Shared.csproj | 9 +---- 8 files changed, 11 insertions(+), 49 deletions(-) diff --git a/.gitignore b/.gitignore index 3d34062..96e7749 100644 --- a/.gitignore +++ b/.gitignore @@ -363,4 +363,4 @@ MigrationBackup/ FodyWeavers.xsd # Rider -.idea \ No newline at end of file +.idea diff --git a/external-services.yml b/external-services.yml index 1178e7a..cc6213f 100644 --- a/external-services.yml +++ b/external-services.yml @@ -32,8 +32,8 @@ services: image: docker.elastic.co/elasticsearch/elasticsearch:7.9.2 ports: - 9200:9200 - volumes: - - elasticsearch-data:/usr/share/elasticsearch/data +# volumes: +# - elasticsearch-data:/usr/share/elasticsearch/data environment: - xpack.monitoring.enabled=true - xpack.watcher.enabled=false diff --git a/internal-services.yml b/internal-services.yml index 21b150b..2a8a86b 100644 --- a/internal-services.yml +++ b/internal-services.yml @@ -39,6 +39,8 @@ services: dockerfile: src/Gateway/Gateway.WebAPI/Dockerfile environment: ASPNETCORE_ENVIRONMENT: Production + ports: + - 5043:80 depends_on: - expiry_check_api - shortener_api diff --git a/src/Buffer/Infrastructure/Queries/GetAllUrlsFromBufferQueryHandler.cs b/src/Buffer/Infrastructure/Queries/GetAllUrlsFromBufferQueryHandler.cs index c7e1769..7809c26 100644 --- a/src/Buffer/Infrastructure/Queries/GetAllUrlsFromBufferQueryHandler.cs +++ b/src/Buffer/Infrastructure/Queries/GetAllUrlsFromBufferQueryHandler.cs @@ -33,7 +33,9 @@ public async Task Handle(GetAllUrlsFromBufferQuery request, Ca logger.LogInformation($"Request was handled by {nameof(GetAllUrlsFromBufferQueryHandler)}"); var sql = @"SELECT ""Id"", ""LongUrl"", ""ShortPath"", ""CreatedDate"", ""LastRequestedDate"", ""RequestCounter"", ""ExpireDate"", ""IsPublic"" FROM public.""Urls"" -WHERE ""IsPublic"" = true;"; +WHERE ""IsPublic"" = true +ORDER BY ""CreatedDate"" DESC; +"; var result = await connection.QueryAsync(sql); logger.LogInformation($"Executed Query:{Environment.NewLine}\t{sql}"); ArgumentNullException.ThrowIfNull(result); diff --git a/src/Shortener/Infrastructure/Commands/ReachUrlCommandHandler.cs b/src/Shortener/Infrastructure/Commands/ReachUrlCommandHandler.cs index 644c140..ecb94e9 100644 --- a/src/Shortener/Infrastructure/Commands/ReachUrlCommandHandler.cs +++ b/src/Shortener/Infrastructure/Commands/ReachUrlCommandHandler.cs @@ -30,12 +30,12 @@ public async Task Handle(ReachUrlCommand request, CancellationToken var url = await dbContext.Urls.FirstOrDefaultAsync(p => p.ShortPath == request.ShortPath); if (url == null) { - return new() { Message = "an error occurred" }; + return new() { Message = string.Empty }; } url.RequestCounter++; url.LastRequestedDate = DateTime.UtcNow; await dbContext.SaveChangesAsync(); - return new() { Message = "it is okay" }; + return new() { Message = url.LongUrl }; } } } diff --git a/src/Shortener/Infrastructure/Services/OutboxWorker.cs b/src/Shortener/Infrastructure/Services/OutboxWorker.cs index 01ca222..72fcbc4 100644 --- a/src/Shortener/Infrastructure/Services/OutboxWorker.cs +++ b/src/Shortener/Infrastructure/Services/OutboxWorker.cs @@ -63,7 +63,6 @@ private async Task PublishOutboxMessages(CancellationToken stoppingToken) _logger.LogWarning(ex.ToJsonString()); } } - await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken); } } diff --git a/src/Utils/Shared/Extensions/SharedExtensions.cs b/src/Utils/Shared/Extensions/SharedExtensions.cs index c900f09..39d7ace 100644 --- a/src/Utils/Shared/Extensions/SharedExtensions.cs +++ b/src/Utils/Shared/Extensions/SharedExtensions.cs @@ -1,9 +1,5 @@ using System.Collections; -using System.Reflection; using System.Text.Json; -using Microsoft.Extensions.Configuration; -using Serilog; -using Serilog.Sinks.Elasticsearch; namespace Shared.Extensions { @@ -29,35 +25,5 @@ public static string ToJsonString(this Exception ex) var jsonException = JsonSerializer.Serialize(exceptionDetails, new JsonSerializerOptions { WriteIndented = true }); return jsonException; } - - public static void ConfigureLogging() - { - var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); - var configuration = new ConfigurationBuilder() - .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) - .AddJsonFile( - $"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", - optional: true) - .Build(); - - Log.Logger = new LoggerConfiguration() - .Enrich.FromLogContext() - .Enrich.WithMachineName() - .WriteTo.Debug() - .WriteTo.Console() - .WriteTo.Elasticsearch(ConfigureElasticSink(configuration, environment)) - .Enrich.WithProperty("Environment", environment) - .ReadFrom.Configuration(configuration) - .CreateLogger(); - } - - private static ElasticsearchSinkOptions ConfigureElasticSink(IConfigurationRoot configuration, string environment) - { - return new ElasticsearchSinkOptions(new Uri(configuration["ElasticConfiguration:Uri"])) - { - AutoRegisterTemplate = true, - IndexFormat = $"{Assembly.GetExecutingAssembly().GetName().Name.ToLower().Replace(".", "-")}-{environment?.ToLower().Replace(".", "-")}-{DateTime.UtcNow:yyyy-MM}" - }; - } } } diff --git a/src/Utils/Shared/Shared.csproj b/src/Utils/Shared/Shared.csproj index 346ec21..7794584 100644 --- a/src/Utils/Shared/Shared.csproj +++ b/src/Utils/Shared/Shared.csproj @@ -5,12 +5,5 @@ enable enable - - - - - - - - +