namespace Brizco.Repository.MartenHandlers.NewsFeeds; public class DeleteNewsFeedCommandHandler(IMartenRepositoryWrapper martenRepositoryWrapper, ICurrentUserService currentUserService) : IRequestHandler { public async Task Handle(DeleteNewsFeedCommand request, CancellationToken cancellationToken) { if (currentUserService.ComplexId == null) throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is null"); if (!Guid.TryParse(currentUserService.ComplexId, out Guid complexId)) throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is wrong"); var ent = await martenRepositoryWrapper.SetRepository().GetEntityAsync(request.Id, cancellationToken); if (ent.ComplexId != complexId) throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is wrong"); await martenRepositoryWrapper.SetRepository().RemoveEntityAsync(ent, cancellationToken); return true; } }