Api/Netina.Repository/Handlers/Reviews/DeleteReviewCommandHandler.cs

17 lines
727 B
C#

namespace Netina.Repository.Handlers.Reviews;
public class DeleteReviewCommandHandler(IRepositoryWrapper repositoryWrapper)
: IRequestHandler<DeleteReviewCommand, bool>
{
public async Task<bool> Handle(DeleteReviewCommand request, CancellationToken cancellationToken)
{
var review = await repositoryWrapper.SetRepository<Review>().TableNoTracking
.FirstOrDefaultAsync(r => r.Id == request.Id, cancellationToken);
if (review == null)
throw new AppException("Review not found", ApiResultStatusCode.NotFound);
repositoryWrapper.SetRepository<Review>().Delete(review);
await repositoryWrapper.SaveChangesAsync(cancellationToken);
return true;
}
}