Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Shortify.NET.API/Contracts/UpdateShortenedUrlRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
public record UpdateShortenedUrlRequest(
Guid Id,
string OriginalUrl,
string? Title,
List<string>? Tags);
}
15 changes: 15 additions & 0 deletions Shortify.NET.API/Controllers/V1/ShortController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public async Task<IActionResult> RedirectUrl(string code, CancellationToken canc
/// <param name="searchTerm">Search term can be the Title or any Tag or a fraction of them. Nullable.</param>
/// <param name="sortColumn">Column to Sort the response on. Nullable. Default sort will be on Id.</param>
/// <param name="sortOrder">Can be "desc" or null. Default is ascending.</param>
/// <param name="fromDate">Starting Range of CreatedOnUtc for filtering. Nullable.</param>
/// <param name="toDate">Ending Range of CreatedOnUtc for filtering. Nullable.</param>
/// <param name="page">Page No. Mandatory.</param>
/// <param name="pageSize">Page Size. Mandatory.</param>
/// <param name="cancellationToken">The cancellation token.</param>
Expand All @@ -128,6 +130,8 @@ public async Task<IActionResult> GetShortenedUrls(
string? searchTerm,
string? sortColumn,
string? sortOrder,
DateTime? fromDate,
DateTime? toDate,
int page,
int pageSize,
CancellationToken cancellationToken = default)
Expand All @@ -144,6 +148,8 @@ public async Task<IActionResult> GetShortenedUrls(
SearchTerm: searchTerm,
SortColumn: sortColumn,
SortOrder: sortOrder,
FromDate: fromDate,
ToDate: toDate,
Page: page,
PageSize: pageSize);

Expand Down Expand Up @@ -263,6 +269,15 @@ public async Task<IActionResult> 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);

Expand Down
4 changes: 2 additions & 2 deletions Shortify.NET.API/wwwroot/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@
<h1>This link or QR Code is invalid</h1>
<p>
The link you're trying to access is not a valid one.
Use <a href="https://shortify.net">Shortify.NET</a> to create and manage short links, QR codes, and landing
Use <a href="https://shortify-net.web.app">Shortify.NET</a> to create and manage short links, QR codes, and landing
pages.
</p>
<p>
Visit <a href="https://shortify.net">Shortify.NET</a> to learn more and get started today.
Visit <a href="https://shortify-net.web.app">Shortify.NET</a> to learn more and get started today.
</p>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions Shortify.NET.API/wwwroot/410.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@
<h1>This link or QR Code has been deactivated</h1>
<p>
The link you're trying to access is no longer active.
Use <a href="https://shortify.net">Shortify.NET</a> to create and manage short links, QR codes, and landing
Use <a href="https://shortify-net.web.app">Shortify.NET</a> to create and manage short links, QR codes, and landing
pages.
</p>
<p>
Visit <a href="https://shortify.net">Shortify.NET</a> to learn more and get started today.
Visit <a href="https://shortify-net.web.app">Shortify.NET</a> to learn more and get started today.
</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@

Task<ShortenedUrl?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default);

Task<ShortenedUrl?> GetLatestByUserIdAsync(Guid userId, CancellationToken cancellationToken = default);

Check notice on line 12 in Shortify.NET.Application/Abstractions/Repositories/IShortenedUrlRepository.cs

View workflow job for this annotation

GitHub Actions / Qodana Community for .NET

Type member is never used: Non-private accessibility

Method 'GetLatestByUserIdAsync' is never used

Task<ShortenedUrl?> GetByCodeAsync(string code, CancellationToken cancellationToken = default);

Task<List<ShortenedUrl>?> GetAllByUserIdAsync(Guid userId, CancellationToken cancellationToken = default);

Check notice on line 16 in Shortify.NET.Application/Abstractions/Repositories/IShortenedUrlRepository.cs

View workflow job for this annotation

GitHub Actions / Qodana Community for .NET

Type member is never used: Non-private accessibility

Method 'GetAllByUserIdAsync' is never used

Task<PagedList<ShortenedUrl>?> GetByIdWithFilterAndSort(
Guid id,
string? searchTerm,
string? sortColumn,
string? sortOrder,
string? sortOrder,
DateTime? fromDate,
DateTime? toDate,
int page,
int pageSize,
CancellationToken cancellationToken = default);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Shortify.NET.Application.Url.Commands.UpdateUrl
{
public record UpdateShortenedUrlCommand(
Guid Id,
string OriginalUrl,
string? Title,
List<string>? Tags)
: ICommand<ShortenedUrlDto>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
IUnitOfWork unitOfWork)
: ICommandHandler<UpdateShortenedUrlCommand, ShortenedUrlDto>
{
private readonly IShortenedUrlRepository _shortenedUrlRepository = shortenedUrlRepository;

Check notice on line 15 in Shortify.NET.Application/Url/Commands/UpdateUrl/UpdateShortenedUrlCommandHandler.cs

View workflow job for this annotation

GitHub Actions / Qodana Community for .NET

Replace with primary constructor parameter

Replace with primary constructor parameter
private readonly IUnitOfWork _unitOfWork = unitOfWork;

Check notice on line 16 in Shortify.NET.Application/Url/Commands/UpdateUrl/UpdateShortenedUrlCommandHandler.cs

View workflow job for this annotation

GitHub Actions / Qodana Community for .NET

Replace with primary constructor parameter

Replace with primary constructor parameter

public async Task<Result<ShortenedUrlDto>> Handle(
UpdateShortenedUrlCommand command,
Expand All @@ -23,7 +23,7 @@

if (url is null) return Result.Failure<ShortenedUrlDto>(DomainErrors.ShortenedUrl.ShortenedUrlNotFound);

url.Update(command.Title, command.Tags);
url.Update(command.OriginalUrl, command.Title, command.Tags);
_shortenedUrlRepository.Update(url);
await _unitOfWork.SaveChangesAsync(cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public record GetShortenedUrlsQuery(
string? SearchTerm,
string? SortColumn,
string? SortOrder,
DateTime? FromDate,
DateTime? ToDate,
int Page,
int PageSize)
: IQuery<PagedList<ShortenedUrlDto>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
internal sealed class GetShortenedUrlsQueryHandler(IShortenedUrlRepository shortenedUrlRepository)
: IQueryHandler<GetShortenedUrlsQuery, PagedList<ShortenedUrlDto>>
{
private readonly IShortenedUrlRepository _shortenedUrlRepository = shortenedUrlRepository;

Check notice on line 12 in Shortify.NET.Application/Url/Queries/GetAllShortenedUrls/GetShortenedUrlsQueryHandler.cs

View workflow job for this annotation

GitHub Actions / Qodana Community for .NET

Replace with primary constructor parameter

Replace with primary constructor parameter

public async Task<Result<PagedList<ShortenedUrlDto>>> Handle(GetShortenedUrlsQuery query, CancellationToken cancellationToken)
{
Expand All @@ -21,6 +21,8 @@
query.SearchTerm,
query.SortColumn,
query.SortOrder,
query.FromDate,
query.ToDate,
query.Page,
query.PageSize,
cancellationToken);
Expand Down
2 changes: 2 additions & 0 deletions Shortify.NET.Core/Entites/ShortenedUrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ public static ShortenedUrl Create(
}

public void Update(
string originalUrl,
string? title,
List<string>? tags)
{
this.OriginalUrl = originalUrl;
this.Title = title;
this.Tags = tags;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class ShortenedUrlRepository(AppDbContext context)
: IShortenedUrlRepository
{
private readonly AppDbContext _appDbContext = context;

Check notice on line 13 in Shortify.NET.Persistence/Repository/ShortenedUrlRepository.cs

View workflow job for this annotation

GitHub Actions / Qodana Community for .NET

Replace with primary constructor parameter

Replace with primary constructor parameter

#region Private Methods

Expand Down Expand Up @@ -87,6 +87,8 @@
string? searchTerm,
string? sortColumn,
string? sortOrder,
DateTime? fromDate,
DateTime? toDate,
int page,
int pageSize,
CancellationToken cancellationToken = default)
Expand All @@ -105,6 +107,11 @@
(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)
Expand Down
Loading