Skip to content

feat(productreview): add ProductReview microservice#1

Open
MuhammedEminClk wants to merge 17 commits into
senrecep:mainfrom
MuhammedEminClk:feat/product-review-service
Open

feat(productreview): add ProductReview microservice#1
MuhammedEminClk wants to merge 17 commits into
senrecep:mainfrom
MuhammedEminClk:feat/product-review-service

Conversation

@MuhammedEminClk

Copy link
Copy Markdown

Fork

Original repo: https://github.com/senrecep/Aspire

This PR implements the ProductReview microservice following the existing ProductService and CategoryService patterns exactly — Clean Architecture with CQRS separation, DDD aggregate roots, and the Result pattern throughout. The domain layer encapsulates all business logic: ownership checks (update/delete authorization) live inside the ProductReview entity itself, not in handlers, and value objects (ReviewRating, ReviewComment, ProductId, UserId) enforce invariants at construction time via factory methods returning Result<T>. The AlreadyReviewed business rule is enforced in the command handler before hitting the repository, keeping the aggregate free of query dependencies.

For the persistence layer, separate ApplicationWriteDbContext and ApplicationReadDbContext instances maintain the CQRS boundary — the read context runs with NoTracking and has audit/domain-event interceptors disabled. A unique composite index on (product_id, user_id) provides a database-level safety net for the duplicate review rule. Soft deletes are handled via a global query filter so deleted records are transparently excluded from all queries. The ProductReviewCreatedDomainEventHandler invalidates Redis cache tags and publishes a ProductReviewCreatedIntegrationEvent to RabbitMQ via MassTransit — keeping the integration concern out of the domain and inside the application layer where it belongs.

Trade-offs

  • userId on the DELETE endpoint is passed as a query parameter (?userId=...) rather than extracted from the JWT claims. In a real production system this would be extracted from the authenticated user context to prevent spoofing, but since Keycloak auth is already wired and the task focuses on architectural patterns, this approach keeps the implementation straightforward and consistent with how other endpoints receive user identity.
  • The read model uses raw Guid primitives instead of value objects, which is intentional — read models are flat projections for queries, not domain objects, so value object overhead is unnecessary there.

…d UserId

ProductReview.Create() was returning ProductReviewErrors.Rating.EmptyError
for both empty ProductId and UserId checks — wrong error type entirely.
Added dedicated EmptyProductIdError and EmptyUserIdError to ProductReviewErrors,
updated Create() to use them, and strengthened the corresponding unit tests
to assert on the specific error codes rather than just IsFailure.
Also added ProductReviewUpdatedDomainEvent assertion to Update_ByOwner_Succeeds test.
…eviews

Updated the `ProductReviewCreatedDomainEventHandler` to invalidate both "reviews" and "average-rating" cache tags. Modified the `GetProductReviewListQuery` to support pagination with `PageNumber` and `PageSize` parameters, and adjusted the corresponding query handler and repository methods to return paginated results. Updated the API endpoint to reflect these changes, ensuring a more efficient retrieval of product reviews.
…ement check

Updated the health check for RabbitMQ to use an HTTP-based approach due to compatibility issues with the RabbitMQ.Client version. This change ensures that the health check remains functional regardless of the RabbitMQ client version. Additionally, modified the ProductReviewDeleteEndpoint to correctly bind the userId from the query parameters and updated the Keycloak realm in the dependency injection configuration.
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