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