In progress
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MediatR" Version="11.1.0" />
|
||||
<PackageReference Include="MediatR" Version="13.1.0" />
|
||||
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.10.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
190
colaflow-api/src/ColaFlow.API/Controllers/StoriesController.cs
Normal file
190
colaflow-api/src/ColaFlow.API/Controllers/StoriesController.cs
Normal file
@@ -0,0 +1,190 @@
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.Commands.CreateStory;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.Commands.UpdateStory;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.Commands.DeleteStory;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.Commands.AssignStory;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.Queries.GetStoryById;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.Queries.GetStoriesByEpicId;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.Queries.GetStoriesByProjectId;
|
||||
|
||||
namespace ColaFlow.API.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// Stories API Controller
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/v1")]
|
||||
public class StoriesController : ControllerBase
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public StoriesController(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get story by ID
|
||||
/// </summary>
|
||||
[HttpGet("stories/{id:guid}")]
|
||||
[ProducesResponseType(typeof(StoryDto), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetStory(Guid id, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var query = new GetStoryByIdQuery(id);
|
||||
var result = await _mediator.Send(query, cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all stories for an epic
|
||||
/// </summary>
|
||||
[HttpGet("epics/{epicId:guid}/stories")]
|
||||
[ProducesResponseType(typeof(List<StoryDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetEpicStories(Guid epicId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var query = new GetStoriesByEpicIdQuery(epicId);
|
||||
var result = await _mediator.Send(query, cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all stories for a project
|
||||
/// </summary>
|
||||
[HttpGet("projects/{projectId:guid}/stories")]
|
||||
[ProducesResponseType(typeof(List<StoryDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetProjectStories(Guid projectId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var query = new GetStoriesByProjectIdQuery(projectId);
|
||||
var result = await _mediator.Send(query, cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new story
|
||||
/// </summary>
|
||||
[HttpPost("epics/{epicId:guid}/stories")]
|
||||
[ProducesResponseType(typeof(StoryDto), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> CreateStory(
|
||||
Guid epicId,
|
||||
[FromBody] CreateStoryRequest request,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var command = new CreateStoryCommand
|
||||
{
|
||||
EpicId = epicId,
|
||||
Title = request.Title,
|
||||
Description = request.Description,
|
||||
Priority = request.Priority,
|
||||
AssigneeId = request.AssigneeId,
|
||||
EstimatedHours = request.EstimatedHours,
|
||||
CreatedBy = request.CreatedBy
|
||||
};
|
||||
|
||||
var result = await _mediator.Send(command, cancellationToken);
|
||||
return CreatedAtAction(nameof(GetStory), new { id = result.Id }, result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update an existing story
|
||||
/// </summary>
|
||||
[HttpPut("stories/{id:guid}")]
|
||||
[ProducesResponseType(typeof(StoryDto), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> UpdateStory(
|
||||
Guid id,
|
||||
[FromBody] UpdateStoryRequest request,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var command = new UpdateStoryCommand
|
||||
{
|
||||
StoryId = id,
|
||||
Title = request.Title,
|
||||
Description = request.Description,
|
||||
Status = request.Status,
|
||||
Priority = request.Priority,
|
||||
AssigneeId = request.AssigneeId,
|
||||
EstimatedHours = request.EstimatedHours
|
||||
};
|
||||
|
||||
var result = await _mediator.Send(command, cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete a story
|
||||
/// </summary>
|
||||
[HttpDelete("stories/{id:guid}")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> DeleteStory(Guid id, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var command = new DeleteStoryCommand { StoryId = id };
|
||||
await _mediator.Send(command, cancellationToken);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Assign a story to a user
|
||||
/// </summary>
|
||||
[HttpPut("stories/{id:guid}/assign")]
|
||||
[ProducesResponseType(typeof(StoryDto), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> AssignStory(
|
||||
Guid id,
|
||||
[FromBody] AssignStoryRequest request,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var command = new AssignStoryCommand
|
||||
{
|
||||
StoryId = id,
|
||||
AssigneeId = request.AssigneeId
|
||||
};
|
||||
|
||||
var result = await _mediator.Send(command, cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request model for creating a story
|
||||
/// </summary>
|
||||
public record CreateStoryRequest
|
||||
{
|
||||
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; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request model for updating a story
|
||||
/// </summary>
|
||||
public record UpdateStoryRequest
|
||||
{
|
||||
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; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request model for assigning a story
|
||||
/// </summary>
|
||||
public record AssignStoryRequest
|
||||
{
|
||||
public Guid AssigneeId { get; init; }
|
||||
}
|
||||
230
colaflow-api/src/ColaFlow.API/Controllers/TasksController.cs
Normal file
230
colaflow-api/src/ColaFlow.API/Controllers/TasksController.cs
Normal file
@@ -0,0 +1,230 @@
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.Commands.CreateTask;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.Commands.UpdateTask;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.Commands.DeleteTask;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.Commands.AssignTask;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.Commands.UpdateTaskStatus;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.Queries.GetTaskById;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.Queries.GetTasksByStoryId;
|
||||
using ColaFlow.Modules.ProjectManagement.Application.Queries.GetTasksByProjectId;
|
||||
|
||||
namespace ColaFlow.API.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// Tasks API Controller
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/v1")]
|
||||
public class TasksController : ControllerBase
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public TasksController(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get task by ID
|
||||
/// </summary>
|
||||
[HttpGet("tasks/{id:guid}")]
|
||||
[ProducesResponseType(typeof(TaskDto), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetTask(Guid id, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var query = new GetTaskByIdQuery(id);
|
||||
var result = await _mediator.Send(query, cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all tasks for a story
|
||||
/// </summary>
|
||||
[HttpGet("stories/{storyId:guid}/tasks")]
|
||||
[ProducesResponseType(typeof(List<TaskDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetStoryTasks(Guid storyId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var query = new GetTasksByStoryIdQuery(storyId);
|
||||
var result = await _mediator.Send(query, cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all tasks for a project (for Kanban board)
|
||||
/// </summary>
|
||||
[HttpGet("projects/{projectId:guid}/tasks")]
|
||||
[ProducesResponseType(typeof(List<TaskDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetProjectTasks(
|
||||
Guid projectId,
|
||||
[FromQuery] string? status = null,
|
||||
[FromQuery] Guid? assigneeId = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var query = new GetTasksByProjectIdQuery
|
||||
{
|
||||
ProjectId = projectId,
|
||||
Status = status,
|
||||
AssigneeId = assigneeId
|
||||
};
|
||||
var result = await _mediator.Send(query, cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new task
|
||||
/// </summary>
|
||||
[HttpPost("stories/{storyId:guid}/tasks")]
|
||||
[ProducesResponseType(typeof(TaskDto), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> CreateTask(
|
||||
Guid storyId,
|
||||
[FromBody] CreateTaskRequest request,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var command = new CreateTaskCommand
|
||||
{
|
||||
StoryId = storyId,
|
||||
Title = request.Title,
|
||||
Description = request.Description,
|
||||
Priority = request.Priority,
|
||||
EstimatedHours = request.EstimatedHours,
|
||||
AssigneeId = request.AssigneeId,
|
||||
CreatedBy = request.CreatedBy
|
||||
};
|
||||
|
||||
var result = await _mediator.Send(command, cancellationToken);
|
||||
return CreatedAtAction(nameof(GetTask), new { id = result.Id }, result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update an existing task
|
||||
/// </summary>
|
||||
[HttpPut("tasks/{id:guid}")]
|
||||
[ProducesResponseType(typeof(TaskDto), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> UpdateTask(
|
||||
Guid id,
|
||||
[FromBody] UpdateTaskRequest request,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var command = new UpdateTaskCommand
|
||||
{
|
||||
TaskId = id,
|
||||
Title = request.Title,
|
||||
Description = request.Description,
|
||||
Status = request.Status,
|
||||
Priority = request.Priority,
|
||||
EstimatedHours = request.EstimatedHours,
|
||||
AssigneeId = request.AssigneeId
|
||||
};
|
||||
|
||||
var result = await _mediator.Send(command, cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete a task
|
||||
/// </summary>
|
||||
[HttpDelete("tasks/{id:guid}")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> DeleteTask(Guid id, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var command = new DeleteTaskCommand { TaskId = id };
|
||||
await _mediator.Send(command, cancellationToken);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Assign a task to a user
|
||||
/// </summary>
|
||||
[HttpPut("tasks/{id:guid}/assign")]
|
||||
[ProducesResponseType(typeof(TaskDto), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> AssignTask(
|
||||
Guid id,
|
||||
[FromBody] AssignTaskRequest request,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var command = new AssignTaskCommand
|
||||
{
|
||||
TaskId = id,
|
||||
AssigneeId = request.AssigneeId
|
||||
};
|
||||
|
||||
var result = await _mediator.Send(command, cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update task status (for Kanban board drag & drop)
|
||||
/// </summary>
|
||||
[HttpPut("tasks/{id:guid}/status")]
|
||||
[ProducesResponseType(typeof(TaskDto), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> UpdateTaskStatus(
|
||||
Guid id,
|
||||
[FromBody] UpdateTaskStatusRequest request,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var command = new UpdateTaskStatusCommand
|
||||
{
|
||||
TaskId = id,
|
||||
NewStatus = request.NewStatus
|
||||
};
|
||||
|
||||
var result = await _mediator.Send(command, cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request model for creating a task
|
||||
/// </summary>
|
||||
public record CreateTaskRequest
|
||||
{
|
||||
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; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request model for updating a task
|
||||
/// </summary>
|
||||
public record UpdateTaskRequest
|
||||
{
|
||||
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 decimal? EstimatedHours { get; init; }
|
||||
public Guid? AssigneeId { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request model for assigning a task
|
||||
/// </summary>
|
||||
public record AssignTaskRequest
|
||||
{
|
||||
public Guid? AssigneeId { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request model for updating task status
|
||||
/// </summary>
|
||||
public record UpdateTaskStatusRequest
|
||||
{
|
||||
public string NewStatus { get; init; } = string.Empty;
|
||||
}
|
||||
@@ -30,8 +30,12 @@ public static class ModuleExtensions
|
||||
services.AddScoped<IProjectRepository, ProjectRepository>();
|
||||
services.AddScoped<IUnitOfWork, UnitOfWork>();
|
||||
|
||||
// Register MediatR handlers from Application assembly
|
||||
services.AddMediatR(typeof(CreateProjectCommand).Assembly);
|
||||
// Register MediatR handlers from Application assembly (v13.x syntax)
|
||||
services.AddMediatR(cfg =>
|
||||
{
|
||||
cfg.LicenseKey = configuration["MediatR:LicenseKey"];
|
||||
cfg.RegisterServicesFromAssembly(typeof(CreateProjectCommand).Assembly);
|
||||
});
|
||||
|
||||
// Register FluentValidation validators
|
||||
services.AddValidatorsFromAssembly(typeof(CreateProjectCommand).Assembly);
|
||||
|
||||
130
colaflow-api/src/ColaFlow.API/Handlers/GlobalExceptionHandler.cs
Normal file
130
colaflow-api/src/ColaFlow.API/Handlers/GlobalExceptionHandler.cs
Normal file
@@ -0,0 +1,130 @@
|
||||
using System.Diagnostics;
|
||||
using FluentValidation;
|
||||
using Microsoft.AspNetCore.Diagnostics;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Exceptions;
|
||||
|
||||
namespace ColaFlow.API.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// Global exception handler using IExceptionHandler (.NET 8+)
|
||||
/// Handles all unhandled exceptions and converts them to ProblemDetails responses
|
||||
/// </summary>
|
||||
public sealed class GlobalExceptionHandler : IExceptionHandler
|
||||
{
|
||||
private readonly ILogger<GlobalExceptionHandler> _logger;
|
||||
|
||||
public GlobalExceptionHandler(ILogger<GlobalExceptionHandler> logger)
|
||||
{
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
public async ValueTask<bool> TryHandleAsync(
|
||||
HttpContext httpContext,
|
||||
Exception exception,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
// Log with appropriate level based on exception type
|
||||
if (exception is ValidationException or DomainException or NotFoundException)
|
||||
{
|
||||
_logger.LogWarning(exception, "Client error occurred: {Message}", exception.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogError(exception, "Internal server error occurred: {Message}", exception.Message);
|
||||
}
|
||||
|
||||
var problemDetails = exception switch
|
||||
{
|
||||
ValidationException validationEx => CreateValidationProblemDetails(httpContext, validationEx),
|
||||
DomainException domainEx => CreateDomainProblemDetails(httpContext, domainEx),
|
||||
NotFoundException notFoundEx => CreateNotFoundProblemDetails(httpContext, notFoundEx),
|
||||
_ => CreateInternalServerErrorProblemDetails(httpContext, exception)
|
||||
};
|
||||
|
||||
httpContext.Response.StatusCode = problemDetails.Status ?? StatusCodes.Status500InternalServerError;
|
||||
await httpContext.Response.WriteAsJsonAsync(problemDetails, cancellationToken);
|
||||
|
||||
return true; // Exception handled
|
||||
}
|
||||
|
||||
private static ProblemDetails CreateValidationProblemDetails(
|
||||
HttpContext context,
|
||||
ValidationException exception)
|
||||
{
|
||||
var errors = exception.Errors
|
||||
.GroupBy(e => e.PropertyName)
|
||||
.ToDictionary(
|
||||
g => g.Key,
|
||||
g => g.Select(e => e.ErrorMessage).ToArray()
|
||||
);
|
||||
|
||||
return new ProblemDetails
|
||||
{
|
||||
Type = "https://tools.ietf.org/html/rfc7231#section-6.5.1",
|
||||
Title = "Validation Error",
|
||||
Status = StatusCodes.Status400BadRequest,
|
||||
Detail = "One or more validation errors occurred.",
|
||||
Instance = context.Request.Path,
|
||||
Extensions =
|
||||
{
|
||||
["traceId"] = Activity.Current?.Id ?? context.TraceIdentifier,
|
||||
["errors"] = errors
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static ProblemDetails CreateDomainProblemDetails(
|
||||
HttpContext context,
|
||||
DomainException exception)
|
||||
{
|
||||
return new ProblemDetails
|
||||
{
|
||||
Type = "https://tools.ietf.org/html/rfc7231#section-6.5.1",
|
||||
Title = "Domain Error",
|
||||
Status = StatusCodes.Status400BadRequest,
|
||||
Detail = exception.Message,
|
||||
Instance = context.Request.Path,
|
||||
Extensions =
|
||||
{
|
||||
["traceId"] = Activity.Current?.Id ?? context.TraceIdentifier
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static ProblemDetails CreateNotFoundProblemDetails(
|
||||
HttpContext context,
|
||||
NotFoundException exception)
|
||||
{
|
||||
return new ProblemDetails
|
||||
{
|
||||
Type = "https://tools.ietf.org/html/rfc7231#section-6.5.4",
|
||||
Title = "Resource Not Found",
|
||||
Status = StatusCodes.Status404NotFound,
|
||||
Detail = exception.Message,
|
||||
Instance = context.Request.Path,
|
||||
Extensions =
|
||||
{
|
||||
["traceId"] = Activity.Current?.Id ?? context.TraceIdentifier
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static ProblemDetails CreateInternalServerErrorProblemDetails(
|
||||
HttpContext context,
|
||||
Exception exception)
|
||||
{
|
||||
return new ProblemDetails
|
||||
{
|
||||
Type = "https://tools.ietf.org/html/rfc7231#section-6.6.1",
|
||||
Title = "Internal Server Error",
|
||||
Status = StatusCodes.Status500InternalServerError,
|
||||
Detail = "An unexpected error occurred. Please contact support if the problem persists.",
|
||||
Instance = context.Request.Path,
|
||||
Extensions =
|
||||
{
|
||||
["traceId"] = Activity.Current?.Id ?? context.TraceIdentifier
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
using FluentValidation;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Exceptions;
|
||||
|
||||
namespace ColaFlow.API.Middleware;
|
||||
|
||||
/// <summary>
|
||||
/// Global exception handler middleware
|
||||
/// </summary>
|
||||
public class GlobalExceptionHandlerMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly ILogger<GlobalExceptionHandlerMiddleware> _logger;
|
||||
|
||||
public GlobalExceptionHandlerMiddleware(
|
||||
RequestDelegate next,
|
||||
ILogger<GlobalExceptionHandlerMiddleware> logger)
|
||||
{
|
||||
_next = next ?? throw new ArgumentNullException(nameof(next));
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
public async Task InvokeAsync(HttpContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _next(context);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await HandleExceptionAsync(context, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleExceptionAsync(HttpContext context, Exception exception)
|
||||
{
|
||||
context.Response.ContentType = "application/json";
|
||||
|
||||
var (statusCode, response) = exception switch
|
||||
{
|
||||
ValidationException validationEx => (
|
||||
StatusCodes.Status400BadRequest,
|
||||
new
|
||||
{
|
||||
StatusCode = StatusCodes.Status400BadRequest,
|
||||
Message = "Validation failed",
|
||||
Errors = validationEx.Errors.Select(e => new
|
||||
{
|
||||
Property = e.PropertyName,
|
||||
Message = e.ErrorMessage
|
||||
})
|
||||
}),
|
||||
DomainException domainEx => (
|
||||
StatusCodes.Status400BadRequest,
|
||||
new
|
||||
{
|
||||
StatusCode = StatusCodes.Status400BadRequest,
|
||||
Message = domainEx.Message
|
||||
}),
|
||||
NotFoundException notFoundEx => (
|
||||
StatusCodes.Status404NotFound,
|
||||
new
|
||||
{
|
||||
StatusCode = StatusCodes.Status404NotFound,
|
||||
Message = notFoundEx.Message
|
||||
}),
|
||||
_ => (
|
||||
StatusCodes.Status500InternalServerError,
|
||||
new
|
||||
{
|
||||
StatusCode = StatusCodes.Status500InternalServerError,
|
||||
Message = "An internal server error occurred"
|
||||
})
|
||||
};
|
||||
|
||||
context.Response.StatusCode = statusCode;
|
||||
|
||||
// Log with appropriate level
|
||||
if (statusCode >= 500)
|
||||
{
|
||||
_logger.LogError(exception, "Internal server error occurred: {Message}", exception.Message);
|
||||
}
|
||||
else if (statusCode >= 400)
|
||||
{
|
||||
_logger.LogWarning(exception, "Client error occurred: {Message}", exception.Message);
|
||||
}
|
||||
|
||||
var jsonResponse = JsonSerializer.Serialize(response, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
||||
});
|
||||
|
||||
await context.Response.WriteAsync(jsonResponse);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
using ColaFlow.API.Extensions;
|
||||
using ColaFlow.API.Middleware;
|
||||
using ColaFlow.API.Handlers;
|
||||
using Scalar.AspNetCore;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
@@ -10,6 +10,10 @@ builder.Services.AddProjectManagementModule(builder.Configuration);
|
||||
// Add controllers
|
||||
builder.Services.AddControllers();
|
||||
|
||||
// Configure exception handling (IExceptionHandler - .NET 8+)
|
||||
builder.Services.AddExceptionHandler<GlobalExceptionHandler>();
|
||||
builder.Services.AddProblemDetails();
|
||||
|
||||
// Configure CORS for frontend
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
@@ -34,7 +38,7 @@ if (app.Environment.IsDevelopment())
|
||||
}
|
||||
|
||||
// Global exception handler (should be first in pipeline)
|
||||
app.UseMiddleware<GlobalExceptionHandlerMiddleware>();
|
||||
app.UseExceptionHandler();
|
||||
|
||||
// Enable CORS
|
||||
app.UseCors("AllowFrontend");
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
"ConnectionStrings": {
|
||||
"PMDatabase": "Host=localhost;Port=5432;Database=colaflow_pm;Username=colaflow;Password=colaflow_dev_password"
|
||||
},
|
||||
"MediatR": {
|
||||
"LicenseKey": "eyJhbGciOiJSUzI1NiIsImtpZCI6Ikx1Y2t5UGVubnlTb2Z0d2FyZUxpY2Vuc2VLZXkvYmJiMTNhY2I1OTkwNGQ4OWI0Y2IxYzg1ZjA4OGNjZjkiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2x1Y2t5cGVubnlzb2Z0d2FyZS5jb20iLCJhdWQiOiJMdWNreVBlbm55U29mdHdhcmUiLCJleHAiOiIxNzkzNTc3NjAwIiwiaWF0IjoiMTc2MjEyNTU2MiIsImFjY291bnRfaWQiOiIwMTlhNDZkZGZiZjk3YTk4Yjg1ZTVmOTllNWRhZjIwNyIsImN1c3RvbWVyX2lkIjoiY3RtXzAxazkzZHdnOG0weDByanp3Mm5rM2dxeDExIiwic3ViX2lkIjoiLSIsImVkaXRpb24iOiIwIiwidHlwZSI6IjIifQ.V45vUlze27pQG3Vs9dvagyUTSp-a74ymB6I0TIGD_NwFt1mMMPsuVXOKH1qK7A7V5qDQBvYyryzJy8xRE1rRKq2MJKgyfYjvzuGkpBbKbM6JRQPYknb5tjF-Rf3LAeWp73FiqbPZOPt5saCsoKqUHej-4zcKg5GA4y-PpGaGAONKyqwK9G2rvc1BUHfEnHKRMr0pprA5W1Yx-Lry85KOckUsI043HGOdfbubnGdAZs74FKvrV2qVir6K6VsZjWwX8IFnl1CzxjICa5MxyHOAVpXRnRtMt6fpsA1fMstFuRjq_2sbqGfsTv6LyCzLPnXdmU5DnWZHUcjy0xlAT_f0aw"
|
||||
},
|
||||
"AutoMapper": {
|
||||
"LicenseKey": "eyJhbGciOiJSUzI1NiIsImtpZCI6Ikx1Y2t5UGVubnlTb2Z0d2FyZUxpY2Vuc2VLZXkvYmJiMTNhY2I1OTkwNGQ4OWI0Y2IxYzg1ZjA4OGNjZjkiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2x1Y2t5cGVubnlzb2Z0d2FyZS5jb20iLCJhdWQiOiJMdWNreVBlbm55U29mdHdhcmUiLCJleHAiOiIxNzkzNTc3NjAwIiwiaWF0IjoiMTc2MjEyNTU2MiIsImFjY291bnRfaWQiOiIwMTlhNDZkZGZiZjk3YTk4Yjg1ZTVmOTllNWRhZjIwNyIsImN1c3RvbWVyX2lkIjoiY3RtXzAxazkzZHdnOG0weDByanp3Mm5rM2dxeDExIiwic3ViX2lkIjoiLSIsImVkaXRpb24iOiIwIiwidHlwZSI6IjIifQ.V45vUlze27pQG3Vs9dvagyUTSp-a74ymB6I0TIGD_NwFt1mMMPsuVXOKH1qK7A7V5qDQBvYyryzJy8xRE1rRKq2MJKgyfYjvzuGkpBbKbM6JRQPYknb5tjF-Rf3LAeWp73FiqbPZOPt5saCsoKqUHej-4zcKg5GA4y-PpGaGAONKyqwK9G2rvc1BUHfEnHKRMr0pprA5W1Yx-Lry85KOckUsI043HGOdfbubnGdAZs74FKvrV2qVir6K6VsZjWwX8IFnl1CzxjICa5MxyHOAVpXRnRtMt6fpsA1fMstFuRjq_2sbqGfsTv6LyCzLPnXdmU5DnWZHUcjy0xlAT_f0aw"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
|
||||
@@ -5,11 +5,10 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="12.0.1" />
|
||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
||||
<PackageReference Include="AutoMapper" Version="15.1.0" />
|
||||
<PackageReference Include="FluentValidation" Version="12.0.0" />
|
||||
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="12.0.0" />
|
||||
<PackageReference Include="MediatR" Version="11.1.0" />
|
||||
<PackageReference Include="MediatR" Version="13.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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",
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -56,7 +56,21 @@ public abstract class Enumeration : IComparable
|
||||
|
||||
public static T FromDisplayName<T>(string displayName) where T : Enumeration
|
||||
{
|
||||
var matchingItem = Parse<T, string>(displayName, "display name", item => item.Name == displayName);
|
||||
// First try exact match
|
||||
var matchingItem = GetAll<T>().FirstOrDefault(item => item.Name == displayName);
|
||||
|
||||
// If not found, try removing spaces from both the input and the enumeration names
|
||||
// This allows "InProgress" to match "In Progress", "ToDo" to match "To Do", etc.
|
||||
if (matchingItem == null)
|
||||
{
|
||||
var normalizedInput = displayName.Replace(" ", "");
|
||||
matchingItem = GetAll<T>().FirstOrDefault(item =>
|
||||
item.Name.Replace(" ", "").Equals(normalizedInput, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
if (matchingItem == null)
|
||||
throw new InvalidOperationException($"'{displayName}' is not a valid display name in {typeof(T)}");
|
||||
|
||||
return matchingItem;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user