Implemented complete REST API for querying audit logs using CQRS pattern.
Features:
- GET /api/v1/auditlogs/{id} - Retrieve specific audit log
- GET /api/v1/auditlogs/entity/{entityType}/{entityId} - Get entity history
- GET /api/v1/auditlogs/recent?count=100 - Get recent logs (max 1000)
Implementation:
- AuditLogDto - Transfer object for query results
- GetAuditLogByIdQuery + Handler
- GetAuditLogsByEntity Query + Handler
- GetRecentAuditLogsQuery + Handler
- AuditLogsController with 3 endpoints
Technical:
- Multi-tenant isolation via Global Query Filters (automatic)
- Read-only query endpoints (no mutations)
- Swagger/OpenAPI documentation
- Proper HTTP status codes (200 OK, 404 Not Found)
- Cancellation token support
- Primary constructor pattern (modern C# style)
Tests: Build succeeded, no new test failures introduced
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
72 lines
2.8 KiB
C#
72 lines
2.8 KiB
C#
using ColaFlow.Shared.Kernel.Modules;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using FluentValidation;
|
|
using MediatR;
|
|
using ColaFlow.Modules.ProjectManagement.Application.Behaviors;
|
|
using ColaFlow.Modules.ProjectManagement.Application.Commands.CreateProject;
|
|
using ColaFlow.Modules.ProjectManagement.Application.Common.Interfaces;
|
|
using ColaFlow.Modules.ProjectManagement.Domain.Repositories;
|
|
using ColaFlow.Modules.ProjectManagement.Infrastructure.Persistence;
|
|
using ColaFlow.Modules.ProjectManagement.Infrastructure.Persistence.Interceptors;
|
|
using ColaFlow.Modules.ProjectManagement.Infrastructure.Repositories;
|
|
using ColaFlow.Modules.ProjectManagement.Infrastructure.Services;
|
|
|
|
namespace ColaFlow.Modules.ProjectManagement;
|
|
|
|
/// <summary>
|
|
/// Project Management Module
|
|
/// Responsible for managing projects, epics, stories, and tasks.
|
|
/// </summary>
|
|
public class ProjectManagementModule : IModule
|
|
{
|
|
public string Name => "ProjectManagement";
|
|
|
|
public void RegisterServices(IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
// Register tenant context service (must be before DbContext for interceptor)
|
|
services.AddScoped<ITenantContext, TenantContext>();
|
|
|
|
// Register audit interceptor
|
|
services.AddScoped<AuditInterceptor>();
|
|
|
|
// Register DbContext with interceptor
|
|
var connectionString = configuration.GetConnectionString("PMDatabase");
|
|
services.AddDbContext<PMDbContext>((serviceProvider, options) =>
|
|
{
|
|
var auditInterceptor = serviceProvider.GetRequiredService<AuditInterceptor>();
|
|
options.UseNpgsql(connectionString)
|
|
.AddInterceptors(auditInterceptor);
|
|
});
|
|
|
|
// Register repositories
|
|
services.AddScoped<IProjectRepository, ProjectRepository>();
|
|
services.AddScoped<IUnitOfWork, UnitOfWork>();
|
|
|
|
// Note: IProjectNotificationService is registered in the API layer (Program.cs)
|
|
// as it depends on IRealtimeNotificationService which is API-specific
|
|
|
|
// Register MediatR handlers from Application assembly
|
|
services.AddMediatR(cfg =>
|
|
{
|
|
cfg.RegisterServicesFromAssembly(typeof(CreateProjectCommand).Assembly);
|
|
});
|
|
|
|
// Register FluentValidation validators
|
|
services.AddValidatorsFromAssembly(typeof(CreateProjectCommand).Assembly);
|
|
|
|
// Register pipeline behaviors
|
|
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
|
|
|
|
Console.WriteLine($"[{Name}] Module services registered");
|
|
}
|
|
|
|
public void ConfigureApplication(IApplicationBuilder app)
|
|
{
|
|
// Configure module-specific middleware if needed
|
|
Console.WriteLine($"[{Name}] Module application configured");
|
|
}
|
|
}
|