hn-dotnet/Application/AddLink/AddLinkCommandHandler.cs
Julien Leicher 3cd5133f66 add-aspnet-identity (#26)
add exception filter when user not connected
default to needing authentication and apply anonymous to some actions
add user in get requests
add user relation in link, comment and vote
signup and in are ok now!
2020-12-11 17:59:35 +01:00

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;
}
}
}