MyBookmark/Modules.Rating.Api/Commands/UnrateObjectCommand.cs
2024-10-21 01:52:41 +03:00

31 lines
917 B
C#

using MediatR;
using Modules.Rating.Api.Database.Entities;
using Modules.Rating.Api.Repositories;
namespace Modules.Rating.Api.Commands;
public class UnrateObjectCommand : IRequest<Unit>
{
public Guid ObjectId { get; set; }
public Guid SubjectId { get; set; }
}
public class UnrateObjectCommandHandler(RateRepository repository) : IRequestHandler<UnrateObjectCommand, Unit>
{
public async Task<Unit> Handle(UnrateObjectCommand request, CancellationToken cancellationToken)
{
//var key = new RateKey
//{
// ObjectId = request.ObjectId,
// SubjectId = request.SubjectId,
//};
//if (await repository.IsRateExists(key)) await repository.DeleteAsync(key);
await repository.DeleteAsync(new RateKey
{
ObjectId = request.ObjectId,
SubjectId = request.SubjectId,
});
return Unit.Value;
}
}