Skip to content

feat(rest-api-application): migrate whitelist context to contract-first architecture - #1947

Merged
josecelano merged 3 commits into
torrust:developfrom
josecelano:1940-migrate-whitelist-context
Jun 26, 2026
Merged

feat(rest-api-application): migrate whitelist context to contract-first architecture#1947
josecelano merged 3 commits into
torrust:developfrom
josecelano:1940-migrate-whitelist-context

Conversation

@josecelano

Copy link
Copy Markdown
Member

Description

Implements SI-2: Migrate whitelist context to contract-first architecture (sub-issue of #1938).

Changes

  • rest-api-protocol: Added v1::context::whitelist/ with WhitelistError protocol error type
  • rest-api-application: Defined WhitelistCommandPort trait and WhitelistApiService use-case
  • rest-api-runtime-adapter: Implemented TrackerWhitelistAdapter wrapping WhitelistManager
  • axum-rest-api-server: Rewired handlers to dispatch through WhitelistApiService instead of calling WhitelistManager directly

Architecture flow

Handlers → WhitelistApiService (use-case)
         → WhitelistCommandPort (trait)
         → TrackerWhitelistAdapter (adapter)
         → WhitelistManager (tracker-core)

Verification

  • WhitelistCommandPort trait defined
  • WhitelistApiService use-case implemented
  • TrackerWhitelistAdapter implemented
  • Axum handlers dispatch through use-case
  • Pre-commit checks pass
  • Pre-push checks pass (full test suite: 108s)

…st architecture

- Add WhitelistError protocol type in rest-api-protocol
- Define WhitelistCommandPort trait in rest-api-application
- Implement WhitelistApiService use-case in rest-api-application
- Implement TrackerWhitelistAdapter in rest-api-runtime-adapter
- Rewire Axum handlers to dispatch through WhitelistApiService
- Update issue spec progress
Copilot AI review requested due to automatic review settings June 26, 2026 07:13
@josecelano josecelano self-assigned this Jun 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Migrates the REST API whitelist context to the contract-first architecture (protocol → application → runtime-adapter → axum transport), aligning this context with the layered pattern introduced by the earlier PoC and reducing direct coupling between Axum handlers and tracker internals.

Changes:

  • Added a whitelist protocol context with a dedicated WhitelistError type in rest-api-protocol.
  • Introduced the application-layer port (WhitelistCommandPort) and use-case (WhitelistApiService) for whitelist commands.
  • Implemented a runtime adapter (TrackerWhitelistAdapter) and rewired Axum routes/handlers to dispatch through the use-case service.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/rest-api-runtime-adapter/src/adapters/whitelist.rs New runtime adapter implementing WhitelistCommandPort by delegating to WhitelistManager.
packages/rest-api-runtime-adapter/src/adapters/mod.rs Exposes the new whitelist adapter module.
packages/rest-api-protocol/src/v1/context/whitelist/resources/whitelist.rs Adds WhitelistError protocol error type for whitelist command failures.
packages/rest-api-protocol/src/v1/context/whitelist/resources/mod.rs Registers whitelist resources module.
packages/rest-api-protocol/src/v1/context/whitelist/mod.rs Adds protocol-level whitelist context module.
packages/rest-api-protocol/src/v1/context/mod.rs Exposes the new whitelist context under v1::context.
packages/rest-api-application/src/use_cases/whitelist.rs Adds WhitelistApiService use-case service for whitelist operations.
packages/rest-api-application/src/use_cases/mod.rs Exposes the new whitelist use-case module.
packages/rest-api-application/src/ports/whitelist.rs Adds WhitelistCommandPort trait defining the application/runtime boundary.
packages/rest-api-application/src/ports/mod.rs Exposes the new whitelist port module.
packages/axum-rest-api-server/src/v1/routes.rs Wires TrackerWhitelistAdapter + WhitelistApiService into the v1 router composition.
packages/axum-rest-api-server/src/v1/context/whitelist/routes.rs Switches whitelist route state from WhitelistManager to WhitelistApiService.
packages/axum-rest-api-server/src/v1/context/whitelist/handlers.rs Replaces direct WhitelistManager calls with WhitelistApiService dispatch.
docs/issues/open/1940-1938-si-2-migrate-whitelist-context.md Updates SI-2 spec progress/checklists to reflect completed migration tasks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/issues/open/1940-1938-si-2-migrate-whitelist-context.md Outdated
Remove the "database error: " prefix from the Display impl to
preserve the original error message format (out-of-scope to change).
Also check the pre-commit/pre-push verification boxes in the spec.
@josecelano

Copy link
Copy Markdown
Member Author

ACK 8b6d92d

@josecelano
josecelano merged commit d0d8ee3 into torrust:develop Jun 26, 2026
16 checks passed
@josecelano josecelano linked an issue Jun 26, 2026 that may be closed by this pull request
6 tasks
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.

SI-2: Migrate whitelist context to contract-first architecture

2 participants