diff --git a/Shortify.NET.API/Contracts/UpdateShortenedUrlRequest.cs b/Shortify.NET.API/Contracts/UpdateShortenedUrlRequest.cs index d61114b..2224849 100644 --- a/Shortify.NET.API/Contracts/UpdateShortenedUrlRequest.cs +++ b/Shortify.NET.API/Contracts/UpdateShortenedUrlRequest.cs @@ -2,6 +2,7 @@ { public record UpdateShortenedUrlRequest( Guid Id, + string OriginalUrl, string? Title, List? Tags); } \ No newline at end of file diff --git a/Shortify.NET.API/Controllers/V1/ShortController.cs b/Shortify.NET.API/Controllers/V1/ShortController.cs index 8f8b748..0f00ea7 100644 --- a/Shortify.NET.API/Controllers/V1/ShortController.cs +++ b/Shortify.NET.API/Controllers/V1/ShortController.cs @@ -112,6 +112,8 @@ public async Task RedirectUrl(string code, CancellationToken canc /// Search term can be the Title or any Tag or a fraction of them. Nullable. /// Column to Sort the response on. Nullable. Default sort will be on Id. /// Can be "desc" or null. Default is ascending. + /// Starting Range of CreatedOnUtc for filtering. Nullable. + /// Ending Range of CreatedOnUtc for filtering. Nullable. /// Page No. Mandatory. /// Page Size. Mandatory. /// The cancellation token. @@ -128,6 +130,8 @@ public async Task GetShortenedUrls( string? searchTerm, string? sortColumn, string? sortOrder, + DateTime? fromDate, + DateTime? toDate, int page, int pageSize, CancellationToken cancellationToken = default) @@ -144,6 +148,8 @@ public async Task GetShortenedUrls( SearchTerm: searchTerm, SortColumn: sortColumn, SortOrder: sortOrder, + FromDate: fromDate, + ToDate: toDate, Page: page, PageSize: pageSize); @@ -263,6 +269,15 @@ public async Task UpdateShortenedUrl( [FromBody] UpdateShortenedUrlRequest request, CancellationToken cancellationToken = default) { + if(!Uri.TryCreate(request.OriginalUrl, UriKind.Absolute, out _)) + { + return HandleFailure( + Result.Failure( + Error.Validation( + "Error.ValidationError", + "The specified Original URL is not valid."))); + } + var command = _mapper.UpdateShortenedUrlRequestToCommand(request); var response = await _apiService.SendAsync(command, cancellationToken); diff --git a/Shortify.NET.API/wwwroot/404.html b/Shortify.NET.API/wwwroot/404.html index 2662a53..9d98ba6 100644 --- a/Shortify.NET.API/wwwroot/404.html +++ b/Shortify.NET.API/wwwroot/404.html @@ -83,11 +83,11 @@

This link or QR Code is invalid

The link you're trying to access is not a valid one. - Use Shortify.NET to create and manage short links, QR codes, and landing + Use Shortify.NET to create and manage short links, QR codes, and landing pages.

- Visit Shortify.NET to learn more and get started today. + Visit Shortify.NET to learn more and get started today.

diff --git a/Shortify.NET.API/wwwroot/410.html b/Shortify.NET.API/wwwroot/410.html index a292efa..5ba05e8 100644 --- a/Shortify.NET.API/wwwroot/410.html +++ b/Shortify.NET.API/wwwroot/410.html @@ -83,11 +83,11 @@

This link or QR Code has been deactivated

The link you're trying to access is no longer active. - Use Shortify.NET to create and manage short links, QR codes, and landing + Use Shortify.NET to create and manage short links, QR codes, and landing pages.

- Visit Shortify.NET to learn more and get started today. + Visit Shortify.NET to learn more and get started today.

diff --git a/Shortify.NET.Application/Abstractions/Repositories/IShortenedUrlRepository.cs b/Shortify.NET.Application/Abstractions/Repositories/IShortenedUrlRepository.cs index ae27461..df56ee6 100644 --- a/Shortify.NET.Application/Abstractions/Repositories/IShortenedUrlRepository.cs +++ b/Shortify.NET.Application/Abstractions/Repositories/IShortenedUrlRepository.cs @@ -19,7 +19,9 @@ public interface IShortenedUrlRepository Guid id, string? searchTerm, string? sortColumn, - string? sortOrder, + string? sortOrder, + DateTime? fromDate, + DateTime? toDate, int page, int pageSize, CancellationToken cancellationToken = default); diff --git a/Shortify.NET.Application/Url/Commands/ShortenUrl/ShortenUrlCommandHandler.cs b/Shortify.NET.Application/Url/Commands/ShortenUrl/ShortenUrlCommandHandler.cs index 0a3a0cc..e8254d6 100644 --- a/Shortify.NET.Application/Url/Commands/ShortenUrl/ShortenUrlCommandHandler.cs +++ b/Shortify.NET.Application/Url/Commands/ShortenUrl/ShortenUrlCommandHandler.cs @@ -1,6 +1,7 @@ using Shortify.NET.Application.Abstractions; using Shortify.NET.Application.Abstractions.Repositories; using Shortify.NET.Application.Shared; +using Shortify.NET.Application.Shared.Models; using Shortify.NET.Common.FunctionalTypes; using Shortify.NET.Common.Messaging.Abstractions; using Shortify.NET.Core; @@ -102,11 +103,22 @@ private async Task SetCache( CancellationToken cancellationToken) { var cacheKey = $"{Constant.Cache.Prefixes.OriginalUrls}{shortenedUrl.Code}"; + var cacheItem = new ShortenedUrlDto( + shortenedUrl.Id, + shortenedUrl.UserId, + shortenedUrl.OriginalUrl, + shortenedUrl.ShortUrl.Value, + shortenedUrl.Code, + shortenedUrl.Title, + shortenedUrl.Tags, + shortenedUrl.CreatedOnUtc, + shortenedUrl.UpdatedOnUtc, + shortenedUrl.RowStatus); await _cachingServices .SetAsync( - cacheKey, - shortenedUrl.OriginalUrl, + cacheKey, + cacheItem, cancellationToken: cancellationToken, slidingExpiration: TimeSpan.FromDays(1)); } diff --git a/Shortify.NET.Application/Url/Commands/UpdateUrl/UpdateShortenedUrlCommand.cs b/Shortify.NET.Application/Url/Commands/UpdateUrl/UpdateShortenedUrlCommand.cs index b23a538..d9b06fd 100644 --- a/Shortify.NET.Application/Url/Commands/UpdateUrl/UpdateShortenedUrlCommand.cs +++ b/Shortify.NET.Application/Url/Commands/UpdateUrl/UpdateShortenedUrlCommand.cs @@ -5,6 +5,7 @@ namespace Shortify.NET.Application.Url.Commands.UpdateUrl { public record UpdateShortenedUrlCommand( Guid Id, + string OriginalUrl, string? Title, List? Tags) : ICommand; diff --git a/Shortify.NET.Application/Url/Commands/UpdateUrl/UpdateShortenedUrlCommandHandler.cs b/Shortify.NET.Application/Url/Commands/UpdateUrl/UpdateShortenedUrlCommandHandler.cs index 83c91af..d1a4e5b 100644 --- a/Shortify.NET.Application/Url/Commands/UpdateUrl/UpdateShortenedUrlCommandHandler.cs +++ b/Shortify.NET.Application/Url/Commands/UpdateUrl/UpdateShortenedUrlCommandHandler.cs @@ -23,7 +23,7 @@ public async Task> Handle( if (url is null) return Result.Failure(DomainErrors.ShortenedUrl.ShortenedUrlNotFound); - url.Update(command.Title, command.Tags); + url.Update(command.OriginalUrl, command.Title, command.Tags); _shortenedUrlRepository.Update(url); await _unitOfWork.SaveChangesAsync(cancellationToken); diff --git a/Shortify.NET.Application/Url/Queries/GetAllShortenedUrls/GetShortenedUrlsQuery.cs b/Shortify.NET.Application/Url/Queries/GetAllShortenedUrls/GetShortenedUrlsQuery.cs index 9d90118..c4d9cd3 100644 --- a/Shortify.NET.Application/Url/Queries/GetAllShortenedUrls/GetShortenedUrlsQuery.cs +++ b/Shortify.NET.Application/Url/Queries/GetAllShortenedUrls/GetShortenedUrlsQuery.cs @@ -9,6 +9,8 @@ public record GetShortenedUrlsQuery( string? SearchTerm, string? SortColumn, string? SortOrder, + DateTime? FromDate, + DateTime? ToDate, int Page, int PageSize) : IQuery>; diff --git a/Shortify.NET.Application/Url/Queries/GetAllShortenedUrls/GetShortenedUrlsQueryHandler.cs b/Shortify.NET.Application/Url/Queries/GetAllShortenedUrls/GetShortenedUrlsQueryHandler.cs index e036a7b..bc1bec0 100644 --- a/Shortify.NET.Application/Url/Queries/GetAllShortenedUrls/GetShortenedUrlsQueryHandler.cs +++ b/Shortify.NET.Application/Url/Queries/GetAllShortenedUrls/GetShortenedUrlsQueryHandler.cs @@ -21,6 +21,8 @@ public async Task>> Handle(GetShortenedUrlsQue query.SearchTerm, query.SortColumn, query.SortOrder, + query.FromDate, + query.ToDate, query.Page, query.PageSize, cancellationToken); diff --git a/Shortify.NET.Core/Entites/ShortenedUrl.cs b/Shortify.NET.Core/Entites/ShortenedUrl.cs index 582a78d..40d20c1 100644 --- a/Shortify.NET.Core/Entites/ShortenedUrl.cs +++ b/Shortify.NET.Core/Entites/ShortenedUrl.cs @@ -81,9 +81,11 @@ public static ShortenedUrl Create( } public void Update( + string originalUrl, string? title, List? tags) { + this.OriginalUrl = originalUrl; this.Title = title; this.Tags = tags; } diff --git a/Shortify.NET.Persistence/Repository/ShortenedUrlRepository.cs b/Shortify.NET.Persistence/Repository/ShortenedUrlRepository.cs index 0295e34..d9e845e 100644 --- a/Shortify.NET.Persistence/Repository/ShortenedUrlRepository.cs +++ b/Shortify.NET.Persistence/Repository/ShortenedUrlRepository.cs @@ -87,6 +87,8 @@ public async Task IsCodeUniqueAsync(string code, CancellationToken cancell string? searchTerm, string? sortColumn, string? sortOrder, + DateTime? fromDate, + DateTime? toDate, int page, int pageSize, CancellationToken cancellationToken = default) @@ -105,6 +107,11 @@ public async Task IsCodeUniqueAsync(string code, CancellationToken cancell (url.Tags != null && url.Tags.Contains(searchTerm))); } + if (fromDate is not null && toDate is not null) + { + query = query.Where(url => url.CreatedOnUtc >= fromDate && url.CreatedOnUtc <= toDate); + } + var sortExpression = GetSortProperty(sortColumn); query = sortOrder?.ToLower() == SortOrder.Descending ? query.OrderByDescending(sortExpression)