hn-dotnet/Application/CommentLink/CommentLinkCommandHandler.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
1.0 KiB
C#

using System;
using System.Threading;
using System.Threading.Tasks;
using HN.Domain;
using MediatR;
namespace HN.Application
{
public sealed class CommentLinkCommandHandler : IRequestHandler<CommentLinkCommand, Guid>
{
private readonly ILinkRepository _linkRepository;
private readonly ICommentRepository _commentRepository;
private readonly IExecutingUserProvider _executingUserProvider;
public CommentLinkCommandHandler(ILinkRepository linkRepository, ICommentRepository commentRepository, IExecutingUserProvider executingUserProvider)
{
_linkRepository = linkRepository;
_commentRepository = commentRepository;
_executingUserProvider = executingUserProvider;
}
public async Task<Guid> Handle(CommentLinkCommand request, CancellationToken cancellationToken)
{
var link = await _linkRepository.GetByIdAsync(request.LinkId);
var comment = link.AddComment(_executingUserProvider.GetCurrentUserId(), request.Content);
await _commentRepository.AddAsync(comment);
return comment.Id;
}
}
}