-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add domain events #47
Conversation
Warning Rate Limit Exceeded@italopessoa has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 57 seconds before requesting another review. How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. WalkthroughThe recent changes across various components of the ByteMeBurger API focus on enhancing documentation, integrating domain events for better event handling, and refining method signatures. Significant additions include XML documentation for better clarity, the introduction of new domain events to manage lifecycle changes of products, orders, and customers, and updates to method parameters to include cancellation tokens for improved task management. Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
Out of diff range and nitpick comments (9)
src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/ProductDeleted.cs (1)
3-7
: Consider enhancing the XML documentation for thepayload
parameter to explain what it represents and how it is used.src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/DomainEvent.cs (1)
3-10
: Enhance the XML documentation to provide more details about the generic typeT
and its role in domain events.src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/ProductCreated.cs (1)
3-9
: Consider enhancing the XML documentation for thepayload
parameter to explain what it represents and how it is used.src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/OrderCreated.cs (1)
3-9
: Consider enhancing the XML documentation for thepayload
parameter to explain what it represents and how it is used.src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/OrderPaymentConfirmed.cs (1)
3-9
: Consider enhancing the XML documentation for thepayload
parameter to explain what it represents and how it is used.src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/CustomerRegistered.cs (1)
3-9
: Consider enhancing the XML documentation for thepayload
parameter to explain what it represents and how it is used.src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/ProductUpdated.cs (1)
3-10
: Consider enhancing the XML documentation for thepayload
parameter to explain what it represents and how it is used, especially clarifying the roles ofoldProduct
andnewProduct
.src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/OrderStatusChanged.cs (1)
9-9
: Ensure the constructor's XML documentation is complete.The constructor lacks XML documentation for its parameter. Consider adding a description for
payload
to improve code readability and maintainability.src/FIAP.TechChallenge.ByteMeBurger.Domain/Ports/Ingoing/ICustomerService.cs (1)
7-20
: Enhance XML documentation inICustomerService
.The XML documentation is good but could be enhanced by adding more details about the parameters and the expected behavior of the methods, especially in error scenarios.
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (32)
- src/FIAP.TechChallenge.ByteMeBurger.Api/Controllers/CustomersController.cs (2 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Api/Controllers/OrdersController.cs (3 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Api/Controllers/ProductsController.cs (4 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Api/DomainEventsHandler.cs (1 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Api/DomainExceptionFilter.cs (1 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Api/FIAP.TechChallenge.ByteMeBurger.Api.csproj (1 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Api/Program.cs (3 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Application/UseCases/Customers/CreateCustomerUseCase.cs (2 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Application/UseCases/Customers/FindCustomerByCpfUseCase.cs (1 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Application/UseCases/Orders/CheckoutOrderUseCase.cs (2 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Application/UseCases/Products/CreateProductUseCase.cs (2 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Application/UseCases/Products/DeleteProductUseCase.cs (2 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Application/UseCases/Products/UpdateProductUseCase.cs (2 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/CustomerRegistered.cs (1 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/DomainEvent.cs (1 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/DomainEventTrigger.cs (1 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/OrderCreated.cs (1 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/OrderPaymentConfirmed.cs (1 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/OrderStatusChanged.cs (1 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/ProductCreated.cs (1 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/ProductDeleted.cs (1 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/ProductUpdated.cs (1 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Domain/FIAP.TechChallenge.ByteMeBurger.Domain.csproj (1 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Domain/Ports/Ingoing/ICustomerService.cs (1 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Domain/Ports/Ingoing/IOrderService.cs (1 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Domain/Ports/Ingoing/IProductService.cs (1 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Domain/Ports/Outgoing/IBaseRepository.cs (1 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Domain/ValueObjects/Cpf.cs (1 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Domain/ValueObjects/OrderStatus.cs (1 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Domain/ValueObjects/ProductCategory.cs (1 hunks)
- src/FIAP.TechChallenge.ByteMeBurger.Facade/RestaurantFacade.cs (1 hunks)
- tests/FIAP.TechChallenge.ByteMeBurger.Application.Test/UseCases/Products/CreateProductUseCaseTest.cs (3 hunks)
Files skipped from review due to trivial changes (9)
- src/FIAP.TechChallenge.ByteMeBurger.Api/FIAP.TechChallenge.ByteMeBurger.Api.csproj
- src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/DomainEventTrigger.cs
- src/FIAP.TechChallenge.ByteMeBurger.Domain/FIAP.TechChallenge.ByteMeBurger.Domain.csproj
- src/FIAP.TechChallenge.ByteMeBurger.Domain/Ports/Ingoing/IOrderService.cs
- src/FIAP.TechChallenge.ByteMeBurger.Domain/Ports/Outgoing/IBaseRepository.cs
- src/FIAP.TechChallenge.ByteMeBurger.Domain/ValueObjects/Cpf.cs
- src/FIAP.TechChallenge.ByteMeBurger.Domain/ValueObjects/OrderStatus.cs
- src/FIAP.TechChallenge.ByteMeBurger.Domain/ValueObjects/ProductCategory.cs
- tests/FIAP.TechChallenge.ByteMeBurger.Application.Test/UseCases/Products/CreateProductUseCaseTest.cs
Additional Context Used
Path-based Instructions (23)
src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/ProductDeleted.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/DomainEvent.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/ProductCreated.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/OrderCreated.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/OrderPaymentConfirmed.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/CustomerRegistered.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/ProductUpdated.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.src/FIAP.TechChallenge.ByteMeBurger.Application/UseCases/Customers/FindCustomerByCpfUseCase.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/OrderStatusChanged.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.src/FIAP.TechChallenge.ByteMeBurger.Facade/RestaurantFacade.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.src/FIAP.TechChallenge.ByteMeBurger.Application/UseCases/Products/DeleteProductUseCase.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.src/FIAP.TechChallenge.ByteMeBurger.Domain/Ports/Ingoing/ICustomerService.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.src/FIAP.TechChallenge.ByteMeBurger.Application/UseCases/Products/CreateProductUseCase.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.src/FIAP.TechChallenge.ByteMeBurger.Api/DomainExceptionFilter.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.src/FIAP.TechChallenge.ByteMeBurger.Application/UseCases/Products/UpdateProductUseCase.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.src/FIAP.TechChallenge.ByteMeBurger.Application/UseCases/Customers/CreateCustomerUseCase.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.src/FIAP.TechChallenge.ByteMeBurger.Application/UseCases/Orders/CheckoutOrderUseCase.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.src/FIAP.TechChallenge.ByteMeBurger.Domain/Ports/Ingoing/IProductService.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.src/FIAP.TechChallenge.ByteMeBurger.Api/Controllers/CustomersController.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.src/FIAP.TechChallenge.ByteMeBurger.Api/DomainEventsHandler.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.src/FIAP.TechChallenge.ByteMeBurger.Api/Controllers/OrdersController.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.src/FIAP.TechChallenge.ByteMeBurger.Api/Program.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.src/FIAP.TechChallenge.ByteMeBurger.Api/Controllers/ProductsController.cs (1)
Pattern
**/*.cs
: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.
Additional comments not posted (12)
src/FIAP.TechChallenge.ByteMeBurger.Application/UseCases/Customers/FindCustomerByCpfUseCase.cs (1)
6-10
: Implementation aligns with clean architecture principles and uses async-await appropriately. Good job!src/FIAP.TechChallenge.ByteMeBurger.Facade/RestaurantFacade.cs (1)
6-7
: Clarify the future ofRestaurantFacade
.The class is marked as obsolete. It's important to verify if there are any plans for its replacement or if existing usages need to be refactored. This information should be documented or communicated to avoid confusion.
src/FIAP.TechChallenge.ByteMeBurger.Application/UseCases/Products/CreateProductUseCase.cs (1)
14-19
: Validate the product creation logic inCreateProductUseCase
.The method
Execute
creates a product and raises a domain event. It's crucial to verify that the product is correctly persisted before the event is raised to ensure data consistency.src/FIAP.TechChallenge.ByteMeBurger.Application/UseCases/Products/UpdateProductUseCase.cs (1)
20-26
: Confirm the update logic inUpdateProductUseCase
.The method
Execute
updates a product and raises a domain event if successful. It's important to verify that the update is correctly persisted and that the event accurately reflects the changes made to ensure data consistency.src/FIAP.TechChallenge.ByteMeBurger.Application/UseCases/Orders/CheckoutOrderUseCase.cs (1)
44-44
: Raising the domain event after order creation is a good practice.src/FIAP.TechChallenge.ByteMeBurger.Domain/Ports/Ingoing/IProductService.cs (2)
44-44
: TODO comment suggests a return type issue. Verify and correct the method's return type as needed.
8-16
: The XML documentation for theCreateAsync
method is clear and informative.src/FIAP.TechChallenge.ByteMeBurger.Api/Controllers/CustomersController.cs (1)
Line range hint
8-47
: The implementation and documentation of the new methods inCustomersController
are well done, including the use of cancellation tokens and appropriate logging.src/FIAP.TechChallenge.ByteMeBurger.Api/DomainEventsHandler.cs (1)
5-71
: The implementation ofDomainEventsHandler
, including event subscription and unsubscription, is correctly handled to ensure proper resource management.src/FIAP.TechChallenge.ByteMeBurger.Api/Controllers/OrdersController.cs (1)
Line range hint
9-62
: The changes inOrdersController
, including the addition of cancellation tokens and detailed logging, enhance the functionality and maintainability of the order management features.src/FIAP.TechChallenge.ByteMeBurger.Api/Program.cs (1)
Line range hint
28-90
: The service configurations inProgram.cs
, including the addition ofDomainEventsHandler
and the setup of health checks, are well-implemented and enhance the application's robustness and maintainability.src/FIAP.TechChallenge.ByteMeBurger.Api/Controllers/ProductsController.cs (1)
Line range hint
9-106
: The changes inProductsController
, including the addition of cancellation tokens, detailed logging, and handling of invalid IDs, enhance the functionality and maintainability of the product management features.
var deleted = await repository.DeleteAsync(productId); | ||
if (deleted) | ||
DomainEventTrigger.RaiseProductDeleted(new ProductDeleted(productId)); | ||
|
||
return deleted; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure proper error handling in DeleteProductUseCase
.
The method Execute
raises a domain event when a product is successfully deleted. However, there is no error handling or logging if the deletion fails. Consider adding error handling or logging to improve robustness.
public void OnException(ExceptionContext context) | ||
{ | ||
if (context.Exception is not DomainException) return; | ||
_logger.LogError(context.Exception, "An unhandled domain exception has occurred."); | ||
|
||
context.Result = new BadRequestObjectResult(new ProblemDetails | ||
{ | ||
Status = StatusCodes.Status404NotFound, | ||
Title = "The request could not be processed.", | ||
Detail = context.Exception.Message, | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refine the exception handling in DomainExceptionFilter
.
The method OnException
only handles DomainException
and logs it. Consider extending the handling to cover other potential exceptions that might not derive from DomainException
but are still relevant to the domain layer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that class is specialized on DomainException. it should not handle different errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@italopessoa, you're absolutely right. Keeping the DomainExceptionFilter
specialized to handle only DomainException
aligns well with the principles of clean architecture, specifically the Single Responsibility Principle. This approach ensures that the class remains focused and cohesive, enhancing maintainability and clarity in the domain layer's error handling strategy.
Thank you for your insight! If there's anything else you'd like to discuss or adjust, feel free to let me know.
var newCustomer = await customerRepository.CreateAsync(customer); | ||
if (newCustomer is null) | ||
throw new UseCaseException("An error occurred while trying to create the customer."); | ||
|
||
DomainEventTrigger.RaiseCustomerRegistered(new CustomerRegistered(customer)); | ||
return newCustomer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enhance error handling in CreateCustomerUseCase
.
The method Execute
creates a customer and raises a domain event. However, the error handling could be improved by adding more specific exceptions or error messages to better inform the user of the failure reasons.
Task<Product> CreateAsync(string name, string description, ProductCategory category, decimal price, | ||
IReadOnlyList<string> images); | ||
|
||
// TODO add new method | ||
// TODO add new method use issue https://github.com/soat-fiap/FIAP.TechChallenge.ByteMeBurger/issues/32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO comment indicates a missing method. Consider implementing it or removing the comment if not needed.
Would you like me to help implement this method or should I open a GitHub issue to track this task?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's already an open issue for that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@italopessoa, thanks for confirming that there's already an open issue for the TODO comment. If you need any further assistance or if there's anything else you'd like me to help with, please let me know!
No description provided.