Skip to content

Conversation

@taiphanvan2k3
Copy link
Member

@taiphanvan2k3 taiphanvan2k3 commented Dec 5, 2025

  • Added ReportMessageCommand and ReportMessageResponse records for reporting messages.
  • Created ReportMessageCommandHandler to handle reporting logic, including user authentication and validation.
  • Implemented ReportMessageCommandValidator for input validation.
  • Developed IReportRepository interface and ReportRepository implementation for data operations.
  • Configured Report entity and its database mappings.
  • Updated MessageController to include endpoint for reporting messages.
  • Added necessary migrations for the new Report table in the database.

Summary by CodeRabbit

Release Notes

  • New Features
    • Added message reporting functionality allowing users to report inappropriate or problematic messages with categorized reason options (Inappropriate Content, Incorrect Information, Technical Issue, Other) and optional detailed explanations.

✏️ Tip: You can customize this high-level summary in your review settings.

- Added ReportMessageCommand and ReportMessageResponse records for reporting messages.
- Created ReportMessageCommandHandler to handle reporting logic, including user authentication and validation.
- Implemented ReportMessageCommandValidator for input validation.
- Developed IReportRepository interface and ReportRepository implementation for data operations.
- Configured Report entity and its database mappings.
- Updated MessageController to include endpoint for reporting messages.
- Added necessary migrations for the new Report table in the database.
@taiphanvan2k3 taiphanvan2k3 self-assigned this Dec 5, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 5, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This PR introduces a comprehensive message reporting feature following the CQRS pattern. It includes a command and handler for submitting reports, domain models for Report entities with a ReportCategory enum, repository abstractions and implementations, EF Core configuration with database migrations, and a new API endpoint for reporting messages.

Changes

Cohort / File(s) Summary
CQRS Command & Response Definition
src/Application/Features/Message/Report/ReportMessageCommand.cs
Adds ReportMessageCommand record with MessageId, Category, and optional Reason, implementing ICommand<Result>; adds ReportMessageResponse record containing ReportId, MessageId, Category, and CreatedAt.
Command Handler & Validation
src/Application/Features/Message/Report/ReportMessageCommandHandler.cs, ReportMessageCommandValidator.cs
Introduces sealed handler implementing ICommandHandler<ReportMessageCommand, Result> with authentication, message retrieval, ownership validation, and duplicate report checks; adds validator enforcing valid Category enum and Reason max length of 1000 characters.
Domain Layer
src/Domain/Enums/ReportCategory.cs, src/Domain/Entities/Report.cs, src/Domain/Entities/Message.cs
Adds ReportCategory enum with four members (InappropriateContent, IncorrectInformation, TechnicalIssue, Other); introduces sealed Report entity with MessageId, ReporterId, Category, optional Reason, and Status ("pending" default); adds Reports navigation property to Message.
Application Repository Interface
src/Application/Interfaces/Repositories/IReportRepository.cs
Defines IReportRepository with async methods: GetListAsync (paginated), AddAsync, GetByIdAsync, GetByMessageIdAsync, and GetByReporterIdAsync.
EF Core Configuration & Repository
src/Infrastructure/Data/Configurations/ReportConfiguration.cs, src/Infrastructure/Repositories/ReportRepository.cs, src/Infrastructure/Extensions/ServiceCollectionExtensions.cs
Adds ReportConfiguration implementing IEntityTypeConfiguration with table mapping, property constraints, relationships (Message cascade delete, Reporter restrict), indexes, and query filter excluding soft-deleted records; implements ReportRepository with full CRUD and query methods; registers IReportRepository in DI.
Database Context & DbSet
src/Infrastructure/Data/Contexts/DataContext.cs
Adds public DbSet Reports property.
Database Migrations
src/Infrastructure/Data/Migrations/20251205100156_AddReportTable.cs, 20251205100156_AddReportTable.Designer.cs, DataContextModelSnapshot.cs
Creates migration AddReportTable with Reports table schema, foreign keys (MessageId cascade, ReporterId restrict), indexes, and defaults; updates designer snapshot and model snapshot reflecting new Report entity mapping and updated Message-ThinkingActivity relationship (changed to one-to-one).
Web API Endpoint
src/Web.Api/Controllers/V1/MessageController.cs
Adds ReportMessage action (POST /api/v{version}/messages/{id}/report) accepting ReportMessageCommand and returning ApiResponse, merging route id into command via with-expression before forwarding to MediatR.

Sequence Diagram

sequenceDiagram
    actor Client
    participant API as MessageController
    participant Handler as ReportMessageCommandHandler
    participant CurrentUserSvc as ICurrentUserService
    participant MsgRepo as IMessageRepository
    participant ReportRepo as IReportRepository
    participant DB as Database

    Client->>API: POST /messages/{id}/report<br/>(ReportMessageCommand)
    API->>Handler: Handle(command)
    
    Handler->>CurrentUserSvc: GetCurrentUser()
    CurrentUserSvc-->>Handler: User or null
    alt User Not Authenticated
        Handler-->>API: Unauthorized Error
        API-->>Client: 401 Response
    end
    
    Handler->>MsgRepo: GetByIdAsync(MessageId)
    MsgRepo->>DB: Query Message
    DB-->>MsgRepo: Message or null
    alt Message Not Found
        Handler-->>API: NotFound Error
        API-->>Client: 404 Response
    end
    
    alt Current User is Message Sender
        Handler-->>API: Validation Error<br/>(Cannot report own message)
        API-->>Client: 400 Response
    end
    
    Handler->>ReportRepo: GetByMessageIdAsync(MessageId)
    ReportRepo->>DB: Query Reports by MessageId
    DB-->>ReportRepo: List<Report>
    alt Report Already Exists from User
        Handler-->>API: Validation Error<br/>(Duplicate report)
        API-->>Client: 400 Response
    end
    
    Handler->>ReportRepo: AddAsync(newReport)
    ReportRepo->>DB: Insert Report
    DB-->>ReportRepo: Success
    
    Handler-->>API: Result<ReportMessageResponse>
    API-->>Client: 200 Response<br/>(ReportId, MessageId, Category, CreatedAt)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Handler validation logic: Review authentication checks, message ownership validation, and duplicate report prevention logic for correctness and edge cases
  • EF Core configuration: Verify relationship mappings (cascade delete on Message, restrict on Reporter), query filter effectiveness, and index definitions
  • Database migration: Confirm foreign key constraints, column types/constraints, and model snapshot accuracy reflect intended schema
  • API endpoint integration: Validate error response handling and proper parameter binding from route to command

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Free

📥 Commits

Reviewing files that changed from the base of the PR and between 0e34c0e and 80a6d17.

📒 Files selected for processing (15)
  • src/Application/Features/Message/Report/ReportMessageCommand.cs (1 hunks)
  • src/Application/Features/Message/Report/ReportMessageCommandHandler.cs (1 hunks)
  • src/Application/Features/Message/Report/ReportMessageCommandValidator.cs (1 hunks)
  • src/Application/Interfaces/Repositories/IReportRepository.cs (1 hunks)
  • src/Domain/Entities/Message.cs (1 hunks)
  • src/Domain/Entities/Report.cs (1 hunks)
  • src/Domain/Enums/ReportCategory.cs (1 hunks)
  • src/Infrastructure/Data/Configurations/ReportConfiguration.cs (1 hunks)
  • src/Infrastructure/Data/Contexts/DataContext.cs (1 hunks)
  • src/Infrastructure/Data/Migrations/20251205100156_AddReportTable.Designer.cs (1 hunks)
  • src/Infrastructure/Data/Migrations/20251205100156_AddReportTable.cs (1 hunks)
  • src/Infrastructure/Data/Migrations/DataContextModelSnapshot.cs (3 hunks)
  • src/Infrastructure/Extensions/ServiceCollectionExtensions.cs (1 hunks)
  • src/Infrastructure/Repositories/ReportRepository.cs (1 hunks)
  • src/Web.Api/Controllers/V1/MessageController.cs (2 hunks)

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

@taiphanvan2k3 taiphanvan2k3 merged commit 3ccfa9e into main Dec 5, 2025
2 of 3 checks passed
@taiphanvan2k3 taiphanvan2k3 deleted the feat/implement-message-reporting branch December 5, 2025 10:37
taiphanvan2k3 added a commit that referenced this pull request Dec 22, 2025
…e-reporting

feat: Implement message reporting feature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants