In progress
This commit is contained in:
@@ -7,8 +7,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MediatR" Version="11.1.0" />
|
||||
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="11.1.0" />
|
||||
<PackageReference Include="MediatR" Version="13.1.0" />
|
||||
<PackageReference Include="FluentValidation" Version="11.10.0" />
|
||||
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.10.0" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.AssignStory;
|
||||
|
||||
/// <summary>
|
||||
/// Command to assign a Story to a user
|
||||
/// </summary>
|
||||
public sealed record AssignStoryCommand : IRequest<StoryDto>
|
||||
{
|
||||
public Guid StoryId { get; init; }
|
||||
public Guid AssigneeId { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Repositories;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.ValueObjects;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Exceptions;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.AssignStory;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for AssignStoryCommand
|
||||
/// </summary>
|
||||
public sealed class AssignStoryCommandHandler : IRequestHandler<AssignStoryCommand, StoryDto>
|
||||
{
|
||||
private readonly IProjectRepository _projectRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public AssignStoryCommandHandler(
|
||||
IProjectRepository projectRepository,
|
||||
IUnitOfWork unitOfWork)
|
||||
{
|
||||
_projectRepository = projectRepository ?? throw new ArgumentNullException(nameof(projectRepository));
|
||||
_unitOfWork = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
|
||||
}
|
||||
|
||||
public async Task<StoryDto> Handle(AssignStoryCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Get the project with story
|
||||
var storyId = StoryId.From(request.StoryId);
|
||||
var project = await _projectRepository.GetProjectWithStoryAsync(storyId, cancellationToken);
|
||||
|
||||
if (project == null)
|
||||
throw new NotFoundException("Story", request.StoryId);
|
||||
|
||||
// Find the story
|
||||
var story = project.Epics
|
||||
.SelectMany(e => e.Stories)
|
||||
.FirstOrDefault(s => s.Id.Value == request.StoryId);
|
||||
|
||||
if (story == null)
|
||||
throw new NotFoundException("Story", request.StoryId);
|
||||
|
||||
// Assign to user
|
||||
var assigneeId = UserId.From(request.AssigneeId);
|
||||
story.AssignTo(assigneeId);
|
||||
|
||||
// Save changes
|
||||
_projectRepository.Update(project);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
|
||||
// Map to DTO
|
||||
return new StoryDto
|
||||
{
|
||||
Id = story.Id.Value,
|
||||
Title = story.Title,
|
||||
Description = story.Description,
|
||||
EpicId = story.EpicId.Value,
|
||||
Status = story.Status.Name,
|
||||
Priority = story.Priority.Name,
|
||||
AssigneeId = story.AssigneeId?.Value,
|
||||
EstimatedHours = story.EstimatedHours,
|
||||
ActualHours = story.ActualHours,
|
||||
CreatedBy = story.CreatedBy.Value,
|
||||
CreatedAt = story.CreatedAt,
|
||||
UpdatedAt = story.UpdatedAt,
|
||||
Tasks = story.Tasks.Select(t => new TaskDto
|
||||
{
|
||||
Id = t.Id.Value,
|
||||
Title = t.Title,
|
||||
Description = t.Description,
|
||||
StoryId = t.StoryId.Value,
|
||||
Status = t.Status.Name,
|
||||
Priority = t.Priority.Name,
|
||||
AssigneeId = t.AssigneeId?.Value,
|
||||
EstimatedHours = t.EstimatedHours,
|
||||
ActualHours = t.ActualHours,
|
||||
CreatedBy = t.CreatedBy.Value,
|
||||
CreatedAt = t.CreatedAt,
|
||||
UpdatedAt = t.UpdatedAt
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.AssignStory;
|
||||
|
||||
/// <summary>
|
||||
/// Validator for AssignStoryCommand
|
||||
/// </summary>
|
||||
public sealed class AssignStoryCommandValidator : AbstractValidator<AssignStoryCommand>
|
||||
{
|
||||
public AssignStoryCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.StoryId)
|
||||
.NotEmpty().WithMessage("Story ID is required");
|
||||
|
||||
RuleFor(x => x.AssigneeId)
|
||||
.NotEmpty().WithMessage("Assignee ID is required");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.AssignTask;
|
||||
|
||||
/// <summary>
|
||||
/// Command to assign a Task to a user
|
||||
/// </summary>
|
||||
public sealed record AssignTaskCommand : IRequest<TaskDto>
|
||||
{
|
||||
public Guid TaskId { get; init; }
|
||||
public Guid? AssigneeId { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Repositories;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.ValueObjects;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Exceptions;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.AssignTask;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for AssignTaskCommand
|
||||
/// </summary>
|
||||
public sealed class AssignTaskCommandHandler : IRequestHandler<AssignTaskCommand, TaskDto>
|
||||
{
|
||||
private readonly IProjectRepository _projectRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public AssignTaskCommandHandler(
|
||||
IProjectRepository projectRepository,
|
||||
IUnitOfWork unitOfWork)
|
||||
{
|
||||
_projectRepository = projectRepository ?? throw new ArgumentNullException(nameof(projectRepository));
|
||||
_unitOfWork = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
|
||||
}
|
||||
|
||||
public async Task<TaskDto> Handle(AssignTaskCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Get the project containing the task
|
||||
var taskId = TaskId.From(request.TaskId);
|
||||
var project = await _projectRepository.GetProjectWithTaskAsync(taskId, cancellationToken);
|
||||
|
||||
if (project == null)
|
||||
throw new NotFoundException("Task", request.TaskId);
|
||||
|
||||
// Find the task within the project aggregate
|
||||
WorkTask? task = null;
|
||||
foreach (var epic in project.Epics)
|
||||
{
|
||||
foreach (var story in epic.Stories)
|
||||
{
|
||||
task = story.Tasks.FirstOrDefault(t => t.Id.Value == request.TaskId);
|
||||
if (task != null)
|
||||
break;
|
||||
}
|
||||
if (task != null)
|
||||
break;
|
||||
}
|
||||
|
||||
if (task == null)
|
||||
throw new NotFoundException("Task", request.TaskId);
|
||||
|
||||
// Assign task
|
||||
if (request.AssigneeId.HasValue)
|
||||
{
|
||||
var assigneeId = UserId.From(request.AssigneeId.Value);
|
||||
task.AssignTo(assigneeId);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unassign by setting to null - need to add this method to WorkTask
|
||||
task.AssignTo(null!);
|
||||
}
|
||||
|
||||
// Update project
|
||||
_projectRepository.Update(project);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
|
||||
// Map to DTO
|
||||
return new TaskDto
|
||||
{
|
||||
Id = task.Id.Value,
|
||||
Title = task.Title,
|
||||
Description = task.Description,
|
||||
StoryId = task.StoryId.Value,
|
||||
Status = task.Status.Name,
|
||||
Priority = task.Priority.Name,
|
||||
AssigneeId = task.AssigneeId?.Value,
|
||||
EstimatedHours = task.EstimatedHours,
|
||||
ActualHours = task.ActualHours,
|
||||
CreatedBy = task.CreatedBy.Value,
|
||||
CreatedAt = task.CreatedAt,
|
||||
UpdatedAt = task.UpdatedAt
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.AssignTask;
|
||||
|
||||
/// <summary>
|
||||
/// Validator for AssignTaskCommand
|
||||
/// </summary>
|
||||
public sealed class AssignTaskCommandValidator : AbstractValidator<AssignTaskCommand>
|
||||
{
|
||||
public AssignTaskCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.TaskId)
|
||||
.NotEmpty()
|
||||
.WithMessage("TaskId is required");
|
||||
}
|
||||
}
|
||||
@@ -46,8 +46,8 @@ public sealed class CreateEpicCommandHandler : IRequestHandler<CreateEpicCommand
|
||||
Name = epic.Name,
|
||||
Description = epic.Description,
|
||||
ProjectId = epic.ProjectId.Value,
|
||||
Status = epic.Status.Value,
|
||||
Priority = epic.Priority.Value,
|
||||
Status = epic.Status.Name,
|
||||
Priority = epic.Priority.Name,
|
||||
CreatedBy = epic.CreatedBy.Value,
|
||||
CreatedAt = epic.CreatedAt,
|
||||
UpdatedAt = epic.UpdatedAt,
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.CreateStory;
|
||||
|
||||
/// <summary>
|
||||
/// Command to create a new Story
|
||||
/// </summary>
|
||||
public sealed record CreateStoryCommand : IRequest<StoryDto>
|
||||
{
|
||||
public Guid EpicId { get; init; }
|
||||
public string Title { get; init; } = string.Empty;
|
||||
public string Description { get; init; } = string.Empty;
|
||||
public string Priority { get; init; } = "Medium";
|
||||
public Guid? AssigneeId { get; init; }
|
||||
public decimal? EstimatedHours { get; init; }
|
||||
public Guid CreatedBy { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Repositories;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.ValueObjects;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Exceptions;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.CreateStory;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for CreateStoryCommand
|
||||
/// </summary>
|
||||
public sealed class CreateStoryCommandHandler : IRequestHandler<CreateStoryCommand, StoryDto>
|
||||
{
|
||||
private readonly IProjectRepository _projectRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public CreateStoryCommandHandler(
|
||||
IProjectRepository projectRepository,
|
||||
IUnitOfWork unitOfWork)
|
||||
{
|
||||
_projectRepository = projectRepository ?? throw new ArgumentNullException(nameof(projectRepository));
|
||||
_unitOfWork = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
|
||||
}
|
||||
|
||||
public async Task<StoryDto> Handle(CreateStoryCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Get the project with epic
|
||||
var epicId = EpicId.From(request.EpicId);
|
||||
var project = await _projectRepository.GetProjectWithEpicAsync(epicId, cancellationToken);
|
||||
|
||||
if (project == null)
|
||||
throw new NotFoundException("Epic", request.EpicId);
|
||||
|
||||
// Find the epic
|
||||
var epic = project.Epics.FirstOrDefault(e => e.Id.Value == request.EpicId);
|
||||
if (epic == null)
|
||||
throw new NotFoundException("Epic", request.EpicId);
|
||||
|
||||
// Parse priority
|
||||
var priority = request.Priority switch
|
||||
{
|
||||
"Low" => TaskPriority.Low,
|
||||
"Medium" => TaskPriority.Medium,
|
||||
"High" => TaskPriority.High,
|
||||
"Urgent" => TaskPriority.Urgent,
|
||||
_ => TaskPriority.Medium
|
||||
};
|
||||
|
||||
// Create story through epic
|
||||
var createdById = UserId.From(request.CreatedBy);
|
||||
var story = epic.CreateStory(request.Title, request.Description, priority, createdById);
|
||||
|
||||
// Assign if assignee provided
|
||||
if (request.AssigneeId.HasValue)
|
||||
{
|
||||
var assigneeId = UserId.From(request.AssigneeId.Value);
|
||||
story.AssignTo(assigneeId);
|
||||
}
|
||||
|
||||
// Set estimated hours if provided
|
||||
if (request.EstimatedHours.HasValue)
|
||||
{
|
||||
story.UpdateEstimate(request.EstimatedHours.Value);
|
||||
}
|
||||
|
||||
// Update project (story is part of aggregate)
|
||||
_projectRepository.Update(project);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
|
||||
// Map to DTO
|
||||
return new StoryDto
|
||||
{
|
||||
Id = story.Id.Value,
|
||||
Title = story.Title,
|
||||
Description = story.Description,
|
||||
EpicId = story.EpicId.Value,
|
||||
Status = story.Status.Name,
|
||||
Priority = story.Priority.Name,
|
||||
AssigneeId = story.AssigneeId?.Value,
|
||||
EstimatedHours = story.EstimatedHours,
|
||||
ActualHours = story.ActualHours,
|
||||
CreatedBy = story.CreatedBy.Value,
|
||||
CreatedAt = story.CreatedAt,
|
||||
UpdatedAt = story.UpdatedAt,
|
||||
Tasks = new List<TaskDto>()
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.CreateStory;
|
||||
|
||||
/// <summary>
|
||||
/// Validator for CreateStoryCommand
|
||||
/// </summary>
|
||||
public sealed class CreateStoryCommandValidator : AbstractValidator<CreateStoryCommand>
|
||||
{
|
||||
public CreateStoryCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.EpicId)
|
||||
.NotEmpty().WithMessage("Epic ID is required");
|
||||
|
||||
RuleFor(x => x.Title)
|
||||
.NotEmpty().WithMessage("Story title is required")
|
||||
.MaximumLength(200).WithMessage("Story title cannot exceed 200 characters");
|
||||
|
||||
RuleFor(x => x.Priority)
|
||||
.NotEmpty().WithMessage("Priority is required")
|
||||
.Must(p => p == "Low" || p == "Medium" || p == "High" || p == "Urgent")
|
||||
.WithMessage("Priority must be one of: Low, Medium, High, Urgent");
|
||||
|
||||
RuleFor(x => x.EstimatedHours)
|
||||
.GreaterThanOrEqualTo(0).When(x => x.EstimatedHours.HasValue)
|
||||
.WithMessage("Estimated hours cannot be negative");
|
||||
|
||||
RuleFor(x => x.CreatedBy)
|
||||
.NotEmpty().WithMessage("Created by user ID is required");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.CreateTask;
|
||||
|
||||
/// <summary>
|
||||
/// Command to create a new Task
|
||||
/// </summary>
|
||||
public sealed record CreateTaskCommand : IRequest<TaskDto>
|
||||
{
|
||||
public Guid StoryId { get; init; }
|
||||
public string Title { get; init; } = string.Empty;
|
||||
public string Description { get; init; } = string.Empty;
|
||||
public string Priority { get; init; } = "Medium";
|
||||
public decimal? EstimatedHours { get; init; }
|
||||
public Guid? AssigneeId { get; init; }
|
||||
public Guid CreatedBy { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Repositories;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.ValueObjects;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Exceptions;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.CreateTask;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for CreateTaskCommand
|
||||
/// </summary>
|
||||
public sealed class CreateTaskCommandHandler : IRequestHandler<CreateTaskCommand, TaskDto>
|
||||
{
|
||||
private readonly IProjectRepository _projectRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public CreateTaskCommandHandler(
|
||||
IProjectRepository projectRepository,
|
||||
IUnitOfWork unitOfWork)
|
||||
{
|
||||
_projectRepository = projectRepository ?? throw new ArgumentNullException(nameof(projectRepository));
|
||||
_unitOfWork = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
|
||||
}
|
||||
|
||||
public async Task<TaskDto> Handle(CreateTaskCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Get the project containing the story
|
||||
var storyId = StoryId.From(request.StoryId);
|
||||
var project = await _projectRepository.GetProjectWithStoryAsync(storyId, cancellationToken);
|
||||
|
||||
if (project == null)
|
||||
throw new NotFoundException("Story", request.StoryId);
|
||||
|
||||
// Find the story within the project aggregate
|
||||
Story? story = null;
|
||||
foreach (var epic in project.Epics)
|
||||
{
|
||||
story = epic.Stories.FirstOrDefault(s => s.Id.Value == request.StoryId);
|
||||
if (story is not null)
|
||||
break;
|
||||
}
|
||||
|
||||
if (story is null)
|
||||
throw new NotFoundException("Story", request.StoryId);
|
||||
|
||||
// Parse priority
|
||||
var priority = TaskPriority.FromDisplayName<TaskPriority>(request.Priority);
|
||||
var createdById = UserId.From(request.CreatedBy);
|
||||
|
||||
// Create task through story aggregate
|
||||
var task = story.CreateTask(request.Title, request.Description, priority, createdById);
|
||||
|
||||
// Set optional fields
|
||||
if (request.EstimatedHours.HasValue)
|
||||
{
|
||||
task.UpdateEstimate(request.EstimatedHours.Value);
|
||||
}
|
||||
|
||||
if (request.AssigneeId.HasValue)
|
||||
{
|
||||
var assigneeId = UserId.From(request.AssigneeId.Value);
|
||||
task.AssignTo(assigneeId);
|
||||
}
|
||||
|
||||
// Update project (task is part of aggregate)
|
||||
_projectRepository.Update(project);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
|
||||
// Map to DTO
|
||||
return new TaskDto
|
||||
{
|
||||
Id = task.Id.Value,
|
||||
Title = task.Title,
|
||||
Description = task.Description,
|
||||
StoryId = task.StoryId.Value,
|
||||
Status = task.Status.Name,
|
||||
Priority = task.Priority.Name,
|
||||
AssigneeId = task.AssigneeId?.Value,
|
||||
EstimatedHours = task.EstimatedHours,
|
||||
ActualHours = task.ActualHours,
|
||||
CreatedBy = task.CreatedBy.Value,
|
||||
CreatedAt = task.CreatedAt,
|
||||
UpdatedAt = task.UpdatedAt
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.CreateTask;
|
||||
|
||||
/// <summary>
|
||||
/// Validator for CreateTaskCommand
|
||||
/// </summary>
|
||||
public sealed class CreateTaskCommandValidator : AbstractValidator<CreateTaskCommand>
|
||||
{
|
||||
public CreateTaskCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.StoryId)
|
||||
.NotEmpty()
|
||||
.WithMessage("StoryId is required");
|
||||
|
||||
RuleFor(x => x.Title)
|
||||
.NotEmpty()
|
||||
.WithMessage("Title is required")
|
||||
.MaximumLength(200)
|
||||
.WithMessage("Title cannot exceed 200 characters");
|
||||
|
||||
RuleFor(x => x.Description)
|
||||
.MaximumLength(5000)
|
||||
.WithMessage("Description cannot exceed 5000 characters");
|
||||
|
||||
RuleFor(x => x.Priority)
|
||||
.NotEmpty()
|
||||
.WithMessage("Priority is required")
|
||||
.Must(BeValidPriority)
|
||||
.WithMessage("Priority must be one of: Low, Medium, High, Urgent");
|
||||
|
||||
RuleFor(x => x.EstimatedHours)
|
||||
.GreaterThanOrEqualTo(0)
|
||||
.When(x => x.EstimatedHours.HasValue)
|
||||
.WithMessage("Estimated hours cannot be negative");
|
||||
|
||||
RuleFor(x => x.CreatedBy)
|
||||
.NotEmpty()
|
||||
.WithMessage("CreatedBy is required");
|
||||
}
|
||||
|
||||
private bool BeValidPriority(string priority)
|
||||
{
|
||||
var validPriorities = new[] { "Low", "Medium", "High", "Urgent" };
|
||||
return validPriorities.Contains(priority, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using MediatR;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.DeleteStory;
|
||||
|
||||
/// <summary>
|
||||
/// Command to delete a Story
|
||||
/// </summary>
|
||||
public sealed record DeleteStoryCommand : IRequest<Unit>
|
||||
{
|
||||
public Guid StoryId { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Repositories;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.ValueObjects;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Exceptions;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.DeleteStory;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for DeleteStoryCommand
|
||||
/// </summary>
|
||||
public sealed class DeleteStoryCommandHandler : IRequestHandler<DeleteStoryCommand, Unit>
|
||||
{
|
||||
private readonly IProjectRepository _projectRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public DeleteStoryCommandHandler(
|
||||
IProjectRepository projectRepository,
|
||||
IUnitOfWork unitOfWork)
|
||||
{
|
||||
_projectRepository = projectRepository ?? throw new ArgumentNullException(nameof(projectRepository));
|
||||
_unitOfWork = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(DeleteStoryCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Get the project with story
|
||||
var storyId = StoryId.From(request.StoryId);
|
||||
var project = await _projectRepository.GetProjectWithStoryAsync(storyId, cancellationToken);
|
||||
|
||||
if (project == null)
|
||||
throw new NotFoundException("Story", request.StoryId);
|
||||
|
||||
// Find the epic containing the story
|
||||
var epic = project.Epics.FirstOrDefault(e => e.Stories.Any(s => s.Id.Value == request.StoryId));
|
||||
if (epic == null)
|
||||
throw new NotFoundException("Story", request.StoryId);
|
||||
|
||||
// Remove story from epic (domain logic validates no tasks exist)
|
||||
epic.RemoveStory(storyId);
|
||||
|
||||
// Save changes
|
||||
_projectRepository.Update(project);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return Unit.Value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.DeleteStory;
|
||||
|
||||
/// <summary>
|
||||
/// Validator for DeleteStoryCommand
|
||||
/// </summary>
|
||||
public sealed class DeleteStoryCommandValidator : AbstractValidator<DeleteStoryCommand>
|
||||
{
|
||||
public DeleteStoryCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.StoryId)
|
||||
.NotEmpty().WithMessage("Story ID is required");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using MediatR;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.DeleteTask;
|
||||
|
||||
/// <summary>
|
||||
/// Command to delete a Task
|
||||
/// </summary>
|
||||
public sealed record DeleteTaskCommand : IRequest<Unit>
|
||||
{
|
||||
public Guid TaskId { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Repositories;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.ValueObjects;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Exceptions;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.DeleteTask;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for DeleteTaskCommand
|
||||
/// </summary>
|
||||
public sealed class DeleteTaskCommandHandler : IRequestHandler<DeleteTaskCommand, Unit>
|
||||
{
|
||||
private readonly IProjectRepository _projectRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public DeleteTaskCommandHandler(
|
||||
IProjectRepository projectRepository,
|
||||
IUnitOfWork unitOfWork)
|
||||
{
|
||||
_projectRepository = projectRepository ?? throw new ArgumentNullException(nameof(projectRepository));
|
||||
_unitOfWork = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(DeleteTaskCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Get the project containing the task
|
||||
var taskId = TaskId.From(request.TaskId);
|
||||
var project = await _projectRepository.GetProjectWithTaskAsync(taskId, cancellationToken);
|
||||
|
||||
if (project == null)
|
||||
throw new NotFoundException("Task", request.TaskId);
|
||||
|
||||
// Find the story containing the task
|
||||
Story? parentStory = null;
|
||||
foreach (var epic in project.Epics)
|
||||
{
|
||||
foreach (var story in epic.Stories)
|
||||
{
|
||||
var task = story.Tasks.FirstOrDefault(t => t.Id.Value == request.TaskId);
|
||||
if (task != null)
|
||||
{
|
||||
parentStory = story;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (parentStory != null)
|
||||
break;
|
||||
}
|
||||
|
||||
if (parentStory == null)
|
||||
throw new NotFoundException("Task", request.TaskId);
|
||||
|
||||
// Remove task from story
|
||||
parentStory.RemoveTask(taskId);
|
||||
|
||||
// Update project
|
||||
_projectRepository.Update(project);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return Unit.Value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.DeleteTask;
|
||||
|
||||
/// <summary>
|
||||
/// Validator for DeleteTaskCommand
|
||||
/// </summary>
|
||||
public sealed class DeleteTaskCommandValidator : AbstractValidator<DeleteTaskCommand>
|
||||
{
|
||||
public DeleteTaskCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.TaskId)
|
||||
.NotEmpty()
|
||||
.WithMessage("TaskId is required");
|
||||
}
|
||||
}
|
||||
@@ -50,8 +50,8 @@ public sealed class UpdateEpicCommandHandler : IRequestHandler<UpdateEpicCommand
|
||||
Name = epic.Name,
|
||||
Description = epic.Description,
|
||||
ProjectId = epic.ProjectId.Value,
|
||||
Status = epic.Status.Value,
|
||||
Priority = epic.Priority.Value,
|
||||
Status = epic.Status.Name,
|
||||
Priority = epic.Priority.Name,
|
||||
CreatedBy = epic.CreatedBy.Value,
|
||||
CreatedAt = epic.CreatedAt,
|
||||
UpdatedAt = epic.UpdatedAt,
|
||||
@@ -61,8 +61,8 @@ public sealed class UpdateEpicCommandHandler : IRequestHandler<UpdateEpicCommand
|
||||
Title = s.Title,
|
||||
Description = s.Description,
|
||||
EpicId = s.EpicId.Value,
|
||||
Status = s.Status.Value,
|
||||
Priority = s.Priority.Value,
|
||||
Status = s.Status.Name,
|
||||
Priority = s.Priority.Name,
|
||||
EstimatedHours = s.EstimatedHours,
|
||||
ActualHours = s.ActualHours,
|
||||
AssigneeId = s.AssigneeId?.Value,
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.UpdateStory;
|
||||
|
||||
/// <summary>
|
||||
/// Command to update an existing Story
|
||||
/// </summary>
|
||||
public sealed record UpdateStoryCommand : IRequest<StoryDto>
|
||||
{
|
||||
public Guid StoryId { get; init; }
|
||||
public string Title { get; init; } = string.Empty;
|
||||
public string Description { get; init; } = string.Empty;
|
||||
public string? Status { get; init; }
|
||||
public string? Priority { get; init; }
|
||||
public Guid? AssigneeId { get; init; }
|
||||
public decimal? EstimatedHours { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Repositories;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.ValueObjects;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Exceptions;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.UpdateStory;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for UpdateStoryCommand
|
||||
/// </summary>
|
||||
public sealed class UpdateStoryCommandHandler : IRequestHandler<UpdateStoryCommand, StoryDto>
|
||||
{
|
||||
private readonly IProjectRepository _projectRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public UpdateStoryCommandHandler(
|
||||
IProjectRepository projectRepository,
|
||||
IUnitOfWork unitOfWork)
|
||||
{
|
||||
_projectRepository = projectRepository ?? throw new ArgumentNullException(nameof(projectRepository));
|
||||
_unitOfWork = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
|
||||
}
|
||||
|
||||
public async Task<StoryDto> Handle(UpdateStoryCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Get the project with story
|
||||
var storyId = StoryId.From(request.StoryId);
|
||||
var project = await _projectRepository.GetProjectWithStoryAsync(storyId, cancellationToken);
|
||||
|
||||
if (project == null)
|
||||
throw new NotFoundException("Story", request.StoryId);
|
||||
|
||||
// Find the story
|
||||
var story = project.Epics
|
||||
.SelectMany(e => e.Stories)
|
||||
.FirstOrDefault(s => s.Id.Value == request.StoryId);
|
||||
|
||||
if (story == null)
|
||||
throw new NotFoundException("Story", request.StoryId);
|
||||
|
||||
// Update basic details
|
||||
story.UpdateDetails(request.Title, request.Description);
|
||||
|
||||
// Update status if provided
|
||||
if (!string.IsNullOrEmpty(request.Status))
|
||||
{
|
||||
var status = request.Status switch
|
||||
{
|
||||
"To Do" => WorkItemStatus.ToDo,
|
||||
"In Progress" => WorkItemStatus.InProgress,
|
||||
"In Review" => WorkItemStatus.InReview,
|
||||
"Done" => WorkItemStatus.Done,
|
||||
"Blocked" => WorkItemStatus.Blocked,
|
||||
_ => throw new DomainException($"Invalid status: {request.Status}")
|
||||
};
|
||||
story.UpdateStatus(status);
|
||||
}
|
||||
|
||||
// Update priority if provided
|
||||
if (!string.IsNullOrEmpty(request.Priority))
|
||||
{
|
||||
var priority = TaskPriority.FromDisplayName<TaskPriority>(request.Priority);
|
||||
story.UpdatePriority(priority);
|
||||
}
|
||||
|
||||
// Update assignee if provided
|
||||
if (request.AssigneeId.HasValue)
|
||||
{
|
||||
var assigneeId = UserId.From(request.AssigneeId.Value);
|
||||
story.AssignTo(assigneeId);
|
||||
}
|
||||
|
||||
// Update estimated hours if provided
|
||||
if (request.EstimatedHours.HasValue)
|
||||
{
|
||||
story.UpdateEstimate(request.EstimatedHours.Value);
|
||||
}
|
||||
|
||||
// Save changes
|
||||
_projectRepository.Update(project);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
|
||||
// Map to DTO
|
||||
return new StoryDto
|
||||
{
|
||||
Id = story.Id.Value,
|
||||
Title = story.Title,
|
||||
Description = story.Description,
|
||||
EpicId = story.EpicId.Value,
|
||||
Status = story.Status.Name,
|
||||
Priority = story.Priority.Name,
|
||||
AssigneeId = story.AssigneeId?.Value,
|
||||
EstimatedHours = story.EstimatedHours,
|
||||
ActualHours = story.ActualHours,
|
||||
CreatedBy = story.CreatedBy.Value,
|
||||
CreatedAt = story.CreatedAt,
|
||||
UpdatedAt = story.UpdatedAt,
|
||||
Tasks = story.Tasks.Select(t => new TaskDto
|
||||
{
|
||||
Id = t.Id.Value,
|
||||
Title = t.Title,
|
||||
Description = t.Description,
|
||||
StoryId = t.StoryId.Value,
|
||||
Status = t.Status.Name,
|
||||
Priority = t.Priority.Name,
|
||||
AssigneeId = t.AssigneeId?.Value,
|
||||
EstimatedHours = t.EstimatedHours,
|
||||
ActualHours = t.ActualHours,
|
||||
CreatedBy = t.CreatedBy.Value,
|
||||
CreatedAt = t.CreatedAt,
|
||||
UpdatedAt = t.UpdatedAt
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.UpdateStory;
|
||||
|
||||
/// <summary>
|
||||
/// Validator for UpdateStoryCommand
|
||||
/// </summary>
|
||||
public sealed class UpdateStoryCommandValidator : AbstractValidator<UpdateStoryCommand>
|
||||
{
|
||||
public UpdateStoryCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.StoryId)
|
||||
.NotEmpty().WithMessage("Story ID is required");
|
||||
|
||||
RuleFor(x => x.Title)
|
||||
.NotEmpty().WithMessage("Story title is required")
|
||||
.MaximumLength(200).WithMessage("Story title cannot exceed 200 characters");
|
||||
|
||||
RuleFor(x => x.Status)
|
||||
.Must(s => s == null || s == "To Do" || s == "In Progress" || s == "In Review" || s == "Done" || s == "Blocked")
|
||||
.WithMessage("Status must be one of: To Do, In Progress, In Review, Done, Blocked");
|
||||
|
||||
RuleFor(x => x.Priority)
|
||||
.Must(p => p == null || p == "Low" || p == "Medium" || p == "High" || p == "Urgent")
|
||||
.WithMessage("Priority must be one of: Low, Medium, High, Urgent");
|
||||
|
||||
RuleFor(x => x.EstimatedHours)
|
||||
.GreaterThanOrEqualTo(0).When(x => x.EstimatedHours.HasValue)
|
||||
.WithMessage("Estimated hours cannot be negative");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.UpdateTask;
|
||||
|
||||
/// <summary>
|
||||
/// Command to update an existing Task
|
||||
/// </summary>
|
||||
public sealed record UpdateTaskCommand : IRequest<TaskDto>
|
||||
{
|
||||
public Guid TaskId { get; init; }
|
||||
public string Title { get; init; } = string.Empty;
|
||||
public string Description { get; init; } = string.Empty;
|
||||
public string? Priority { get; init; }
|
||||
public string? Status { get; init; }
|
||||
public decimal? EstimatedHours { get; init; }
|
||||
public Guid? AssigneeId { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Repositories;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.ValueObjects;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Exceptions;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.UpdateTask;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for UpdateTaskCommand
|
||||
/// </summary>
|
||||
public sealed class UpdateTaskCommandHandler : IRequestHandler<UpdateTaskCommand, TaskDto>
|
||||
{
|
||||
private readonly IProjectRepository _projectRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public UpdateTaskCommandHandler(
|
||||
IProjectRepository projectRepository,
|
||||
IUnitOfWork unitOfWork)
|
||||
{
|
||||
_projectRepository = projectRepository ?? throw new ArgumentNullException(nameof(projectRepository));
|
||||
_unitOfWork = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
|
||||
}
|
||||
|
||||
public async Task<TaskDto> Handle(UpdateTaskCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Get the project containing the task
|
||||
var taskId = TaskId.From(request.TaskId);
|
||||
var project = await _projectRepository.GetProjectWithTaskAsync(taskId, cancellationToken);
|
||||
|
||||
if (project == null)
|
||||
throw new NotFoundException("Task", request.TaskId);
|
||||
|
||||
// Find the task within the project aggregate
|
||||
WorkTask? task = null;
|
||||
foreach (var epic in project.Epics)
|
||||
{
|
||||
foreach (var story in epic.Stories)
|
||||
{
|
||||
task = story.Tasks.FirstOrDefault(t => t.Id.Value == request.TaskId);
|
||||
if (task != null)
|
||||
break;
|
||||
}
|
||||
if (task != null)
|
||||
break;
|
||||
}
|
||||
|
||||
if (task == null)
|
||||
throw new NotFoundException("Task", request.TaskId);
|
||||
|
||||
// Update task details
|
||||
task.UpdateDetails(request.Title, request.Description);
|
||||
|
||||
// Update priority if provided
|
||||
if (!string.IsNullOrWhiteSpace(request.Priority))
|
||||
{
|
||||
var priority = TaskPriority.FromDisplayName<TaskPriority>(request.Priority);
|
||||
task.UpdatePriority(priority);
|
||||
}
|
||||
|
||||
// Update status if provided
|
||||
if (!string.IsNullOrWhiteSpace(request.Status))
|
||||
{
|
||||
var status = WorkItemStatus.FromDisplayName<WorkItemStatus>(request.Status);
|
||||
task.UpdateStatus(status);
|
||||
}
|
||||
|
||||
// Update estimated hours if provided
|
||||
if (request.EstimatedHours.HasValue)
|
||||
{
|
||||
task.UpdateEstimate(request.EstimatedHours.Value);
|
||||
}
|
||||
|
||||
// Update assignee if provided
|
||||
if (request.AssigneeId.HasValue)
|
||||
{
|
||||
var assigneeId = UserId.From(request.AssigneeId.Value);
|
||||
task.AssignTo(assigneeId);
|
||||
}
|
||||
|
||||
// Update project
|
||||
_projectRepository.Update(project);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
|
||||
// Map to DTO
|
||||
return new TaskDto
|
||||
{
|
||||
Id = task.Id.Value,
|
||||
Title = task.Title,
|
||||
Description = task.Description,
|
||||
StoryId = task.StoryId.Value,
|
||||
Status = task.Status.Name,
|
||||
Priority = task.Priority.Name,
|
||||
AssigneeId = task.AssigneeId?.Value,
|
||||
EstimatedHours = task.EstimatedHours,
|
||||
ActualHours = task.ActualHours,
|
||||
CreatedBy = task.CreatedBy.Value,
|
||||
CreatedAt = task.CreatedAt,
|
||||
UpdatedAt = task.UpdatedAt
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.UpdateTask;
|
||||
|
||||
/// <summary>
|
||||
/// Validator for UpdateTaskCommand
|
||||
/// </summary>
|
||||
public sealed class UpdateTaskCommandValidator : AbstractValidator<UpdateTaskCommand>
|
||||
{
|
||||
public UpdateTaskCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.TaskId)
|
||||
.NotEmpty()
|
||||
.WithMessage("TaskId is required");
|
||||
|
||||
RuleFor(x => x.Title)
|
||||
.NotEmpty()
|
||||
.WithMessage("Title is required")
|
||||
.MaximumLength(200)
|
||||
.WithMessage("Title cannot exceed 200 characters");
|
||||
|
||||
RuleFor(x => x.Description)
|
||||
.MaximumLength(5000)
|
||||
.WithMessage("Description cannot exceed 5000 characters");
|
||||
|
||||
RuleFor(x => x.Priority)
|
||||
.Must(BeValidPriority)
|
||||
.When(x => !string.IsNullOrWhiteSpace(x.Priority))
|
||||
.WithMessage("Priority must be one of: Low, Medium, High, Urgent");
|
||||
|
||||
RuleFor(x => x.Status)
|
||||
.Must(BeValidStatus)
|
||||
.When(x => !string.IsNullOrWhiteSpace(x.Status))
|
||||
.WithMessage("Status must be one of: ToDo, InProgress, Done, Blocked");
|
||||
|
||||
RuleFor(x => x.EstimatedHours)
|
||||
.GreaterThanOrEqualTo(0)
|
||||
.When(x => x.EstimatedHours.HasValue)
|
||||
.WithMessage("Estimated hours cannot be negative");
|
||||
}
|
||||
|
||||
private bool BeValidPriority(string? priority)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(priority)) return true;
|
||||
var validPriorities = new[] { "Low", "Medium", "High", "Urgent" };
|
||||
return validPriorities.Contains(priority, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private bool BeValidStatus(string? status)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(status)) return true;
|
||||
var validStatuses = new[] { "ToDo", "InProgress", "Done", "Blocked" };
|
||||
return validStatuses.Contains(status, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.UpdateTaskStatus;
|
||||
|
||||
/// <summary>
|
||||
/// Command to update Task status (for Kanban board drag & drop)
|
||||
/// </summary>
|
||||
public sealed record UpdateTaskStatusCommand : IRequest<TaskDto>
|
||||
{
|
||||
public Guid TaskId { get; init; }
|
||||
public string NewStatus { get; init; } = string.Empty;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Repositories;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.ValueObjects;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Exceptions;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.UpdateTaskStatus;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for UpdateTaskStatusCommand
|
||||
/// </summary>
|
||||
public sealed class UpdateTaskStatusCommandHandler : IRequestHandler<UpdateTaskStatusCommand, TaskDto>
|
||||
{
|
||||
private readonly IProjectRepository _projectRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public UpdateTaskStatusCommandHandler(
|
||||
IProjectRepository projectRepository,
|
||||
IUnitOfWork unitOfWork)
|
||||
{
|
||||
_projectRepository = projectRepository ?? throw new ArgumentNullException(nameof(projectRepository));
|
||||
_unitOfWork = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
|
||||
}
|
||||
|
||||
public async Task<TaskDto> Handle(UpdateTaskStatusCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Get the project containing the task
|
||||
var taskId = TaskId.From(request.TaskId);
|
||||
var project = await _projectRepository.GetProjectWithTaskAsync(taskId, cancellationToken);
|
||||
|
||||
if (project == null)
|
||||
throw new NotFoundException("Task", request.TaskId);
|
||||
|
||||
// Find the task within the project aggregate
|
||||
WorkTask? task = null;
|
||||
foreach (var epic in project.Epics)
|
||||
{
|
||||
foreach (var story in epic.Stories)
|
||||
{
|
||||
task = story.Tasks.FirstOrDefault(t => t.Id.Value == request.TaskId);
|
||||
if (task != null)
|
||||
break;
|
||||
}
|
||||
if (task != null)
|
||||
break;
|
||||
}
|
||||
|
||||
if (task == null)
|
||||
throw new NotFoundException("Task", request.TaskId);
|
||||
|
||||
// Parse and validate new status
|
||||
var newStatus = WorkItemStatus.FromDisplayName<WorkItemStatus>(request.NewStatus);
|
||||
|
||||
// Validate status transition (business rule)
|
||||
ValidateStatusTransition(task.Status, newStatus);
|
||||
|
||||
// Update task status
|
||||
task.UpdateStatus(newStatus);
|
||||
|
||||
// Update project
|
||||
_projectRepository.Update(project);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
|
||||
// Map to DTO
|
||||
return new TaskDto
|
||||
{
|
||||
Id = task.Id.Value,
|
||||
Title = task.Title,
|
||||
Description = task.Description,
|
||||
StoryId = task.StoryId.Value,
|
||||
Status = task.Status.Name,
|
||||
Priority = task.Priority.Name,
|
||||
AssigneeId = task.AssigneeId?.Value,
|
||||
EstimatedHours = task.EstimatedHours,
|
||||
ActualHours = task.ActualHours,
|
||||
CreatedBy = task.CreatedBy.Value,
|
||||
CreatedAt = task.CreatedAt,
|
||||
UpdatedAt = task.UpdatedAt
|
||||
};
|
||||
}
|
||||
|
||||
private void ValidateStatusTransition(WorkItemStatus currentStatus, WorkItemStatus newStatus)
|
||||
{
|
||||
// Business rule: Can't move from Done back to ToDo
|
||||
if (currentStatus == WorkItemStatus.Done && newStatus == WorkItemStatus.ToDo)
|
||||
{
|
||||
throw new DomainException("Cannot move a completed task back to ToDo. Please create a new task instead.");
|
||||
}
|
||||
|
||||
// Business rule: Blocked can be moved to any status
|
||||
// Business rule: Any status can be moved to Blocked
|
||||
// All other transitions are allowed
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Commands.UpdateTaskStatus;
|
||||
|
||||
/// <summary>
|
||||
/// Validator for UpdateTaskStatusCommand
|
||||
/// </summary>
|
||||
public sealed class UpdateTaskStatusCommandValidator : AbstractValidator<UpdateTaskStatusCommand>
|
||||
{
|
||||
public UpdateTaskStatusCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.TaskId)
|
||||
.NotEmpty()
|
||||
.WithMessage("TaskId is required");
|
||||
|
||||
RuleFor(x => x.NewStatus)
|
||||
.NotEmpty()
|
||||
.WithMessage("NewStatus is required")
|
||||
.Must(BeValidStatus)
|
||||
.WithMessage("NewStatus must be one of: ToDo, InProgress, Done, Blocked");
|
||||
}
|
||||
|
||||
private bool BeValidStatus(string status)
|
||||
{
|
||||
var validStatuses = new[] { "ToDo", "InProgress", "Done", "Blocked" };
|
||||
return validStatuses.Contains(status, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
@@ -36,8 +36,8 @@ public sealed class GetEpicByIdQueryHandler : IRequestHandler<GetEpicByIdQuery,
|
||||
Name = epic.Name,
|
||||
Description = epic.Description,
|
||||
ProjectId = epic.ProjectId.Value,
|
||||
Status = epic.Status.Value,
|
||||
Priority = epic.Priority.Value,
|
||||
Status = epic.Status.Name,
|
||||
Priority = epic.Priority.Name,
|
||||
CreatedBy = epic.CreatedBy.Value,
|
||||
CreatedAt = epic.CreatedAt,
|
||||
UpdatedAt = epic.UpdatedAt,
|
||||
@@ -47,8 +47,8 @@ public sealed class GetEpicByIdQueryHandler : IRequestHandler<GetEpicByIdQuery,
|
||||
Title = s.Title,
|
||||
Description = s.Description,
|
||||
EpicId = s.EpicId.Value,
|
||||
Status = s.Status.Value,
|
||||
Priority = s.Priority.Value,
|
||||
Status = s.Status.Name,
|
||||
Priority = s.Priority.Name,
|
||||
EstimatedHours = s.EstimatedHours,
|
||||
ActualHours = s.ActualHours,
|
||||
AssigneeId = s.AssigneeId?.Value,
|
||||
|
||||
@@ -32,8 +32,8 @@ public sealed class GetEpicsByProjectIdQueryHandler : IRequestHandler<GetEpicsBy
|
||||
Name = epic.Name,
|
||||
Description = epic.Description,
|
||||
ProjectId = epic.ProjectId.Value,
|
||||
Status = epic.Status.Value,
|
||||
Priority = epic.Priority.Value,
|
||||
Status = epic.Status.Name,
|
||||
Priority = epic.Priority.Name,
|
||||
CreatedBy = epic.CreatedBy.Value,
|
||||
CreatedAt = epic.CreatedAt,
|
||||
UpdatedAt = epic.UpdatedAt,
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Queries.GetStoriesByEpicId;
|
||||
|
||||
/// <summary>
|
||||
/// Query to get all Stories for an Epic
|
||||
/// </summary>
|
||||
public sealed record GetStoriesByEpicIdQuery(Guid EpicId) : IRequest<List<StoryDto>>;
|
||||
@@ -0,0 +1,67 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Repositories;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.ValueObjects;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Exceptions;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Queries.GetStoriesByEpicId;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for GetStoriesByEpicIdQuery
|
||||
/// </summary>
|
||||
public sealed class GetStoriesByEpicIdQueryHandler : IRequestHandler<GetStoriesByEpicIdQuery, List<StoryDto>>
|
||||
{
|
||||
private readonly IProjectRepository _projectRepository;
|
||||
|
||||
public GetStoriesByEpicIdQueryHandler(IProjectRepository projectRepository)
|
||||
{
|
||||
_projectRepository = projectRepository ?? throw new ArgumentNullException(nameof(projectRepository));
|
||||
}
|
||||
|
||||
public async Task<List<StoryDto>> Handle(GetStoriesByEpicIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Get the project with epic
|
||||
var epicId = EpicId.From(request.EpicId);
|
||||
var project = await _projectRepository.GetProjectWithEpicAsync(epicId, cancellationToken);
|
||||
|
||||
if (project == null)
|
||||
throw new NotFoundException("Epic", request.EpicId);
|
||||
|
||||
// Find the epic
|
||||
var epic = project.Epics.FirstOrDefault(e => e.Id.Value == request.EpicId);
|
||||
if (epic == null)
|
||||
throw new NotFoundException("Epic", request.EpicId);
|
||||
|
||||
// Map stories to DTOs
|
||||
return epic.Stories.Select(story => new StoryDto
|
||||
{
|
||||
Id = story.Id.Value,
|
||||
Title = story.Title,
|
||||
Description = story.Description,
|
||||
EpicId = story.EpicId.Value,
|
||||
Status = story.Status.Name,
|
||||
Priority = story.Priority.Name,
|
||||
AssigneeId = story.AssigneeId?.Value,
|
||||
EstimatedHours = story.EstimatedHours,
|
||||
ActualHours = story.ActualHours,
|
||||
CreatedBy = story.CreatedBy.Value,
|
||||
CreatedAt = story.CreatedAt,
|
||||
UpdatedAt = story.UpdatedAt,
|
||||
Tasks = story.Tasks.Select(t => new TaskDto
|
||||
{
|
||||
Id = t.Id.Value,
|
||||
Title = t.Title,
|
||||
Description = t.Description,
|
||||
StoryId = t.StoryId.Value,
|
||||
Status = t.Status.Name,
|
||||
Priority = t.Priority.Name,
|
||||
AssigneeId = t.AssigneeId?.Value,
|
||||
EstimatedHours = t.EstimatedHours,
|
||||
ActualHours = t.ActualHours,
|
||||
CreatedBy = t.CreatedBy.Value,
|
||||
CreatedAt = t.CreatedAt,
|
||||
UpdatedAt = t.UpdatedAt
|
||||
}).ToList()
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Queries.GetStoriesByProjectId;
|
||||
|
||||
/// <summary>
|
||||
/// Query to get all Stories for a Project
|
||||
/// </summary>
|
||||
public sealed record GetStoriesByProjectIdQuery(Guid ProjectId) : IRequest<List<StoryDto>>;
|
||||
@@ -0,0 +1,66 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Repositories;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.ValueObjects;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Exceptions;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Queries.GetStoriesByProjectId;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for GetStoriesByProjectIdQuery
|
||||
/// </summary>
|
||||
public sealed class GetStoriesByProjectIdQueryHandler : IRequestHandler<GetStoriesByProjectIdQuery, List<StoryDto>>
|
||||
{
|
||||
private readonly IProjectRepository _projectRepository;
|
||||
|
||||
public GetStoriesByProjectIdQueryHandler(IProjectRepository projectRepository)
|
||||
{
|
||||
_projectRepository = projectRepository ?? throw new ArgumentNullException(nameof(projectRepository));
|
||||
}
|
||||
|
||||
public async Task<List<StoryDto>> Handle(GetStoriesByProjectIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Get the project
|
||||
var projectId = ProjectId.From(request.ProjectId);
|
||||
var project = await _projectRepository.GetByIdAsync(projectId, cancellationToken);
|
||||
|
||||
if (project == null)
|
||||
throw new NotFoundException("Project", request.ProjectId);
|
||||
|
||||
// Get all stories from all epics
|
||||
var stories = project.Epics
|
||||
.SelectMany(epic => epic.Stories.Select(story => new StoryDto
|
||||
{
|
||||
Id = story.Id.Value,
|
||||
Title = story.Title,
|
||||
Description = story.Description,
|
||||
EpicId = story.EpicId.Value,
|
||||
Status = story.Status.Name,
|
||||
Priority = story.Priority.Name,
|
||||
AssigneeId = story.AssigneeId?.Value,
|
||||
EstimatedHours = story.EstimatedHours,
|
||||
ActualHours = story.ActualHours,
|
||||
CreatedBy = story.CreatedBy.Value,
|
||||
CreatedAt = story.CreatedAt,
|
||||
UpdatedAt = story.UpdatedAt,
|
||||
Tasks = story.Tasks.Select(t => new TaskDto
|
||||
{
|
||||
Id = t.Id.Value,
|
||||
Title = t.Title,
|
||||
Description = t.Description,
|
||||
StoryId = t.StoryId.Value,
|
||||
Status = t.Status.Name,
|
||||
Priority = t.Priority.Name,
|
||||
AssigneeId = t.AssigneeId?.Value,
|
||||
EstimatedHours = t.EstimatedHours,
|
||||
ActualHours = t.ActualHours,
|
||||
CreatedBy = t.CreatedBy.Value,
|
||||
CreatedAt = t.CreatedAt,
|
||||
UpdatedAt = t.UpdatedAt
|
||||
}).ToList()
|
||||
}))
|
||||
.ToList();
|
||||
|
||||
return stories;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Queries.GetStoryById;
|
||||
|
||||
/// <summary>
|
||||
/// Query to get a Story by ID
|
||||
/// </summary>
|
||||
public sealed record GetStoryByIdQuery(Guid StoryId) : IRequest<StoryDto>;
|
||||
@@ -0,0 +1,70 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Repositories;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.ValueObjects;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Exceptions;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Queries.GetStoryById;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for GetStoryByIdQuery
|
||||
/// </summary>
|
||||
public sealed class GetStoryByIdQueryHandler : IRequestHandler<GetStoryByIdQuery, StoryDto>
|
||||
{
|
||||
private readonly IProjectRepository _projectRepository;
|
||||
|
||||
public GetStoryByIdQueryHandler(IProjectRepository projectRepository)
|
||||
{
|
||||
_projectRepository = projectRepository ?? throw new ArgumentNullException(nameof(projectRepository));
|
||||
}
|
||||
|
||||
public async Task<StoryDto> Handle(GetStoryByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Get the project with story
|
||||
var storyId = StoryId.From(request.StoryId);
|
||||
var project = await _projectRepository.GetProjectWithStoryAsync(storyId, cancellationToken);
|
||||
|
||||
if (project == null)
|
||||
throw new NotFoundException("Story", request.StoryId);
|
||||
|
||||
// Find the story
|
||||
var story = project.Epics
|
||||
.SelectMany(e => e.Stories)
|
||||
.FirstOrDefault(s => s.Id.Value == request.StoryId);
|
||||
|
||||
if (story == null)
|
||||
throw new NotFoundException("Story", request.StoryId);
|
||||
|
||||
// Map to DTO
|
||||
return new StoryDto
|
||||
{
|
||||
Id = story.Id.Value,
|
||||
Title = story.Title,
|
||||
Description = story.Description,
|
||||
EpicId = story.EpicId.Value,
|
||||
Status = story.Status.Name,
|
||||
Priority = story.Priority.Name,
|
||||
AssigneeId = story.AssigneeId?.Value,
|
||||
EstimatedHours = story.EstimatedHours,
|
||||
ActualHours = story.ActualHours,
|
||||
CreatedBy = story.CreatedBy.Value,
|
||||
CreatedAt = story.CreatedAt,
|
||||
UpdatedAt = story.UpdatedAt,
|
||||
Tasks = story.Tasks.Select(t => new TaskDto
|
||||
{
|
||||
Id = t.Id.Value,
|
||||
Title = t.Title,
|
||||
Description = t.Description,
|
||||
StoryId = t.StoryId.Value,
|
||||
Status = t.Status.Name,
|
||||
Priority = t.Priority.Name,
|
||||
AssigneeId = t.AssigneeId?.Value,
|
||||
EstimatedHours = t.EstimatedHours,
|
||||
ActualHours = t.ActualHours,
|
||||
CreatedBy = t.CreatedBy.Value,
|
||||
CreatedAt = t.CreatedAt,
|
||||
UpdatedAt = t.UpdatedAt
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Queries.GetTaskById;
|
||||
|
||||
/// <summary>
|
||||
/// Query to get a Task by ID
|
||||
/// </summary>
|
||||
public sealed record GetTaskByIdQuery(Guid TaskId) : IRequest<TaskDto>;
|
||||
@@ -0,0 +1,65 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Repositories;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.ValueObjects;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Exceptions;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Queries.GetTaskById;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for GetTaskByIdQuery
|
||||
/// </summary>
|
||||
public sealed class GetTaskByIdQueryHandler : IRequestHandler<GetTaskByIdQuery, TaskDto>
|
||||
{
|
||||
private readonly IProjectRepository _projectRepository;
|
||||
|
||||
public GetTaskByIdQueryHandler(IProjectRepository projectRepository)
|
||||
{
|
||||
_projectRepository = projectRepository ?? throw new ArgumentNullException(nameof(projectRepository));
|
||||
}
|
||||
|
||||
public async Task<TaskDto> Handle(GetTaskByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Get the project containing the task
|
||||
var taskId = TaskId.From(request.TaskId);
|
||||
var project = await _projectRepository.GetProjectWithTaskAsync(taskId, cancellationToken);
|
||||
|
||||
if (project == null)
|
||||
throw new NotFoundException("Task", request.TaskId);
|
||||
|
||||
// Find the task within the project aggregate
|
||||
WorkTask? task = null;
|
||||
foreach (var epic in project.Epics)
|
||||
{
|
||||
foreach (var story in epic.Stories)
|
||||
{
|
||||
task = story.Tasks.FirstOrDefault(t => t.Id.Value == request.TaskId);
|
||||
if (task != null)
|
||||
break;
|
||||
}
|
||||
if (task != null)
|
||||
break;
|
||||
}
|
||||
|
||||
if (task == null)
|
||||
throw new NotFoundException("Task", request.TaskId);
|
||||
|
||||
// Map to DTO
|
||||
return new TaskDto
|
||||
{
|
||||
Id = task.Id.Value,
|
||||
Title = task.Title,
|
||||
Description = task.Description,
|
||||
StoryId = task.StoryId.Value,
|
||||
Status = task.Status.Name,
|
||||
Priority = task.Priority.Name,
|
||||
AssigneeId = task.AssigneeId?.Value,
|
||||
EstimatedHours = task.EstimatedHours,
|
||||
ActualHours = task.ActualHours,
|
||||
CreatedBy = task.CreatedBy.Value,
|
||||
CreatedAt = task.CreatedAt,
|
||||
UpdatedAt = task.UpdatedAt
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Queries.GetTasksByAssignee;
|
||||
|
||||
/// <summary>
|
||||
/// Query to get all Tasks assigned to a user
|
||||
/// </summary>
|
||||
public sealed record GetTasksByAssigneeQuery(Guid AssigneeId) : IRequest<List<TaskDto>>;
|
||||
@@ -0,0 +1,49 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Repositories;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Queries.GetTasksByAssignee;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for GetTasksByAssigneeQuery
|
||||
/// </summary>
|
||||
public sealed class GetTasksByAssigneeQueryHandler : IRequestHandler<GetTasksByAssigneeQuery, List<TaskDto>>
|
||||
{
|
||||
private readonly IProjectRepository _projectRepository;
|
||||
|
||||
public GetTasksByAssigneeQueryHandler(IProjectRepository projectRepository)
|
||||
{
|
||||
_projectRepository = projectRepository ?? throw new ArgumentNullException(nameof(projectRepository));
|
||||
}
|
||||
|
||||
public async Task<List<TaskDto>> Handle(GetTasksByAssigneeQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Get all projects
|
||||
var allProjects = await _projectRepository.GetAllAsync(cancellationToken);
|
||||
|
||||
// Get all tasks assigned to the user across all projects
|
||||
var userTasks = allProjects
|
||||
.SelectMany(project => project.Epics)
|
||||
.SelectMany(epic => epic.Stories)
|
||||
.SelectMany(story => story.Tasks)
|
||||
.Where(task => task.AssigneeId != null && task.AssigneeId.Value == request.AssigneeId)
|
||||
.ToList();
|
||||
|
||||
// Map to DTOs
|
||||
return userTasks.Select(task => new TaskDto
|
||||
{
|
||||
Id = task.Id.Value,
|
||||
Title = task.Title,
|
||||
Description = task.Description,
|
||||
StoryId = task.StoryId.Value,
|
||||
Status = task.Status.Name,
|
||||
Priority = task.Priority.Name,
|
||||
AssigneeId = task.AssigneeId?.Value,
|
||||
EstimatedHours = task.EstimatedHours,
|
||||
ActualHours = task.ActualHours,
|
||||
CreatedBy = task.CreatedBy.Value,
|
||||
CreatedAt = task.CreatedAt,
|
||||
UpdatedAt = task.UpdatedAt
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Queries.GetTasksByProjectId;
|
||||
|
||||
/// <summary>
|
||||
/// Query to get all Tasks for a Project (for Kanban board)
|
||||
/// </summary>
|
||||
public sealed record GetTasksByProjectIdQuery : IRequest<List<TaskDto>>
|
||||
{
|
||||
public Guid ProjectId { get; init; }
|
||||
public string? Status { get; init; }
|
||||
public Guid? AssigneeId { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Repositories;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.ValueObjects;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Exceptions;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Queries.GetTasksByProjectId;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for GetTasksByProjectIdQuery
|
||||
/// </summary>
|
||||
public sealed class GetTasksByProjectIdQueryHandler : IRequestHandler<GetTasksByProjectIdQuery, List<TaskDto>>
|
||||
{
|
||||
private readonly IProjectRepository _projectRepository;
|
||||
|
||||
public GetTasksByProjectIdQueryHandler(IProjectRepository projectRepository)
|
||||
{
|
||||
_projectRepository = projectRepository ?? throw new ArgumentNullException(nameof(projectRepository));
|
||||
}
|
||||
|
||||
public async Task<List<TaskDto>> Handle(GetTasksByProjectIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Get the project with all its tasks
|
||||
var projectId = ProjectId.From(request.ProjectId);
|
||||
var project = await _projectRepository.GetByIdAsync(projectId, cancellationToken);
|
||||
|
||||
if (project == null)
|
||||
throw new NotFoundException("Project", request.ProjectId);
|
||||
|
||||
// Get all tasks from all stories in all epics
|
||||
var allTasks = project.Epics
|
||||
.SelectMany(epic => epic.Stories)
|
||||
.SelectMany(story => story.Tasks)
|
||||
.ToList();
|
||||
|
||||
// Apply filters
|
||||
if (!string.IsNullOrWhiteSpace(request.Status))
|
||||
{
|
||||
allTasks = allTasks.Where(t => t.Status.Name.Equals(request.Status, StringComparison.OrdinalIgnoreCase)).ToList();
|
||||
}
|
||||
|
||||
if (request.AssigneeId.HasValue)
|
||||
{
|
||||
allTasks = allTasks.Where(t => t.AssigneeId != null && t.AssigneeId.Value == request.AssigneeId.Value).ToList();
|
||||
}
|
||||
|
||||
// Map to DTOs
|
||||
return allTasks.Select(task => new TaskDto
|
||||
{
|
||||
Id = task.Id.Value,
|
||||
Title = task.Title,
|
||||
Description = task.Description,
|
||||
StoryId = task.StoryId.Value,
|
||||
Status = task.Status.Name,
|
||||
Priority = task.Priority.Name,
|
||||
AssigneeId = task.AssigneeId?.Value,
|
||||
EstimatedHours = task.EstimatedHours,
|
||||
ActualHours = task.ActualHours,
|
||||
CreatedBy = task.CreatedBy.Value,
|
||||
CreatedAt = task.CreatedAt,
|
||||
UpdatedAt = task.UpdatedAt
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Queries.GetTasksByStoryId;
|
||||
|
||||
/// <summary>
|
||||
/// Query to get all Tasks for a Story
|
||||
/// </summary>
|
||||
public sealed record GetTasksByStoryIdQuery(Guid StoryId) : IRequest<List<TaskDto>>;
|
||||
@@ -0,0 +1,55 @@
|
||||
using MediatR;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Repositories;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.ValueObjects;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Exceptions;
|
||||
|
||||
namespace ColaFlow.Modules.ProjectManagement.Application.Queries.GetTasksByStoryId;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for GetTasksByStoryIdQuery
|
||||
/// </summary>
|
||||
public sealed class GetTasksByStoryIdQueryHandler : IRequestHandler<GetTasksByStoryIdQuery, List<TaskDto>>
|
||||
{
|
||||
private readonly IProjectRepository _projectRepository;
|
||||
|
||||
public GetTasksByStoryIdQueryHandler(IProjectRepository projectRepository)
|
||||
{
|
||||
_projectRepository = projectRepository ?? throw new ArgumentNullException(nameof(projectRepository));
|
||||
}
|
||||
|
||||
public async Task<List<TaskDto>> Handle(GetTasksByStoryIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Get the project containing the story
|
||||
var storyId = StoryId.From(request.StoryId);
|
||||
var project = await _projectRepository.GetProjectWithStoryAsync(storyId, cancellationToken);
|
||||
|
||||
if (project == null)
|
||||
throw new NotFoundException("Story", request.StoryId);
|
||||
|
||||
// Find the story within the project aggregate
|
||||
var story = project.Epics
|
||||
.SelectMany(e => e.Stories)
|
||||
.FirstOrDefault(s => s.Id.Value == request.StoryId);
|
||||
|
||||
if (story == null)
|
||||
throw new NotFoundException("Story", request.StoryId);
|
||||
|
||||
// Map tasks to DTOs
|
||||
return story.Tasks.Select(task => new TaskDto
|
||||
{
|
||||
Id = task.Id.Value,
|
||||
Title = task.Title,
|
||||
Description = task.Description,
|
||||
StoryId = task.StoryId.Value,
|
||||
Status = task.Status.Name,
|
||||
Priority = task.Priority.Name,
|
||||
AssigneeId = task.AssigneeId?.Value,
|
||||
EstimatedHours = task.EstimatedHours,
|
||||
ActualHours = task.ActualHours,
|
||||
CreatedBy = task.CreatedBy.Value,
|
||||
CreatedAt = task.CreatedAt,
|
||||
UpdatedAt = task.UpdatedAt
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user