myhn/Application/CreateLink/CreateLinkCommandHandler.cs
2021-01-08 16:26:19 +01:00

31 lines
759 B
C#

using System.Threading;
using System;
using MediatR;
using System.Threading.Tasks;
using MyHN.Domain;
namespace MyHN.Application
{
public class CreateLinkCommandHandler : IRequestHandler<CreateLinkCommand, Guid>
{
private readonly ILinkRepository _repository;
private readonly IUserProvider _userProvider;
public CreateLinkCommandHandler(
ILinkRepository repository
, IUserProvider userProvider)
{
_repository = repository;
_userProvider = userProvider;
}
public async Task<Guid> Handle(CreateLinkCommand request, CancellationToken cancellationToken)
{
var link = new Link(request.Url, _userProvider.GetCurrentUserId());
await _repository.AddAsync(link);
return link.Id;
}
}
}