-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ShortenEndpointFilter, Add Constants. Unifies all mesages.
- Loading branch information
1 parent
e656f1f
commit c3d3f5e
Showing
6 changed files
with
37 additions
and
4 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
...plication/Resources/ApplicationMessage.cs → ...ftLink.Application/Constants/Constants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace SwiftLink.Presentation; | ||
|
||
internal static class Constants | ||
{ | ||
public static class EndPointFilterMessages | ||
{ | ||
public const string InvalidUrl = "Url is not valid! :("; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/SwiftLink.Presentation/Filters/ShortenEndpointFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
using SwiftLink.Application.UseCases.Links.GenerateCommand; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace SwiftLink.Presentation.Filters; | ||
|
||
public partial class ShortenEndpointFilter : ActionFilterAttribute | ||
{ | ||
private const int _urlArgumentIndex = 0; | ||
private const string _pattern = @"^(?:(?:https?|ftp)://)?[^\s/$.?#].[^\s]*$"; | ||
|
||
public override void OnActionExecuting(ActionExecutingContext context) | ||
{ | ||
} | ||
|
||
private static bool IsValidUrl(string url) | ||
=> ShortCodeRegex().IsMatch(url); | ||
|
||
[GeneratedRegex(_pattern, RegexOptions.IgnoreCase, "en-US")] | ||
private static partial Regex ShortCodeRegex(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/SwiftLink.Shared/Error.cs → src/SwiftLink.Shared/Constants/Constants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
namespace SwiftLink.Shared; | ||
public class Error | ||
public class Constants | ||
{ | ||
public static string DefaultMessage = "عملیات با خطا مواجه شد"; | ||
} |