File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed
SwiftLink.Application/UseCases/Links
Commands/GenerateShortCode Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ public GenerateShortCodeValidator(IApplicationDbContext dbContext)
1616 . Must ( BeAValidUrl ) . WithMessage ( LinkMessages . InvalidUrlFormat . Message ) ;
1717
1818 RuleFor ( x => x . BackHalf )
19+ . MaximumLength ( 16 ) . WithMessage ( LinkMessages . BackHalfLength . Message )
20+ . Must ( BeAValidCharacters ) . WithMessage ( LinkMessages . BackHalfInvalidFormat . Message )
1921 . MustAsync ( BeAValidBackHalf ) . WithMessage ( LinkMessages . BackHalfIsExist . Message ) ;
2022
2123 RuleFor ( x => x . ExpirationDate )
@@ -25,6 +27,9 @@ public GenerateShortCodeValidator(IApplicationDbContext dbContext)
2527 private bool BeAValidUrl ( string url )
2628 => UrlFormatChecker . UrlRegex ( ) . IsMatch ( url ) ;
2729
30+ private bool BeAValidCharacters ( string backHalf )
31+ => BackHalfFormatChecker . WordRegex ( ) . IsMatch ( backHalf ) ;
32+
2833 private bool BeAValidExpirationDate ( DateTime ? date )
2934 => date is null || date . Value > DateTime . Now ;
3035
Original file line number Diff line number Diff line change @@ -13,8 +13,10 @@ internal record LinkMessages
1313 public static readonly Error InvalidLinkId = Error . Validation ( "LinkValidation" , "Invalid LinkId or Subscriber Token." ) ;
1414 public static readonly Error InvalidSubscriberId = Error . Validation ( "LinkValidation" , "Invalid SubscriberId." ) ;
1515 public static readonly Error BackHalfIsExist = Error . Failure ( "LinkValidation" , "This back-half text is used before." ) ;
16+ public static readonly Error BackHalfLength = Error . Validation ( "BackHalf Validation" , "Back-Half must be less than 16 characters." ) ;
17+ public static readonly Error BackHalfInvalidFormat = Error . Validation ( "BackHalf Validation" , "Back-Half must be contain words and numbers." ) ;
18+
1619 public static readonly Error GroupNameMustBeSent = Error . Validation ( "GroupName Validation" , "GroupName field can not be null." ) ;
1720 public static readonly Error InvalidBackHalfLength = Error . Validation ( "LinkValidation" , "maximum length for back-half text is 30." ) ;
1821 public static readonly Error InvalidBackHalf = Error . Validation ( "LinkValidation" , "maximum length for back-half text is 30." ) ;
19-
2022}
Original file line number Diff line number Diff line change 1+ using System . Text . RegularExpressions ;
2+
3+ namespace SwiftLink . Shared ;
4+
5+ public static partial class BackHalfFormatChecker
6+ {
7+ private const string Pattern = @"^[a-zA-Z0-9]*$" ;
8+
9+ [ GeneratedRegex ( Pattern , RegexOptions . IgnoreCase , "en-US" ) ]
10+ public static partial Regex WordRegex ( ) ;
11+ }
You can’t perform that action at this time.
0 commit comments