In progress
Some checks failed
Code Coverage / Generate Coverage Report (push) Has been cancelled
Tests / Run Tests (9.0.x) (push) Has been cancelled
Tests / Docker Build Test (push) Has been cancelled
Tests / Test Summary (push) Has been cancelled

This commit is contained in:
Yaojia Wang
2025-11-03 11:51:02 +01:00
parent 24fb646739
commit fe8ad1c1f9
101 changed files with 26471 additions and 250 deletions

View File

@@ -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>

View File

@@ -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; }
}

View File

@@ -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()
};
}
}

View File

@@ -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");
}
}

View File

@@ -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; }
}

View File

@@ -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
};
}
}

View File

@@ -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");
}
}

View File

@@ -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,

View File

@@ -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; }
}

View File

@@ -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>()
};
}
}

View File

@@ -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");
}
}

View File

@@ -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; }
}

View File

@@ -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
};
}
}

View File

@@ -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);
}
}

View File

@@ -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; }
}

View File

@@ -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;
}
}

View File

@@ -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");
}
}

View File

@@ -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; }
}

View File

@@ -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;
}
}

View File

@@ -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");
}
}

View File

@@ -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,

View File

@@ -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; }
}

View File

@@ -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()
};
}
}

View File

@@ -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");
}
}

View File

@@ -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; }
}

View File

@@ -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
};
}
}

View File

@@ -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);
}
}

View File

@@ -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;
}

View File

@@ -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
}
}

View File

@@ -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);
}
}

View File

@@ -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,

View File

@@ -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,

View File

@@ -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>>;

View File

@@ -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();
}
}

View File

@@ -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>>;

View File

@@ -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;
}
}

View File

@@ -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>;

View File

@@ -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()
};
}
}

View File

@@ -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>;

View File

@@ -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
};
}
}

View File

@@ -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>>;

View File

@@ -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();
}
}

View File

@@ -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; }
}

View File

@@ -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();
}
}

View File

@@ -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>>;

View File

@@ -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();
}
}

View File

@@ -88,4 +88,17 @@ public class Epic : Entity
Priority = newPriority;
UpdatedAt = DateTime.UtcNow;
}
public void RemoveStory(StoryId storyId)
{
var story = _stories.FirstOrDefault(s => s.Id == storyId);
if (story == null)
throw new DomainException($"Story with ID {storyId.Value} not found in epic");
if (story.Tasks.Any())
throw new DomainException($"Cannot delete story with ID {storyId.Value}. The story has {story.Tasks.Count} associated task(s). Please delete or reassign the tasks first.");
_stories.Remove(story);
UpdatedAt = DateTime.UtcNow;
}
}

View File

@@ -67,6 +67,16 @@ public class Story : Entity
return task;
}
public void RemoveTask(TaskId taskId)
{
var task = _tasks.FirstOrDefault(t => t.Id == taskId);
if (task == null)
throw new DomainException($"Task with ID {taskId.Value} not found in story");
_tasks.Remove(task);
UpdatedAt = DateTime.UtcNow;
}
public void UpdateDetails(string title, string description)
{
if (string.IsNullOrWhiteSpace(title))
@@ -109,4 +119,10 @@ public class Story : Entity
ActualHours = hours;
UpdatedAt = DateTime.UtcNow;
}
public void UpdatePriority(TaskPriority newPriority)
{
Priority = newPriority;
UpdatedAt = DateTime.UtcNow;
}
}

View File

@@ -0,0 +1,112 @@
using ColaFlow.Shared.Kernel.Common;
using ColaFlow.Modules.ProjectManagement.Domain.Exceptions;
using ColaFlow.Modules.ProjectManagement.Domain.ValueObjects;
using ColaFlow.Modules.ProjectManagement.Domain.Events;
namespace ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate;
/// <summary>
/// Story Entity (part of Project aggregate)
/// </summary>
public class Story : Entity
{
public new StoryId Id { get; private set; }
public string Title { get; private set; }
public string Description { get; private set; }
public EpicId EpicId { get; private set; }
public WorkItemStatus Status { get; private set; }
public TaskPriority Priority { get; private set; }
public decimal? EstimatedHours { get; private set; }
public decimal? ActualHours { get; private set; }
public UserId? AssigneeId { get; private set; }
private readonly List<WorkTask> _tasks = new();
public IReadOnlyCollection<WorkTask> Tasks => _tasks.AsReadOnly();
public DateTime CreatedAt { get; private set; }
public UserId CreatedBy { get; private set; }
public DateTime? UpdatedAt { get; private set; }
// EF Core constructor
private Story()
{
Id = null!;
Title = null!;
Description = null!;
EpicId = null!;
Status = null!;
Priority = null!;
CreatedBy = null!;
}
public static Story Create(string title, string description, EpicId epicId, TaskPriority priority, UserId createdBy)
{
if (string.IsNullOrWhiteSpace(title))
throw new DomainException("Story title cannot be empty");
if (title.Length > 200)
throw new DomainException("Story title cannot exceed 200 characters");
return new Story
{
Id = StoryId.Create(),
Title = title,
Description = description ?? string.Empty,
EpicId = epicId,
Status = WorkItemStatus.ToDo,
Priority = priority,
CreatedAt = DateTime.UtcNow,
CreatedBy = createdBy
};
}
public WorkTask CreateTask(string title, string description, TaskPriority priority, UserId createdBy)
{
var task = WorkTask.Create(title, description, this.Id, priority, createdBy);
_tasks.Add(task);
return task;
}
public void UpdateDetails(string title, string description)
{
if (string.IsNullOrWhiteSpace(title))
throw new DomainException("Story title cannot be empty");
if (title.Length > 200)
throw new DomainException("Story title cannot exceed 200 characters");
Title = title;
Description = description ?? string.Empty;
UpdatedAt = DateTime.UtcNow;
}
public void UpdateStatus(WorkItemStatus newStatus)
{
Status = newStatus;
UpdatedAt = DateTime.UtcNow;
}
public void AssignTo(UserId assigneeId)
{
AssigneeId = assigneeId;
UpdatedAt = DateTime.UtcNow;
}
public void UpdateEstimate(decimal hours)
{
if (hours < 0)
throw new DomainException("Estimated hours cannot be negative");
EstimatedHours = hours;
UpdatedAt = DateTime.UtcNow;
}
public void LogActualHours(decimal hours)
{
if (hours < 0)
throw new DomainException("Actual hours cannot be negative");
ActualHours = hours;
UpdatedAt = DateTime.UtcNow;
}
}

View File

@@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace ColaFlow.Modules.ProjectManagement.Infrastructure.Migrations
{
[DbContext(typeof(PMDbContext))]
[Migration("20251102220422_InitialCreate")]
partial class InitialCreate
[Migration("20251103000604_FixValueObjectForeignKeys")]
partial class FixValueObjectForeignKeys
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -55,9 +55,6 @@ namespace ColaFlow.Modules.ProjectManagement.Infrastructure.Migrations
b.Property<Guid>("ProjectId")
.HasColumnType("uuid");
b.Property<Guid?>("ProjectId1")
.HasColumnType("uuid");
b.Property<string>("Status")
.IsRequired()
.HasMaxLength(50)
@@ -72,8 +69,6 @@ namespace ColaFlow.Modules.ProjectManagement.Infrastructure.Migrations
b.HasIndex("ProjectId");
b.HasIndex("ProjectId1");
b.ToTable("Epics", "project_management");
});
@@ -232,14 +227,10 @@ namespace ColaFlow.Modules.ProjectManagement.Infrastructure.Migrations
modelBuilder.Entity("ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate.Epic", b =>
{
b.HasOne("ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate.Project", null)
.WithMany()
.WithMany("Epics")
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate.Project", null)
.WithMany("Epics")
.HasForeignKey("ProjectId1");
});
modelBuilder.Entity("ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate.Project", b =>
@@ -273,7 +264,7 @@ namespace ColaFlow.Modules.ProjectManagement.Infrastructure.Migrations
modelBuilder.Entity("ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate.Story", b =>
{
b.HasOne("ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate.Epic", null)
.WithMany()
.WithMany("Stories")
.HasForeignKey("EpicId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -282,16 +273,26 @@ namespace ColaFlow.Modules.ProjectManagement.Infrastructure.Migrations
modelBuilder.Entity("ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate.WorkTask", b =>
{
b.HasOne("ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate.Story", null)
.WithMany()
.WithMany("Tasks")
.HasForeignKey("StoryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate.Epic", b =>
{
b.Navigation("Stories");
});
modelBuilder.Entity("ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate.Project", b =>
{
b.Navigation("Epics");
});
modelBuilder.Entity("ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate.Story", b =>
{
b.Navigation("Tasks");
});
#pragma warning restore 612, 618
}
}

View File

@@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace ColaFlow.Modules.ProjectManagement.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
public partial class FixValueObjectForeignKeys : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
@@ -46,8 +46,7 @@ namespace ColaFlow.Modules.ProjectManagement.Infrastructure.Migrations
Priority = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
CreatedBy = table.Column<Guid>(type: "uuid", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
ProjectId1 = table.Column<Guid>(type: "uuid", nullable: true)
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
@@ -59,12 +58,6 @@ namespace ColaFlow.Modules.ProjectManagement.Infrastructure.Migrations
principalTable: "Projects",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Epics_Projects_ProjectId1",
column: x => x.ProjectId1,
principalSchema: "project_management",
principalTable: "Projects",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
@@ -139,12 +132,6 @@ namespace ColaFlow.Modules.ProjectManagement.Infrastructure.Migrations
table: "Epics",
column: "ProjectId");
migrationBuilder.CreateIndex(
name: "IX_Epics_ProjectId1",
schema: "project_management",
table: "Epics",
column: "ProjectId1");
migrationBuilder.CreateIndex(
name: "IX_Projects_CreatedAt",
schema: "project_management",

View File

@@ -52,9 +52,6 @@ namespace ColaFlow.Modules.ProjectManagement.Infrastructure.Migrations
b.Property<Guid>("ProjectId")
.HasColumnType("uuid");
b.Property<Guid?>("ProjectId1")
.HasColumnType("uuid");
b.Property<string>("Status")
.IsRequired()
.HasMaxLength(50)
@@ -69,8 +66,6 @@ namespace ColaFlow.Modules.ProjectManagement.Infrastructure.Migrations
b.HasIndex("ProjectId");
b.HasIndex("ProjectId1");
b.ToTable("Epics", "project_management");
});
@@ -229,14 +224,10 @@ namespace ColaFlow.Modules.ProjectManagement.Infrastructure.Migrations
modelBuilder.Entity("ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate.Epic", b =>
{
b.HasOne("ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate.Project", null)
.WithMany()
.WithMany("Epics")
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate.Project", null)
.WithMany("Epics")
.HasForeignKey("ProjectId1");
});
modelBuilder.Entity("ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate.Project", b =>
@@ -270,7 +261,7 @@ namespace ColaFlow.Modules.ProjectManagement.Infrastructure.Migrations
modelBuilder.Entity("ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate.Story", b =>
{
b.HasOne("ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate.Epic", null)
.WithMany()
.WithMany("Stories")
.HasForeignKey("EpicId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -279,16 +270,26 @@ namespace ColaFlow.Modules.ProjectManagement.Infrastructure.Migrations
modelBuilder.Entity("ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate.WorkTask", b =>
{
b.HasOne("ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate.Story", null)
.WithMany()
.WithMany("Tasks")
.HasForeignKey("StoryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate.Epic", b =>
{
b.Navigation("Stories");
});
modelBuilder.Entity("ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate.Project", b =>
{
b.Navigation("Epics");
});
modelBuilder.Entity("ColaFlow.Modules.ProjectManagement.Domain.Aggregates.ProjectAggregate.Story", b =>
{
b.Navigation("Tasks");
});
#pragma warning restore 612, 618
}
}

View File

@@ -70,13 +70,11 @@ public class EpicConfiguration : IEntityTypeConfiguration<Epic>
builder.Property(e => e.UpdatedAt);
// Ignore navigation properties (DDD pattern - access through aggregate)
builder.Ignore(e => e.Stories);
// Foreign key relationship to Project
builder.HasOne<Project>()
.WithMany()
.HasForeignKey(e => e.ProjectId)
// Configure Stories collection (owned by Epic in the aggregate)
// Use string-based FK name because EpicId is a value object with conversion configured in StoryConfiguration
builder.HasMany<Story>("Stories")
.WithOne()
.HasForeignKey("EpicId")
.OnDelete(DeleteBehavior.Cascade);
// Indexes

View File

@@ -67,7 +67,12 @@ public class ProjectConfiguration : IEntityTypeConfiguration<Project>
builder.Property(p => p.UpdatedAt);
// Relationships - Epics collection (owned by aggregate)
// Note: We don't expose this as navigation property in DDD, epics are accessed through repository
// Configure the one-to-many relationship with Epic
// Use string-based FK name because ProjectId is a value object with conversion configured in EpicConfiguration
builder.HasMany<Epic>("Epics")
.WithOne()
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade);
// Indexes for performance
builder.HasIndex(p => p.CreatedAt);

View File

@@ -80,13 +80,11 @@ public class StoryConfiguration : IEntityTypeConfiguration<Story>
builder.Property(s => s.UpdatedAt);
// Ignore navigation properties (DDD pattern - access through aggregate)
builder.Ignore(s => s.Tasks);
// Foreign key relationship to Epic
builder.HasOne<Epic>()
.WithMany()
.HasForeignKey(s => s.EpicId)
// Configure Tasks collection (owned by Story in the aggregate)
// Use string-based FK name because StoryId is a value object with conversion configured in WorkTaskConfiguration
builder.HasMany<WorkTask>("Tasks")
.WithOne()
.HasForeignKey("StoryId")
.OnDelete(DeleteBehavior.Cascade);
// Indexes

View File

@@ -80,12 +80,6 @@ public class WorkTaskConfiguration : IEntityTypeConfiguration<WorkTask>
builder.Property(t => t.UpdatedAt);
// Foreign key relationship to Story
builder.HasOne<Story>()
.WithMany()
.HasForeignKey(t => t.StoryId)
.OnDelete(DeleteBehavior.Cascade);
// Indexes
builder.HasIndex(t => t.StoryId);
builder.HasIndex(t => t.AssigneeId);