using GozareshgirProgramManager.Application._Common.Interfaces; using GozareshgirProgramManager.Application._Common.Models; using GozareshgirProgramManager.Domain._Common; using GozareshgirProgramManager.Domain._Common.Exceptions; using GozareshgirProgramManager.Domain.ProjectAgg.Enums; using GozareshgirProgramManager.Domain.ProjectAgg.Repositories; namespace GozareshgirProgramManager.Application.Modules.Projects.Commands.ApproveTaskSectionCompletion; public record ApproveTaskSectionCompletionCommand(Guid TaskSectionId, bool IsApproved) : IBaseCommand; public class ApproveTaskSectionCompletionCommandHandler : IBaseCommandHandler { private readonly ITaskSectionRepository _taskSectionRepository; private readonly IUnitOfWork _unitOfWork; private readonly IAuthHelper _authHelper; public ApproveTaskSectionCompletionCommandHandler( ITaskSectionRepository taskSectionRepository, IUnitOfWork unitOfWork, IAuthHelper authHelper) { _taskSectionRepository = taskSectionRepository; _unitOfWork = unitOfWork; _authHelper = authHelper; } public async Task Handle(ApproveTaskSectionCompletionCommand request, CancellationToken cancellationToken) { var currentUserId = _authHelper.GetCurrentUserId() ?? throw new UnAuthorizedException("کاربر احراز هو?ت نشده است"); var section = await _taskSectionRepository.GetByIdAsync(request.TaskSectionId, cancellationToken); if (section == null) { return OperationResult.NotFound("بخش مورد نظر ?افت نشد"); } if (section.Status != TaskSectionStatus.PendingForCompletion) { return OperationResult.Failure("فقط بخش‌ها?? که در انتظار تکم?ل هستند قابل تا??د ?ا رد هستند"); } if (request.IsApproved) { section.UpdateStatus(TaskSectionStatus.Completed); } else { section.UpdateStatus(TaskSectionStatus.Incomplete); } await _unitOfWork.SaveChangesAsync(cancellationToken); return OperationResult.Success(); } }