From 17a0eff847f4dc858c24504b3a61a31ca22c8ec1 Mon Sep 17 00:00:00 2001 From: mohammadKarimi Date: Tue, 9 Jan 2024 17:48:17 +0330 Subject: [PATCH] Refactor Constants, Make all of them internal static. --- .../Links/GenerateCommand/GenerateShortCodeValidator.cs | 3 +-- src/SwiftLink.Presentation/Constants/Constants.cs | 4 +++- src/SwiftLink.Presentation/Program.cs | 6 +++--- src/SwiftLink.Shared/Constants/Constants.cs | 5 ----- 4 files changed, 7 insertions(+), 11 deletions(-) delete mode 100644 src/SwiftLink.Shared/Constants/Constants.cs diff --git a/src/SwiftLink.Application/UseCases/Links/GenerateCommand/GenerateShortCodeValidator.cs b/src/SwiftLink.Application/UseCases/Links/GenerateCommand/GenerateShortCodeValidator.cs index c39cade..78f5aee 100644 --- a/src/SwiftLink.Application/UseCases/Links/GenerateCommand/GenerateShortCodeValidator.cs +++ b/src/SwiftLink.Application/UseCases/Links/GenerateCommand/GenerateShortCodeValidator.cs @@ -1,5 +1,4 @@ using FluentValidation; -using SwiftLink.Application.Resources; namespace SwiftLink.Application.UseCases.Links.GenerateCommand; @@ -8,6 +7,6 @@ public class GenerateShortCodeValidator : AbstractValidator x.Url).NotNull() - .WithMessage(ApplicationMessage.Link.UrlMustBeSent); + .WithMessage(Constants.Link.UrlMustBeSent); } } \ No newline at end of file diff --git a/src/SwiftLink.Presentation/Constants/Constants.cs b/src/SwiftLink.Presentation/Constants/Constants.cs index 9d0a811..b49124a 100644 --- a/src/SwiftLink.Presentation/Constants/Constants.cs +++ b/src/SwiftLink.Presentation/Constants/Constants.cs @@ -1,7 +1,9 @@ namespace SwiftLink.Presentation; -internal static class Constants +internal static class Constants { + public const string UnHandledExceptions = "oops! something went wrong :("; + public static class EndPointFilterMessages { public const string InvalidUrl = "Url is not valid! :("; diff --git a/src/SwiftLink.Presentation/Program.cs b/src/SwiftLink.Presentation/Program.cs index 3a4495d..21fbb89 100644 --- a/src/SwiftLink.Presentation/Program.cs +++ b/src/SwiftLink.Presentation/Program.cs @@ -2,8 +2,8 @@ using Microsoft.AspNetCore.Diagnostics; using SwiftLink.Application; using SwiftLink.Infrastructure; +using SwiftLink.Presentation; using SwiftLink.Shared; -using SwiftLink.Shared.Constants; var builder = WebApplication.CreateBuilder(args); { @@ -42,7 +42,7 @@ context.Response.ContentType = "application/json"; var exceptionHandlerPathFeature = context.Features.Get(); var exception = exceptionHandlerPathFeature?.Error; - await context.Response.WriteAsync(Result.Failure(Error.DefaultMessage).ToString()!); + await context.Response.WriteAsync(Result.Failure(Constants.UnHandledExceptions).ToString()!); }); }); @@ -50,4 +50,4 @@ app.UseAuthorization(); app.MapControllers(); app.Run(); -} +} \ No newline at end of file diff --git a/src/SwiftLink.Shared/Constants/Constants.cs b/src/SwiftLink.Shared/Constants/Constants.cs deleted file mode 100644 index 4d662a6..0000000 --- a/src/SwiftLink.Shared/Constants/Constants.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace SwiftLink.Shared; -public class Constants -{ - public static string DefaultMessage = "عملیات با خطا مواجه شد"; -}