feat(backend): Implement complete Issue Management Module
Implemented full-featured Issue Management module following Clean Architecture,
DDD, CQRS and Event Sourcing patterns to support Kanban board functionality.
## Domain Layer
- Issue aggregate root with business logic
- IssueType, IssueStatus, IssuePriority enums
- Domain events: IssueCreated, IssueUpdated, IssueStatusChanged, IssueAssigned, IssueDeleted
- IIssueRepository and IUnitOfWork interfaces
- Domain exceptions (DomainException, NotFoundException)
## Application Layer
- **Commands**: CreateIssue, UpdateIssue, ChangeIssueStatus, AssignIssue, DeleteIssue
- **Queries**: GetIssueById, ListIssues, ListIssuesByStatus
- Command/Query handlers with validation
- FluentValidation validators for all commands
- Event handlers for domain events
- IssueDto for data transfer
- ValidationBehavior pipeline
## Infrastructure Layer
- IssueManagementDbContext with EF Core 9.0
- IssueConfiguration for entity mapping
- IssueRepository implementation
- UnitOfWork implementation
- Multi-tenant support with TenantId filtering
- Optimized indexes for query performance
## API Layer
- IssuesController with full REST API
- GET /api/v1/projects/{projectId}/issues (list with optional status filter)
- GET /api/v1/projects/{projectId}/issues/{id} (get by id)
- POST /api/v1/projects/{projectId}/issues (create)
- PUT /api/v1/projects/{projectId}/issues/{id} (update)
- PUT /api/v1/projects/{projectId}/issues/{id}/status (change status for Kanban)
- PUT /api/v1/projects/{projectId}/issues/{id}/assign (assign to user)
- DELETE /api/v1/projects/{projectId}/issues/{id} (delete)
- Request models: CreateIssueRequest, UpdateIssueRequest, ChangeStatusRequest, AssignIssueRequest
- JWT authentication required
- Real-time SignalR notifications integrated
## Module Registration
- Added AddIssueManagementModule extension method
- Registered in Program.cs
- Added IMDatabase connection string
- Added project references to ColaFlow.API.csproj
## Architecture Patterns
- ✅ Clean Architecture (Domain, Application, Infrastructure, API layers)
- ✅ DDD (Aggregate roots, value objects, domain events)
- ✅ CQRS (Command/Query separation)
- ✅ Event Sourcing (Domain events with MediatR)
- ✅ Repository Pattern (IIssueRepository)
- ✅ Unit of Work (Transactional consistency)
- ✅ Dependency Injection
- ✅ FluentValidation
- ✅ Multi-tenancy support
## Real-time Features
- SignalR integration via IRealtimeNotificationService
- NotifyIssueCreated, NotifyIssueUpdated, NotifyIssueStatusChanged, NotifyIssueAssigned, NotifyIssueDeleted
- Project-level broadcasting for collaborative editing
## Next Steps
1. Stop running API process if exists
2. Run: dotnet ef migrations add InitialIssueModule --context IssueManagementDbContext --startup-project ../../../ColaFlow.API
3. Run: dotnet ef database update --context IssueManagementDbContext --startup-project ../../../ColaFlow.API
4. Create test scripts
5. Verify all CRUD operations and real-time notifications
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,8 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Modules\ProjectManagement\ColaFlow.Modules.ProjectManagement.Application\ColaFlow.Modules.ProjectManagement.Application.csproj" />
|
||||
<ProjectReference Include="..\Modules\ProjectManagement\ColaFlow.Modules.ProjectManagement.Infrastructure\ColaFlow.Modules.ProjectManagement.Infrastructure.csproj" />
|
||||
<ProjectReference Include="..\Modules\IssueManagement\ColaFlow.Modules.IssueManagement.Application\ColaFlow.Modules.IssueManagement.Application.csproj" />
|
||||
<ProjectReference Include="..\Modules\IssueManagement\ColaFlow.Modules.IssueManagement.Infrastructure\ColaFlow.Modules.IssueManagement.Infrastructure.csproj" />
|
||||
<ProjectReference Include="..\Shared\ColaFlow.Shared.Kernel\ColaFlow.Shared.Kernel.csproj" />
|
||||
<ProjectReference Include="..\Modules\Identity\ColaFlow.Modules.Identity.Application\ColaFlow.Modules.Identity.Application.csproj" />
|
||||
<ProjectReference Include="..\Modules\Identity\ColaFlow.Modules.Identity.Infrastructure\ColaFlow.Modules.Identity.Infrastructure.csproj" />
|
||||
|
||||
146
colaflow-api/src/ColaFlow.API/Controllers/IssuesController.cs
Normal file
146
colaflow-api/src/ColaFlow.API/Controllers/IssuesController.cs
Normal file
@@ -0,0 +1,146 @@
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using ColaFlow.Modules.IssueManagement.Application.DTOs;
|
||||
using ColaFlow.Modules.IssueManagement.Application.Commands.CreateIssue;
|
||||
using ColaFlow.Modules.IssueManagement.Application.Commands.UpdateIssue;
|
||||
using ColaFlow.Modules.IssueManagement.Application.Commands.ChangeIssueStatus;
|
||||
using ColaFlow.Modules.IssueManagement.Application.Commands.AssignIssue;
|
||||
using ColaFlow.Modules.IssueManagement.Application.Commands.DeleteIssue;
|
||||
using ColaFlow.Modules.IssueManagement.Application.Queries.GetIssueById;
|
||||
using ColaFlow.Modules.IssueManagement.Application.Queries.ListIssues;
|
||||
using ColaFlow.Modules.IssueManagement.Application.Queries.ListIssuesByStatus;
|
||||
using ColaFlow.Modules.IssueManagement.Domain.Enums;
|
||||
using ColaFlow.API.Services;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace ColaFlow.API.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/v1/projects/{projectId:guid}/issues")]
|
||||
[Authorize]
|
||||
public class IssuesController : ControllerBase
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly IRealtimeNotificationService _notificationService;
|
||||
|
||||
public IssuesController(IMediator mediator, IRealtimeNotificationService notificationService)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_notificationService = notificationService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> ListIssues(Guid projectId, [FromQuery] IssueStatus? status = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var result = status.HasValue
|
||||
? await _mediator.Send(new ListIssuesByStatusQuery(projectId, status.Value), cancellationToken)
|
||||
: await _mediator.Send(new ListIssuesQuery(projectId), cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("{id:guid}")]
|
||||
public async Task<IActionResult> GetIssue(Guid projectId, Guid id, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var result = await _mediator.Send(new GetIssueByIdQuery(id), cancellationToken);
|
||||
if (result == null)
|
||||
return NotFound();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> CreateIssue(Guid projectId, [FromBody] CreateIssueRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var tenantId = GetTenantId();
|
||||
var userId = GetUserId();
|
||||
var command = new CreateIssueCommand(projectId, tenantId, request.Title, request.Description, request.Type, request.Priority, userId);
|
||||
var result = await _mediator.Send(command, cancellationToken);
|
||||
await _notificationService.NotifyIssueCreated(tenantId, projectId, result);
|
||||
return CreatedAtAction(nameof(GetIssue), new { projectId, id = result.Id }, result);
|
||||
}
|
||||
|
||||
[HttpPut("{id:guid}")]
|
||||
public async Task<IActionResult> UpdateIssue(Guid projectId, Guid id, [FromBody] UpdateIssueRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var command = new UpdateIssueCommand(id, request.Title, request.Description, request.Priority);
|
||||
await _mediator.Send(command, cancellationToken);
|
||||
var issue = await _mediator.Send(new GetIssueByIdQuery(id), cancellationToken);
|
||||
if (issue != null)
|
||||
await _notificationService.NotifyIssueUpdated(issue.TenantId, projectId, issue);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpPut("{id:guid}/status")]
|
||||
public async Task<IActionResult> ChangeStatus(Guid projectId, Guid id, [FromBody] ChangeStatusRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var command = new ChangeIssueStatusCommand(id, request.Status);
|
||||
await _mediator.Send(command, cancellationToken);
|
||||
var issue = await _mediator.Send(new GetIssueByIdQuery(id), cancellationToken);
|
||||
if (issue != null)
|
||||
await _notificationService.NotifyIssueStatusChanged(issue.TenantId, projectId, id, request.OldStatus?.ToString() ?? "Unknown", request.Status.ToString());
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpPut("{id:guid}/assign")]
|
||||
public async Task<IActionResult> AssignIssue(Guid projectId, Guid id, [FromBody] AssignIssueRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var command = new AssignIssueCommand(id, request.AssigneeId);
|
||||
await _mediator.Send(command, cancellationToken);
|
||||
var issue = await _mediator.Send(new GetIssueByIdQuery(id), cancellationToken);
|
||||
if (issue != null)
|
||||
await _notificationService.NotifyIssueUpdated(issue.TenantId, projectId, issue);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("{id:guid}")]
|
||||
public async Task<IActionResult> DeleteIssue(Guid projectId, Guid id, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var issue = await _mediator.Send(new GetIssueByIdQuery(id), cancellationToken);
|
||||
await _mediator.Send(new DeleteIssueCommand(id), cancellationToken);
|
||||
if (issue != null)
|
||||
await _notificationService.NotifyIssueDeleted(issue.TenantId, projectId, id);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
private Guid GetTenantId()
|
||||
{
|
||||
var claim = User.FindFirst("tenant_id");
|
||||
if (claim == null || !Guid.TryParse(claim.Value, out var id))
|
||||
throw new UnauthorizedAccessException("TenantId not found");
|
||||
return id;
|
||||
}
|
||||
|
||||
private Guid GetUserId()
|
||||
{
|
||||
var claim = User.FindFirst(ClaimTypes.NameIdentifier);
|
||||
if (claim == null || !Guid.TryParse(claim.Value, out var id))
|
||||
throw new UnauthorizedAccessException("UserId not found");
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
public record CreateIssueRequest
|
||||
{
|
||||
public string Title { get; init; } = string.Empty;
|
||||
public string Description { get; init; } = string.Empty;
|
||||
public IssueType Type { get; init; } = IssueType.Task;
|
||||
public IssuePriority Priority { get; init; } = IssuePriority.Medium;
|
||||
}
|
||||
|
||||
public record UpdateIssueRequest
|
||||
{
|
||||
public string Title { get; init; } = string.Empty;
|
||||
public string Description { get; init; } = string.Empty;
|
||||
public IssuePriority Priority { get; init; } = IssuePriority.Medium;
|
||||
}
|
||||
|
||||
public record ChangeStatusRequest
|
||||
{
|
||||
public IssueStatus Status { get; init; }
|
||||
public IssueStatus? OldStatus { get; init; }
|
||||
}
|
||||
|
||||
public record AssignIssueRequest
|
||||
{
|
||||
public Guid? AssigneeId { get; init; }
|
||||
}
|
||||
@@ -6,6 +6,9 @@ using ColaFlow.Modules.ProjectManagement.Application.Commands.CreateProject;
|
||||
using ColaFlow.Modules.ProjectManagement.Domain.Repositories;
|
||||
using ColaFlow.Modules.ProjectManagement.Infrastructure.Persistence;
|
||||
using ColaFlow.Modules.ProjectManagement.Infrastructure.Repositories;
|
||||
using ColaFlow.Modules.IssueManagement.Application.Commands.CreateIssue;
|
||||
using ColaFlow.Modules.IssueManagement.Infrastructure.Persistence;
|
||||
using ColaFlow.Modules.IssueManagement.Infrastructure.Persistence.Repositories;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace ColaFlow.API.Extensions;
|
||||
@@ -35,7 +38,7 @@ public static class ModuleExtensions
|
||||
|
||||
// Register repositories
|
||||
services.AddScoped<IProjectRepository, ProjectRepository>();
|
||||
services.AddScoped<IUnitOfWork, UnitOfWork>();
|
||||
services.AddScoped<IUnitOfWork, ColaFlow.Modules.ProjectManagement.Infrastructure.Persistence.UnitOfWork>();
|
||||
|
||||
// Register MediatR handlers from Application assembly (v13.x syntax)
|
||||
services.AddMediatR(cfg =>
|
||||
@@ -54,4 +57,43 @@ public static class ModuleExtensions
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register IssueManagement Module
|
||||
/// </summary>
|
||||
public static IServiceCollection AddIssueManagementModule(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration,
|
||||
IHostEnvironment? environment = null)
|
||||
{
|
||||
// Only register PostgreSQL DbContext in non-Testing environments
|
||||
if (environment == null || environment.EnvironmentName != "Testing")
|
||||
{
|
||||
// Register DbContext
|
||||
var connectionString = configuration.GetConnectionString("IMDatabase");
|
||||
services.AddDbContext<IssueManagementDbContext>(options =>
|
||||
options.UseNpgsql(connectionString));
|
||||
}
|
||||
|
||||
// Register repositories
|
||||
services.AddScoped<ColaFlow.Modules.IssueManagement.Domain.Repositories.IIssueRepository, IssueRepository>();
|
||||
services.AddScoped<ColaFlow.Modules.IssueManagement.Domain.Repositories.IUnitOfWork, ColaFlow.Modules.IssueManagement.Infrastructure.Persistence.Repositories.UnitOfWork>();
|
||||
|
||||
// Register MediatR handlers from Application assembly
|
||||
services.AddMediatR(cfg =>
|
||||
{
|
||||
cfg.LicenseKey = configuration["MediatR:LicenseKey"];
|
||||
cfg.RegisterServicesFromAssembly(typeof(CreateIssueCommand).Assembly);
|
||||
});
|
||||
|
||||
// Register FluentValidation validators
|
||||
services.AddValidatorsFromAssembly(typeof(CreateIssueCommand).Assembly);
|
||||
|
||||
// Register pipeline behaviors
|
||||
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ColaFlow.Modules.IssueManagement.Application.Behaviors.ValidationBehavior<,>));
|
||||
|
||||
Console.WriteLine("[IssueManagement] Module registered");
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@ var builder = WebApplication.CreateBuilder(args);
|
||||
// Register ProjectManagement Module
|
||||
builder.Services.AddProjectManagementModule(builder.Configuration, builder.Environment);
|
||||
|
||||
// Register IssueManagement Module
|
||||
builder.Services.AddIssueManagementModule(builder.Configuration, builder.Environment);
|
||||
|
||||
// Register Identity Module
|
||||
builder.Services.AddIdentityApplication();
|
||||
builder.Services.AddIdentityInfrastructure(builder.Configuration, builder.Environment);
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"PMDatabase": "Host=localhost;Port=5432;Database=colaflow_pm;Username=colaflow;Password=colaflow_dev_password",
|
||||
"IMDatabase": "Host=localhost;Port=5432;Database=colaflow_im;Username=colaflow;Password=colaflow_dev_password",
|
||||
"DefaultConnection": "Host=localhost;Port=5432;Database=colaflow_identity;Username=colaflow;Password=colaflow_dev_password"
|
||||
},
|
||||
"Email": {
|
||||
|
||||
Reference in New Issue
Block a user