public async Task HandleAsync(UpdateIssue command)
        {
            var issue = await _issueRepository.GetAsync(command.IssueId);

            if (issue is null)
            {
                throw new IssueNotFoundException(command.IssueId);
            }

            if (!string.IsNullOrWhiteSpace(command.EpicId) && !(await _issueRepository.ExistsAsync(command.EpicId)))
            {
                throw new EpicNotFoundException(command.EpicId);
            }

            if (!await _projectsApiHttpClient.HasPermission(IssuePermissionKeys.EditIssues, _appContext.Identity.Id, issue.ProjectId))
            {
                throw new ActionNotAllowedException();
            }

            var newIssue = new Issue(issue.Id, command.Type, command.Status, command.Title, command.Description, command.StoryPoints, issue.ProjectId, command.EpicId, issue.SprintId, command.Assignees, command.LinkedIssues, issue.CreatedAt);
            await _issueRepository.UpdateAsync(newIssue);

            _logger.LogInformation($"Updated issue with id: {issue.Id}.");
            await _messageBroker.PublishAsync(new IssueUpdated(issue.Id));

            await _historyService.SaveHistory(issue, newIssue, HistoryTypes.Updated);
        }
        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(DeleteIssue command)
        {
            var issue = await _issueRepository.GetAsync(command.IssueId);

            if (issue is null)
            {
                throw new IssueNotFoundException(command.IssueId);
            }

            if (!await _projectsApiHttpClient.HasPermission(IssuePermissionKeys.DeleteIssues, _appContext.Identity.Id, issue.ProjectId))
            {
                throw new ActionNotAllowedException();
            }

            await _issueRepository.DeleteAsync(issue.Id);

            _logger.LogInformation($"Deleted issue with id: {issue.Id}.");
            await _messageBroker.PublishAsync(new IssueDeleted(issue.Id, issue.ProjectId));
        }