Files
ColaFlow/docs/plans/sprint_2_story_1_task_2.md
Yaojia Wang ebb56cc9f8 feat(backend): Create Sprint 2 backend Stories and Tasks
Created detailed implementation plans for Sprint 2 backend work:

Story 1: Audit Log Foundation (Phase 1)
- Task 1: Design AuditLog database schema and create migration
- Task 2: Create AuditLog entity and Repository
- Task 3: Implement EF Core SaveChangesInterceptor
- Task 4: Write unit tests for audit logging
- Task 5: Integrate with ProjectManagement Module

Story 2: Audit Log Core Features (Phase 2)
- Task 1: Implement Changed Fields Detection (JSON Diff)
- Task 2: Integrate User Context Tracking
- Task 3: Add Multi-Tenant Isolation
- Task 4: Implement Audit Query API
- Task 5: Write Integration Tests

Story 3: Sprint Management Module
- Task 1: Create Sprint Aggregate Root and Domain Events
- Task 2: Implement Sprint Repository and EF Core Configuration
- Task 3: Create CQRS Commands and Queries
- Task 4: Implement Burndown Chart Calculation
- Task 5: Add SignalR Real-Time Notifications
- Task 6: Write Integration Tests

Total: 3 Stories, 16 Tasks, 24 Story Points (8+8+8)
Estimated Duration: 10-12 days

All tasks include:
- Detailed technical implementation guidance
- Code examples and file paths
- Testing requirements (>= 90% coverage)
- Performance benchmarks (< 5ms audit overhead)
- Multi-tenant security validation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 22:56:31 +01:00

3.6 KiB

task_id, story, status, estimated_hours, created_date, assignee
task_id story status estimated_hours created_date assignee
sprint_2_story_1_task_2 sprint_2_story_1 not_started 4 2025-11-05 Backend Team

Task 2: Create AuditLog Entity and Repository

Story: Story 1 - Audit Log Foundation (Phase 1) Estimated: 4 hours

Description

Create the AuditLog domain entity and repository pattern implementation to support CRUD operations and querying audit logs with proper multi-tenant isolation.

Acceptance Criteria

  • AuditLog entity created in Domain layer
  • IAuditLogRepository interface defined
  • AuditLogRepository implementation with EF Core
  • Multi-tenant query filtering applied
  • Unit tests for repository methods

Implementation Details

Files to Create:

  1. Domain Entity: colaflow-api/src/ColaFlow.Domain/Entities/AuditLog.cs
public class AuditLog
{
    public Guid Id { get; set; }
    public Guid TenantId { get; set; }
    public string EntityType { get; set; } = string.Empty;
    public Guid EntityId { get; set; }
    public AuditAction Action { get; set; } // Enum: Create, Update, Delete
    public Guid? UserId { get; set; }
    public DateTime Timestamp { get; set; }
    public string? OldValues { get; set; } // JSONB stored as string
    public string? NewValues { get; set; } // JSONB stored as string
}

public enum AuditAction
{
    Create,
    Update,
    Delete
}
  1. Repository Interface: colaflow-api/src/ColaFlow.Domain/Repositories/IAuditLogRepository.cs
public interface IAuditLogRepository
{
    Task<AuditLog?> GetByIdAsync(Guid id);
    Task<List<AuditLog>> GetByEntityAsync(string entityType, Guid entityId);
    Task AddAsync(AuditLog auditLog);
    Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
}
  1. Repository Implementation: colaflow-api/src/ColaFlow.Infrastructure/Repositories/AuditLogRepository.cs
public class AuditLogRepository : IAuditLogRepository
{
    private readonly ColaFlowDbContext _context;
    private readonly ITenantContext _tenantContext;

    public AuditLogRepository(ColaFlowDbContext context, ITenantContext tenantContext)
    {
        _context = context;
        _tenantContext = tenantContext;
    }

    public async Task<List<AuditLog>> GetByEntityAsync(string entityType, Guid entityId)
    {
        var tenantId = _tenantContext.TenantId;
        return await _context.AuditLogs
            .Where(a => a.TenantId == tenantId && a.EntityType == entityType && a.EntityId == entityId)
            .OrderByDescending(a => a.Timestamp)
            .ToListAsync();
    }

    // ... other methods
}
  1. EF Core Configuration: colaflow-api/src/ColaFlow.Infrastructure/Data/Configurations/AuditLogConfiguration.cs
public class AuditLogConfiguration : IEntityTypeConfiguration<AuditLog>
{
    public void Configure(EntityTypeBuilder<AuditLog> builder)
    {
        builder.ToTable("AuditLogs");
        builder.HasKey(a => a.Id);

        builder.Property(a => a.EntityType).IsRequired().HasMaxLength(100);
        builder.Property(a => a.Action).IsRequired();
        builder.Property(a => a.Timestamp).IsRequired();

        // JSONB columns
        builder.Property(a => a.OldValues).HasColumnType("jsonb");
        builder.Property(a => a.NewValues).HasColumnType("jsonb");

        // Multi-tenant global query filter
        builder.HasQueryFilter(a => a.TenantId == Guid.Empty); // Will be replaced by TenantContext
    }
}

Testing

  • Unit tests for repository methods
  • Verify multi-tenant filtering works
  • Test JSONB serialization/deserialization

Created: 2025-11-05 by Backend Agent