diff --git a/e-suite.API.Common/e-suite.API.Common/AssignmentDetails.cs b/e-suite.API.Common/e-suite.API.Common/AssignmentDetails.cs new file mode 100644 index 0000000..f9a9188 --- /dev/null +++ b/e-suite.API.Common/e-suite.API.Common/AssignmentDetails.cs @@ -0,0 +1,89 @@ +using e_suite.Database.Core.Extensions; +using e_suite.Database.Core.Models; +using e_suite.Database.Core.Tables.Activity; +using eSuite.Core.Miscellaneous; +using eSuite.Core.Workflow; + +namespace e_suite.API.Common; + +public class GetAssignment : IGeneralId +{ + public GetAssignment() + { + + } + + public GetAssignment(ActivityAssignment assignment) + { + Id = assignment.Id; + Guid = assignment.Guid; + StartDateTime = assignment.StartDateTime; + Raci = assignment.Raci; + AllowNoVerdict = assignment.AllowNoVerdict; + Outcomes = assignment.Outcomes; + RoleId = assignment.Role.ToGeneralIdRef(); + UserId = assignment.User.ToGeneralIdRef(); + Comments = assignment.Comments; + } + public long Id { get; set; } + public Guid Guid { get; set; } + public DateTimeOffset? StartDateTime { get; set; } + public Raci Raci { get; set; } + public bool AllowNoVerdict { get; set; } + public List Outcomes { get; set; } + public GeneralIdRef? RoleId { get; set; } + public GeneralIdRef? UserId { get; set; } + public string Comments { get; set; } +} + +public class GetTask : IGeneralId +{ + public GetTask() + { + + } + + public GetTask(ActivityTask task) + { + Id = task.Id; + Guid = task.Guid; + TaskName = task.TaskName; + TaskType = task.TaskType; + TaskGuid = task.TaskGuid; + } + + public long Id { get; set; } + public Guid Guid { get; set; } + public string TaskName { get; set; } + public string TaskType { get; set; } + public Guid TaskGuid { get; set; } +} + +public class GetActivity : IGeneralId +{ + public GetActivity() + { + + } + + public GetActivity(Activity activity) + { + Id = activity.Id; + Guid = activity.Guid; + Name = activity.Name; + WorkflowVersionId = activity.WorkflowVersionId; + } + + public long Id { get; set; } + public Guid Guid { get; set; } + public string Name { get; set; } + public long WorkflowVersionId { get; set; } +} + +public class AssignmentDetails +{ + public GetAssignment Assignment { get; set; } + public GetTask Task { get; set; } + public object Activity { get; set; } + public GetWorkflowTemplateVersion WorkflowTemplateVersion { get; set; } +} \ No newline at end of file diff --git a/e-suite.API.Common/e-suite.API.Common/GetMyAssignments.cs b/e-suite.API.Common/e-suite.API.Common/GetMyAssignments.cs index 5e9f8c9..f6c804f 100644 --- a/e-suite.API.Common/e-suite.API.Common/GetMyAssignments.cs +++ b/e-suite.API.Common/e-suite.API.Common/GetMyAssignments.cs @@ -1,5 +1,4 @@ -using System.Diagnostics; -using e_suite.Database.Core.Extensions; +using e_suite.Database.Core.Extensions; using e_suite.Database.Core.Models; using eSuite.Core.Miscellaneous; @@ -31,5 +30,4 @@ public class GetMyAssignments : IGeneralId public GeneralIdRef? Role { get; set; } public DateTimeOffset? StartDateTime { get; set; } - } \ No newline at end of file diff --git a/e-suite.API.Common/e-suite.API.Common/IActivityManager.cs b/e-suite.API.Common/e-suite.API.Common/IActivityManager.cs index 933857c..cccaf55 100644 --- a/e-suite.API.Common/e-suite.API.Common/IActivityManager.cs +++ b/e-suite.API.Common/e-suite.API.Common/IActivityManager.cs @@ -1,5 +1,6 @@ using e_suite.Database.Audit; using e_suite.Utilities.Pagination; +using eSuite.Core.Miscellaneous; namespace e_suite.API.Common; @@ -7,4 +8,5 @@ public interface IActivityManager { Task CreateActivity(AuditUserDetails auditUserDetails, CreateActivity template, CancellationToken cancellationToken); Task> GetMyActiveAssignmentsAsync(AuditUserDetails auditUserDetails, Paging paging, CancellationToken cancellationToken); + Task GetAssignmentDetails(AuditUserDetails auditUserDetails, GeneralIdRef assignmentId, CancellationToken cancellationToken); } \ No newline at end of file diff --git a/e-suite.API/eSuite.API/Controllers/TasksController.cs b/e-suite.API/eSuite.API/Controllers/TasksController.cs index b87148b..3f6b69d 100644 --- a/e-suite.API/eSuite.API/Controllers/TasksController.cs +++ b/e-suite.API/eSuite.API/Controllers/TasksController.cs @@ -2,6 +2,7 @@ using e_suite.Utilities.Pagination; using eSuite.API.security; using eSuite.API.Utilities; +using eSuite.Core.Miscellaneous; using eSuite.Core.Security; using Microsoft.AspNetCore.Mvc; @@ -24,7 +25,7 @@ public class TasksController : ESuiteControllerBase /// - /// Get a list of workflow templates + /// Get my current assignments /// /// /// @@ -41,4 +42,23 @@ public class TasksController : ESuiteControllerBase var result = await _activityManager.GetMyActiveAssignmentsAsync(AuditUserDetails, paging, cancellationToken); return Ok(result); } + + /// + /// Get the details of an assignment + /// + /// + /// + /// + /// + [Route("getAssignmentDetails")] + [AccessKey(SecurityAccess.ViewTasks)] + [HttpGet] + public async Task GetAssignmentDetails( [FromQuery] GeneralIdRef assignmentId, CancellationToken cancellationToken = default! + ) + { + var result = await _activityManager.GetAssignmentDetails(AuditUserDetails, assignmentId, cancellationToken); + return Ok(result); + } + + } \ No newline at end of file diff --git a/e-suite.Modules.RunningActivityManager/ActivityManager.cs b/e-suite.Modules.RunningActivityManager/ActivityManager.cs index 745e39f..e5aa31f 100644 --- a/e-suite.Modules.RunningActivityManager/ActivityManager.cs +++ b/e-suite.Modules.RunningActivityManager/ActivityManager.cs @@ -1,15 +1,15 @@ using e_suite.API.Common; +using e_suite.API.Common.exceptions; using e_suite.API.Common.repository; using e_suite.Database.Audit; using e_suite.Database.Core.Extensions; using e_suite.Database.Core.Tables.Activity; using e_suite.Messaging.Common; using e_suite.Utilities.Pagination; +using eSuite.Core.Enums; using eSuite.Core.Miscellaneous; using Microsoft.EntityFrameworkCore; using System.Linq.Expressions; -using System.Runtime.CompilerServices; -using eSuite.Core.Enums; namespace e_suite.Modules.RunningActivityManager; @@ -68,7 +68,7 @@ public class ActivityManager : IActivityManager return paginatedData; } - + private Expression> MyActiveAssignmentsKeySelector(string sortKey) { return sortKey?.ToLowerInvariant() switch @@ -80,4 +80,34 @@ public class ActivityManager : IActivityManager _ => x => x.Id }; } + + public async Task GetAssignmentDetails( + AuditUserDetails auditUserDetails, + GeneralIdRef assignmentId, + CancellationToken cancellationToken + ) + { + var assignment = await _activityRepository.GetAssignments().FindByGeneralIdRefAsync(assignmentId, cancellationToken); + if (assignment == null) + throw new NotFoundException("Unable to find assignment"); + + + + var assignmentObject = new GetAssignment(assignment); + + var taskObject = new GetTask(assignment.Task); + + var activityObject = new GetActivity(assignment.Task.Activity); + + var dbWorkflowTemplate = _workflowTemplateRepository.GetWorkflowVersions().Single(x => x.Id == activityObject.WorkflowVersionId); + + return new AssignmentDetails + { + Assignment = assignmentObject, + Task = taskObject, + Activity = activityObject, + WorkflowTemplateVersion = new GetWorkflowTemplateVersion(dbWorkflowTemplate) + //todo add the assignment metadata (outcomes) + }; + } } \ No newline at end of file diff --git a/e-suite.Modules.RunningActivityManager/repository/ActivityRepository.cs b/e-suite.Modules.RunningActivityManager/repository/ActivityRepository.cs index bc2537d..c4f7297 100644 --- a/e-suite.Modules.RunningActivityManager/repository/ActivityRepository.cs +++ b/e-suite.Modules.RunningActivityManager/repository/ActivityRepository.cs @@ -68,4 +68,5 @@ public class ActivityRepository : RepositoryBase, IActivityRepository .Include(x => x.Task) .ThenInclude( x => x.Activity); } + } \ No newline at end of file diff --git a/e-suite.Modules.WorkflowTemplatesManager/WorkflowTemplateManager.cs b/e-suite.Modules.WorkflowTemplatesManager/WorkflowTemplateManager.cs index 07da1b7..ffa3c8d 100644 --- a/e-suite.Modules.WorkflowTemplatesManager/WorkflowTemplateManager.cs +++ b/e-suite.Modules.WorkflowTemplatesManager/WorkflowTemplateManager.cs @@ -82,9 +82,6 @@ public class WorkflowTemplateManager : IWorkflowTemplateManager 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); }