Skip to content

Comments

[refactor] Apply mediator DP on TrustFunction#185

Merged
Ghass-M merged 6 commits intomasterfrom
feature/trust-function-mediator
Aug 26, 2025
Merged

[refactor] Apply mediator DP on TrustFunction#185
Ghass-M merged 6 commits intomasterfrom
feature/trust-function-mediator

Conversation

@Ghass-M
Copy link
Contributor

@Ghass-M Ghass-M commented Aug 21, 2025

PR Title

Refactor Trust HTTP endpoints to Mediator (remove TrustService) + add command handlers and tests

Summary

  • What: Replaces ITrustService/TrustService with MediatR requests/handlers; updates TrustFunction to dispatch via IMediator; adds targeted unit tests for trust flows.
  • Why: Align with CQRS/Mediator pattern, reduce coupling in Azure Functions, improve testability.
  • Impact: No API surface changes; behavior remains equivalent.

Changes

  • Functions
    • src/ByteSync.Functions/Http/TrustFunction.cs
      • Now injects only IMediator.
      • Sends:
        • SetAuthCheckedRequest
        • RequestTrustPublicKeyRequest
        • InformPublicKeyValidationIsFinishedRequest
  • ServerCommon (new requests/handlers)
    • src/ByteSync.ServerCommon/Commands/Trusts/SetAuthCheckedRequest.cs
    • src/ByteSync.ServerCommon/Commands/Trusts/SetAuthCheckedCommandHandler.cs
    • src/ByteSync.ServerCommon/Commands/Trusts/RequestTrustPublicKeyRequest.cs
    • src/ByteSync.ServerCommon/Commands/Trusts/RequestTrustPublicKeyCommandHandler.cs
    • src/ByteSync.ServerCommon/Commands/Trusts/InformPublicKeyValidationIsFinishedRequest.cs
    • src/ByteSync.ServerCommon/Commands/Trusts/InformPublicKeyValidationIsFinishedCommandHandler.cs
  • Removed
    • ITrustService and TrustService (obsolete after mediator migration)
  • Tests
    • tests/ByteSync.ServerCommon.Tests/Commands/Trusts/RequestTrustPublicKeyCommandHandlerTests.cs
    • tests/ByteSync.ServerCommon.Tests/Commands/Trusts/InformPublicKeyValidationIsFinishedCommandHandlerTests.cs
    • Cover both positive paths and “not found” cases.

Behavior

  • Equivalent:
    • Set auth checked
    • Request trust public key
    • Inform public key validation finished
  • Handlers use ICloudSessionsRepository and IInvokeClientsService in the same way the old service did.

Dependency Injection

  • Ensure ITrustService registrations are removed.
  • Handlers will be discovered via MediatR assembly scanning.

Validation

  • Build:
    • dotnet build ByteSync.sln --verbosity quiet
  • Tests:
    • dotnet test tests/ByteSync.ServerCommon.Tests/ByteSync.ServerCommon.Tests.csproj --nologo
    • Optionally run the full test suite for additional confidence.

Notes / Follow-ups

  • In RequestTrustPublicKeyCommandHandler, the logger is typed as ILogger<SetAuthCheckedCommandHandler>; it should likely be ILogger<RequestTrustPublicKeyCommandHandler>.
  • In logs:
    • Else-branch message in RequestTrustPublicKeyCommandHandler references “InformPublicKeyValidationIsFinished” instead of the current action.
    • Session-missing log in InformPublicKeyValidationIsFinishedCommandHandler says “AskCloudSessionMembersPublicKeys” (copy/paste artifact).
  • Consider correcting these log category/message nits either here or in a follow-up.

Risks

  • Low. Internal refactor; handlers mirror prior service logic; covered by unit tests.

  • Moved trust logic behind MediatR requests and handlers; removed ITrustService/TrustService.

  • Updated TrustFunction to send mediator requests; added unit tests for happy/negative paths.

  • Called out minor logger category and message nits for follow-up.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the trust functionality from a traditional service pattern to the CQRS/Mediator pattern, removing ITrustService and TrustService in favor of MediatR command handlers.

  • Replaces ITrustService/TrustService with three new MediatR request/handler pairs for trust operations
  • Updates TrustFunction to dispatch commands via IMediator instead of direct service calls
  • Adds comprehensive unit tests for all three new command handlers covering both success and failure scenarios

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
TrustFunction.cs Updated to inject only IMediator and dispatch trust commands through it
SetAuthChecked* New MediatR request and handler for setting authentication checked status
RequestTrustPublicKey* New MediatR request and handler for requesting trust public keys
InformPublicKeyValidationIsFinished* New MediatR request and handler for informing validation completion
TrustService.cs Removed obsolete service implementation
ITrustService.cs Removed obsolete service interface
Test files Added comprehensive unit tests for all three command handlers

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@sonarqubecloud
Copy link

@Ghass-M Ghass-M merged commit 040947a into master Aug 26, 2025
25 checks passed
@Ghass-M Ghass-M deleted the feature/trust-function-mediator branch August 26, 2025 15:15
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