This commit is contained in:
SamSys
2026-01-07 12:18:45 +03:30
5 changed files with 45 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
using GozareshgirProgramManager.Application._Common.Interfaces;
using GozareshgirProgramManager.Application._Common.Models;
using GozareshgirProgramManager.Domain._Common;
using GozareshgirProgramManager.Domain.ProjectAgg.Enums;
using GozareshgirProgramManager.Domain.ProjectAgg.Repositories;
namespace GozareshgirProgramManager.Application.Modules.Projects.Commands.ChangeTaskPriority;
/// <summary>
/// Command to change a task priority.
/// </summary>
public record ChangeTaskPriorityCommand(Guid TaskId, TaskPriority Priority) : IBaseCommand;
public class ChangeTaskPriorityCommandHandler : IBaseCommandHandler<ChangeTaskPriorityCommand>
{
private readonly IProjectTaskRepository _taskRepository;
private readonly IUnitOfWork _unitOfWork;
public ChangeTaskPriorityCommandHandler(IProjectTaskRepository taskRepository, IUnitOfWork unitOfWork)
{
_taskRepository = taskRepository;
_unitOfWork = unitOfWork;
}
public async Task<OperationResult> Handle(ChangeTaskPriorityCommand request, CancellationToken cancellationToken)
{
var task = await _taskRepository.GetByIdAsync(request.TaskId, cancellationToken);
if (task is null)
return OperationResult.NotFound("تسک یافت نشد");
// Idempotent: if already same priority, skip extra work
if (task.Priority != request.Priority)
{
task.SetPriority(request.Priority);
}
await _unitOfWork.SaveChangesAsync(cancellationToken);
return OperationResult.Success();
}
}

View File

@@ -189,6 +189,7 @@ public class GetProjectsListQueryHandler : IBaseQueryHandler<GetProjectsListQuer
SpentTime = spentTime,
RemainingTime = remainingTime,
Sections = sectionDtos,
Priority = task.Priority
});
}
return result;

View File

@@ -15,6 +15,7 @@ public class GetTaskDto
// Task-specific fields
public TimeSpan SpentTime { get; init; }
public TimeSpan RemainingTime { get; init; }
public TaskPriority Priority { get; set; }
public List<GetTaskSectionDto> Sections { get; init; }
}

View File

@@ -19,6 +19,7 @@ public class TaskSectionRepository:RepositoryBase<Guid,TaskSection>,ITaskSection
{
return await _context.TaskSections
.Include(x => x.Activities)
.Include(x=>x.AdditionalTimes)
.FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
}

View File

@@ -22,6 +22,7 @@ using GozareshgirProgramManager.Application.Modules.Projects.Queries.GetProjectH
using MediatR;
using Microsoft.AspNetCore.Mvc;
using ServiceHost.BaseControllers;
using GozareshgirProgramManager.Application.Modules.Projects.Commands.ChangeTaskPriority;
namespace ServiceHost.Areas.Admin.Controllers.ProgramManager;