public async Task HandleAsync(CreateIssue command) { if (!(await _projectRepository.ExistsAsync(command.ProjectId))) { throw new ProjectNotFoundException(command.ProjectId); } if (!string.IsNullOrEmpty(command.EpicId) && !(await _issueRepository.ExistsAsync(command.EpicId))) { throw new EpicNotFoundException(command.EpicId); } if (!await _projectsApiHttpClient.HasPermission(IssuePermissionKeys.CreateIssues, _appContext.Identity.Id, command.ProjectId)) { throw new ActionNotAllowedException(); } var issueCount = await _issueRepository.GetIssueCountOfProject(command.ProjectId); var issueId = $"{command.ProjectId}-{issueCount + 1}"; var issue = new Issue(issueId, command.Type, command.Status, command.Title, command.Description, command.StoryPoints, command.ProjectId, command.EpicId, null, command.Assignees, command.LinkedIssues, command.CreatedAt); await _issueRepository.AddAsync(issue); await _messageBroker.PublishAsync(new IssueCreated(issue.Id, issue.ProjectId)); await _historyService.SaveHistory(Issue.Empty, issue, HistoryTypes.Created); }
public async Task HandleAsync(IssueCreated @event) { if (!await _projectRepository.ExistsAsync(@event.ProjectId)) { throw new ProjectNotFoundException(@event.ProjectId); } if (await _issueRepository.ExistsAsync(@event.IssueId)) { throw new IssueAlreadyCreatedException(@event.IssueId); } var issue = new Issue(@event.IssueId, @event.ProjectId, null); await _issueRepository.AddAsync(issue); }
public async Task <ApiResponse <IssueDto> > CreateIssue(IssueDto dto) { try { var entityToAdd = _issueMapper.MapToEntity(dto); if (dto.MilestoneId.HasValue) { var mileStoneFoundResponse = await _mileStoneService.GetMileStoneById(dto.MilestoneId.Value); if (!mileStoneFoundResponse.IsSuccess) { return(mileStoneFoundResponse.ToFailed <IssueDto>()); } } var projectFindResponse = await _projectService.GetProjectByIdAsync(dto.ProjectId); if (!projectFindResponse.IsSuccess) { return(projectFindResponse.ToFailed <IssueDto>()); } entityToAdd.ProjectId = dto.ProjectId; entityToAdd.OpenedAt = _systemClock.UtcNow; entityToAdd.Status = Status.Open; entityToAdd = await _issueRepository.AddAsync(entityToAdd); if (entityToAdd != null) { return(new ApiResponse <IssueDto>(dto)); } _logger.LogWarning("Failed to create entity {0}", JsonConvert.SerializeObject(dto)); return(new ApiResponse <IssueDto>() { StatusCode = 400, IsSuccess = false, ResponseException = new ApiError(ErrorCode.IssueCreationFailed, ErrorCode.IssueCreationFailed.GetDescription()) }); } catch (Exception ex) { _logger.LogWarning(ex, "An error occured while creating new issue {0} ", JsonConvert.SerializeObject(dto)); return(ApiResponse <IssueDto> .InternalError()); } }