public async Task <Unit> Handle(DeleteRepoCommand request, CancellationToken cancellationToken) { var existingRepo = await _repoRepository.GetById(request.Id); if (existingRepo == null) { throw new Exception("Repository not found. Delete failed."); } await _repoRepository.Remove(request.Id); return(Unit.Value); }
public async Task <string> Handle(CreateRepoCommand request, CancellationToken cancellationToken) { var existingRepo = await _repoRepository.GetById(request.Repository.Id); if (existingRepo != null) { throw new Exception("Repository alreay exists. Creation failed."); } request.Repository.LastUpdated = DateTime.Now; await _repoRepository.Create(request.Repository); return(request.Repository.Id); }
public async Task <Unit> Handle(UpdateRepoCommand request, CancellationToken cancellationToken) { var existingRepo = await _repoRepository.GetById(request.Id); if (existingRepo == null) { throw new Exception("Repository not found. Update failed"); } request.Repository.Id = existingRepo.Id; request.Repository.LastUpdated = DateTime.Now; await _repoRepository.Update(existingRepo.Id, request.Repository); return(Unit.Value); }
public async Task <RepoDetailsDTO> Handle(GetRepoDetailsQuery request, CancellationToken cancellationToken) { var repo = await _repoRepository.GetById(request.Id); if (repo == null) { throw new Exception("Repository not found. Failed to get details."); } var repoDetails = _mapper.Map <Repository, RepoDetailsDTO>(repo); repoDetails.Owner = await _userRepository.GetRepoOwner(repo.Id); return(repoDetails); }