Able to load the latest workflow template for editing

This commit is contained in:
Colin Dawson 2026-02-27 10:49:21 +00:00
parent 1d8004ccaa
commit e9616b18ee
4 changed files with 18 additions and 12 deletions

View File

@ -104,7 +104,7 @@ public interface IWorkflowTemplateManager
Task<PaginatedData<GetWorkflowTemplate>> GetWorkflowTemplatesAsync(Paging paging, CancellationToken cancellationToken);
Task<PaginatedData<GetWorkflowTemplateVersion>> GetWorkflowTemplateVersionsAsync(Paging paging, CancellationToken cancellationToken);
Task<GetWorkflowTemplateVersion?> GetWorkflowTemplateVersionAsync(GeneralIdRef generalIdRef, CancellationToken cancellationToken);
Task<GetWorkflowTemplateVersion?> GetWorkflowTemplateAsync(GeneralIdRef generalIdRef, CancellationToken cancellationToken);
Task EditTemplateVersion(AuditUserDetails auditUserDetails, EditWorkflowTemplateVersion template, CancellationToken cancellationToken);
Task PatchTemplateVersion(AuditUserDetails auditUserDetails, IGeneralIdRef templateId, PatchWorkflowTemplateVersion patchTemplate, CancellationToken cancellationToken);
Task PostTemplateVersion(AuditUserDetails auditUserDetails, CreateWorkflowTemplateVersion template, CancellationToken cancellationToken);

View File

@ -77,7 +77,7 @@ public class WorkflowTemplateController : ESuiteControllerBase
CancellationToken cancellationToken = default!
)
{
var result = await _workflowTemplateManager.GetWorkflowTemplateVersionAsync(generalIdRef, cancellationToken);
var result = await _workflowTemplateManager.GetWorkflowTemplateAsync(generalIdRef, cancellationToken);
return Ok(result);
}

View File

@ -165,7 +165,7 @@ public class WorkflowTemplateRepository : RepositoryBase, IWorkflowTemplateRepos
public IQueryable<e_suite.Database.Core.Tables.Workflow.WorkflowVersion> GetWorkflowVersions()
{
return DatabaseDbContext.WorkflowVersions;
return DatabaseDbContext.WorkflowVersions.Include( x => x.Domain);
}
public async Task EditWorkflowVersionAsync(AuditUserDetails auditUserDetails, e_suite.Database.Core.Tables.Workflow.WorkflowVersion workflowVersion, CancellationToken cancellationToken)

View File

@ -78,9 +78,13 @@ public class WorkflowTemplateManager : IWorkflowTemplateManager
};
}
public async Task<GetWorkflowTemplateVersion?> GetWorkflowTemplateVersionAsync(GeneralIdRef generalIdRef, CancellationToken cancellationToken)
public async Task<GetWorkflowTemplateVersion?> GetWorkflowTemplateAsync(GeneralIdRef generalIdRef, CancellationToken cancellationToken)
{
var dbWorkflowTemplate = await _workflowTemplateRepository.GetWorkflowVersions().FindByGeneralIdRefAsync(generalIdRef, cancellationToken) ?? throw new NotFoundException("Unable to find Workflow Version");
var workflow = await _workflowTemplateRepository.GetWorkflows().FindByGeneralIdRefAsync(generalIdRef, cancellationToken) ?? throw new NotFoundException("Unable to find Workflow");
var dbWorkflowTemplate = _workflowTemplateRepository.GetWorkflowVersions().Where(x => x.WorkflowId == workflow.Id).OrderByDescending( x => x.Version).First();
//var dbWorkflowTemplate = await _workflowTemplateRepository.GetWorkflowVersions().FindByGeneralIdRefAsync(generalIdRef, cancellationToken) ?? throw new NotFoundException("Unable to find Workflow Version");
//var workflowTemplate = _workflowConverter.DeserialiseFromDatabase(dbWorkflowTemplate);
return new GetWorkflowTemplateVersion(dbWorkflowTemplate);
@ -101,7 +105,7 @@ public class WorkflowTemplateManager : IWorkflowTemplateManager
version.Description = template.Description;
version.ActivityNameTemplate = template.ActivityNameTemplate;
version.Deleted = false;
version.Version = template.Version;
version.Version = template.Version+1;
version.Tasks = template.Tasks;
}, cancellationToken);
}
@ -142,7 +146,7 @@ public class WorkflowTemplateManager : IWorkflowTemplateManager
await _workflowTemplateRepository.AddWorkflow(auditUserDetails, workflow, cancellationToken);
var workflowDomain = await _domainRepository.GetDomainById(template.DomainId, cancellationToken);
var workflowDomain = await _domainRepository.GetDomainById(template.DomainId, cancellationToken) ?? throw new NotFoundException("Unable to find domain");
var dbWorkflowTemplate = new WorkflowVersion
{
@ -152,13 +156,15 @@ public class WorkflowTemplateManager : IWorkflowTemplateManager
Domain = workflowDomain,
Tasks = template.Tasks,
Workflow = workflow,
Version = 1
};
Workflow.Core.WorkflowVersion? workflowTemplate = _workflowConverter.DeserialiseFromDatabase(dbWorkflowTemplate);
if (workflowTemplate is null)
{
throw new InvalidDataException("The workflow template is not valid");
}
//This will attempt to parse the data onto the internal workflow structure.
//Workflow.Core.WorkflowVersion? workflowTemplate = _workflowConverter.DeserialiseFromDatabase(dbWorkflowTemplate);
//if (workflowTemplate is null)
//{
// throw new InvalidDataException("The workflow template is not valid");
//}
await _workflowTemplateRepository.AddWorkflowVersion(auditUserDetails, dbWorkflowTemplate, cancellationToken);