Files
ColaFlow/colaflow-api/src/ColaFlow.API/Extensions/ModuleExtensions.cs
Yaojia Wang 6b11af9bea 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>
2025-11-04 11:38:04 +01:00

100 lines
4.1 KiB
C#

using Microsoft.EntityFrameworkCore;
using FluentValidation;
using MediatR;
using ColaFlow.Modules.ProjectManagement.Application.Behaviors;
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;
/// <summary>
/// Extension methods for registering modules
/// </summary>
public static class ModuleExtensions
{
/// <summary>
/// Register ProjectManagement Module
/// </summary>
public static IServiceCollection AddProjectManagementModule(
this IServiceCollection services,
IConfiguration configuration,
IHostEnvironment? environment = null)
{
// Only register PostgreSQL DbContext in non-Testing environments
// In Testing environment, WebApplicationFactory will register InMemory provider
if (environment == null || environment.EnvironmentName != "Testing")
{
// Register DbContext
var connectionString = configuration.GetConnectionString("PMDatabase");
services.AddDbContext<PMDbContext>(options =>
options.UseNpgsql(connectionString));
}
// Register repositories
services.AddScoped<IProjectRepository, ProjectRepository>();
services.AddScoped<IUnitOfWork, ColaFlow.Modules.ProjectManagement.Infrastructure.Persistence.UnitOfWork>();
// 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);
// Register pipeline behaviors
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
Console.WriteLine("[ProjectManagement] Module registered");
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;
}
}