32 lines
806 B
C#
32 lines
806 B
C#
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using HN.Domain;
|
|
using MediatR;
|
|
|
|
namespace HN.Application
|
|
{
|
|
|
|
public class AddLinkCommandHandler : IRequestHandler<AddLinkCommand, Guid>
|
|
{
|
|
private readonly ILinkRepository _repository;
|
|
private readonly IExecutingUserProvider _executingUserProvider;
|
|
|
|
public AddLinkCommandHandler(ILinkRepository repository, IExecutingUserProvider executingUserProvider)
|
|
{
|
|
_repository = repository;
|
|
_executingUserProvider = executingUserProvider;
|
|
}
|
|
|
|
public async Task<Guid> Handle(AddLinkCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var link = Link.FromUrl(_executingUserProvider.GetCurrentUserId(), request.Url);
|
|
|
|
await this._repository.AddAsync(link);
|
|
|
|
return link.Id;
|
|
}
|
|
}
|
|
|
|
}
|