Skip to content

Refactor client registration and enhance validation and messaging#42

Merged
Foqsz merged 30 commits intomasterfrom
develop
Apr 30, 2026
Merged

Refactor client registration and enhance validation and messaging#42
Foqsz merged 30 commits intomasterfrom
develop

Conversation

@Foqsz
Copy link
Copy Markdown
Owner

@Foqsz Foqsz commented Apr 30, 2026

No description provided.

Foqsz and others added 30 commits April 7, 2026 12:31
Separated the client registration POST endpoint from ClientsController
and placed it in a new RegisterController for improved organization
and clearer separation of concerns. No changes to endpoint logic.
- Changed password validation error to use LOGIN_INVALID message.
- Added email uniqueness check when updating client info; throws
  EmailAlreadyExistsException if email is already in use.
Replaced PASSWORD_INVALID with LOGIN_INVALID in all resource files and code. Updated InvalidLoginException to use the new resource, ensuring error messages indicate either email or password may be invalid. Improved localization and clarity of login error handling across supported languages.
Removed explicit clientId parameters from product endpoints and use cases. Now, the authenticated user's ID is obtained via the ILoggedUser service for all product operations. Updated controller routes, use case interfaces, and implementations accordingly. This enhances security and maintainability by ensuring actions are always performed in the context of the logged-in user. Also simplified UpdateClientUseCase with null-coalescing exception handling.
Added three unit tests covering success, client not found, and email already exists scenarios for UpdateClientUseCase. Refactored the CreateUseCase helper to accept a clientExist parameter and improved repository setup logic. Included necessary using statements for test utilities and exception handling.
Added RabbitMQ support with configuration in appsettings, a new IMessagePublisher abstraction, and implementations for publishing (RabbitMqPublisher) and consuming (ClientCreatedConsumer) messages. RegisterClientUseCase now publishes to the clients.created queue after registration. Updated dependency injection and tests to support messaging. Added RabbitMQ.Client NuGet package and RabbitMqOptions for configuration binding. Enables event-driven communication for client creation.
#
Add EnableConsumer option to control RabbitMQ consumer

Introduced an EnableConsumer setting in RabbitMQ config (default true)
to allow enabling or disabling the ClientCreatedConsumer hosted
service via configuration. Updated RabbitMqOptions and conditional
service registration accordingly.
#
Add RabbitMQ fanout exchange and multi-queue consumers

Refactor messaging to use a fanout exchange with separate audit and welcome queues for client events. Update configuration and options to support ExchangeName, ClientCreatedQueueName, and ClientWelcomeQueueName. Modify ClientCreatedConsumer to bind to the exchange and consume from the audit queue. Add ClientWelcomeConsumer to process welcome messages. Update publisher to publish to the exchange. Register both consumers as hosted services. Enables multiple consumers to independently process client creation events.
#
Fix ChangePassword logic and add unit tests

Corrected password verification in ChangePasswordUseCase to validate the current password instead of the new one. Added RequestChangePasswordBuilder for test data creation. Introduced ChangePasswordUseCaseTest with cases for success, client not found, and invalid password scenarios.
#
Add integration tests for Get All Clients endpoint

Introduce integration testing setup for the ProductClientHub API, including a custom WebApplicationFactory with in-memory configuration and fake dependencies. Add integration tests for the GET /api/clients endpoint, covering both success and no-content scenarios. Update Program.cs to skip DB migration in testing, add a partial Program class for test referencing, and update the test project file to reference the API. Remove minor unrelated/conflicting code.
#
Implement GetById logic and add integration tests

Updated CustomWebApplicationFactory to return clients by ID from the in-memory store. Added GetByIdClientIntegrationTest to verify GET /api/clients/{id} returns 200 OK for existing clients and 404 Not Found for missing clients, using xUnit and Shouldly.
#
Add integration test for client deletion endpoint

Introduce DeleteClientIntegrationTest to verify client deletion via the API using an in-memory store and fake authentication. Update CustomWebApplicationFactory to support test isolation by removing hosted services and providing a FakeDeleteClientRepository. This enables reliable, database-independent integration testing for client deletion.
… pra o atual, estava disparando erro, o que nao faz sentido, se o e-mail é dele, pode permanecer asssim.
#
Refactor ILoggedUser to ILoggedClient and update tests

Renamed ILoggedUser/LoggedUser to ILoggedClient/loggedClient across the codebase, including namespaces, DI, and test utilities. Updated use cases and tests to use the new interface. Enhanced test builders for clients and products, added ProductsReadOnlyRepositoryBuild for product mocks, and introduced GetAllProductsUseCaseTest. Improved ClientReadOnlyRepositoryBuilder for flexible email existence checks.
@Foqsz Foqsz merged commit a3ea281 into master Apr 30, 2026
0 of 2 checks passed
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.

1 participant