From 15f1c938f730a1aad5672d13c710f2cc64b292b7 Mon Sep 17 00:00:00 2001 From: mahan Date: Sat, 24 Jan 2026 14:02:18 +0330 Subject: [PATCH] add workflow controller --- .../TaskRevisionsByTaskSectionIdQuery.cs | 3 +- .../Queries/WorkflowList/WorkflowListQuery.cs | 62 +++++++++++++++++++ .../ProgramManager/WorkflowController.cs | 25 ++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Workflows/Queries/WorkflowList/WorkflowListQuery.cs create mode 100644 ServiceHost/Areas/Admin/Controllers/ProgramManager/WorkflowController.cs diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/TaskSectionRevision/Queries/TaskRevisionsByTaskSectionId/TaskRevisionsByTaskSectionIdQuery.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/TaskSectionRevision/Queries/TaskRevisionsByTaskSectionId/TaskRevisionsByTaskSectionIdQuery.cs index 9ee7ae0f..f8ff4ec0 100644 --- a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/TaskSectionRevision/Queries/TaskRevisionsByTaskSectionId/TaskRevisionsByTaskSectionIdQuery.cs +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/TaskSectionRevision/Queries/TaskRevisionsByTaskSectionId/TaskRevisionsByTaskSectionIdQuery.cs @@ -49,7 +49,8 @@ public class TaskRevisionsByTaskSectionIdQueryHandler : IBaseQueryHandler f.FileId).Distinct().ToList(); - var files = uploadedFiles.Where(f => itemFileIds.Contains(f.Id)) + var files = uploadedFiles + .Where(f => itemFileIds.Contains(f.Id)) .Select(file => new TaskRevisionsByTaskSectionIdItemFile() { Id = file.Id, diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Workflows/Queries/WorkflowList/WorkflowListQuery.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Workflows/Queries/WorkflowList/WorkflowListQuery.cs new file mode 100644 index 00000000..0087763e --- /dev/null +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/Workflows/Queries/WorkflowList/WorkflowListQuery.cs @@ -0,0 +1,62 @@ +using GozareshgirProgramManager.Application._Common.Interfaces; +using GozareshgirProgramManager.Application._Common.Models; +using GozareshgirProgramManager.Domain.ProjectAgg.Entities.Task.TaskSection; +using Microsoft.EntityFrameworkCore; + +namespace GozareshgirProgramManager.Application.Modules.Workflows.Queries.WorkflowList; + +public record WorkflowListResponse(ListItems); + +public class WorkflowListItem +{ + public string Title { get; set; } + public WorkflowType Type { get; set; } + public Guid EntityId { get; set; } +} + +public enum WorkflowType +{ + Rejected, + NotAssigned, + PendingForApproval, +} + +public record WorkflowListQuery():IBaseQuery; + +public class WorkflowListQueryHandler:IBaseQueryHandler +{ + private readonly IProgramManagerDbContext _context; + private readonly IAuthHelper _authHelper; + + public WorkflowListQueryHandler(IProgramManagerDbContext context, + IAuthHelper authHelper) + { + _context = context; + _authHelper = authHelper; + } + + public async Task> Handle(WorkflowListQuery request, CancellationToken cancellationToken) + { + var currentUserId =_authHelper.GetCurrentUserId(); + + var query = await (from revision in _context.TaskSectionRevisions + .Where(x=>x.Status == RevisionReviewStatus.Pending) + join taskSection in _context.TaskSections.Where(x => x.CurrentAssignedUserId == currentUserId) + on revision.TaskSectionId equals taskSection.Id + select new + { + taskSection, + revision + + }).ToListAsync(cancellationToken: cancellationToken); + + var workflowListItems = query.Select(x=>new WorkflowListItem() + { + EntityId = x.taskSection.Id, + Title = "برگشت از سمت مدیر", + Type = WorkflowType.Rejected + }).ToList(); + var res = new WorkflowListResponse(workflowListItems); + return OperationResult.Success(res); + } +} \ No newline at end of file diff --git a/ServiceHost/Areas/Admin/Controllers/ProgramManager/WorkflowController.cs b/ServiceHost/Areas/Admin/Controllers/ProgramManager/WorkflowController.cs new file mode 100644 index 00000000..0f2da3ef --- /dev/null +++ b/ServiceHost/Areas/Admin/Controllers/ProgramManager/WorkflowController.cs @@ -0,0 +1,25 @@ +using GozareshgirProgramManager.Application._Common.Models; +using GozareshgirProgramManager.Application.Modules.Workflows.Queries.WorkflowList; +using MediatR; +using Microsoft.AspNetCore.Mvc; +using ServiceHost.BaseControllers; + +namespace ServiceHost.Areas.Admin.Controllers.ProgramManager; + +public class WorkflowController:ProgramManagerBaseController +{ + private readonly IMediator _mediator; + + public WorkflowController(IMediator mediator) + { + _mediator = mediator; + } + + [HttpGet] + public async Task>> Get(WorkflowListQuery query) + { + var res = await _mediator.Send(query); + return res; + } + +} \ No newline at end of file