Skip to content
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

Merged
merged 2 commits into from
May 7, 2024
Merged

feat: add domain events #47

merged 2 commits into from
May 7, 2024

Conversation

italopessoa
Copy link
Member

No description provided.

Copy link

coderabbitai bot commented May 7, 2024

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 1e29469 and b161bd1.

Walkthrough

The 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

Files Changes Summary
.../Controllers/CustomersController.cs, .../Controllers/OrdersController.cs, .../Controllers/ProductsController.cs Enhanced XML documentation, added cancellation tokens, and updated return types. Introduced new methods for creating entities.
.../DomainEventsHandler.cs, .../DomainExceptionFilter.cs, .../Program.cs, .../FIAP.TechChallenge.ByteMeBurger.Api.csproj Introduced new classes for domain event handling and exception filtering. Updated program setup and project configuration for XML documentation.
.../UseCases/Customers/..., .../UseCases/Orders/..., .../UseCases/Products/... Integrated domain events in use cases, enhancing the event-driven architecture. Modified methods to trigger specific domain events upon actions like create, update, and delete.
.../Domain/Events/... Added multiple new domain event classes to handle specific lifecycle events for customers, orders, and products, enriching the domain-driven design.

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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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 the payload 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 type T and its role in domain events.

src/FIAP.TechChallenge.ByteMeBurger.Domain/Events/ProductCreated.cs (1)

3-9: Consider enhancing the XML documentation for the payload 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 the payload 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 the payload 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 the payload 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 the payload parameter to explain what it represents and how it is used, especially clarifying the roles of oldProduct and newProduct.

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 in ICustomerService.

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

Commits Files that changed from the base of the PR and between 769cb6d and 1e29469.
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 of RestaurantFacade.

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 in CreateProductUseCase.

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 in UpdateProductUseCase.

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 the CreateAsync 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 in CustomersController are well done, including the use of cancellation tokens and appropriate logging.

src/FIAP.TechChallenge.ByteMeBurger.Api/DomainEventsHandler.cs (1)

5-71: The implementation of DomainEventsHandler, 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 in OrdersController, 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 in Program.cs, including the addition of DomainEventsHandler 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 in ProductsController, including the addition of cancellation tokens, detailed logging, and handling of invalid IDs, enhance the functionality and maintainability of the product management features.

Comment on lines +10 to +14
var deleted = await repository.DeleteAsync(productId);
if (deleted)
DomainEventTrigger.RaiseProductDeleted(new ProductDeleted(productId));

return deleted;
Copy link

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.

Comment on lines +19 to +30
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,
});
}
Copy link

@coderabbitai coderabbitai bot May 7, 2024

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.

Copy link
Member Author

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

Copy link

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.

Comment on lines +25 to +30
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;
Copy link

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
Copy link

@coderabbitai coderabbitai bot May 7, 2024

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?

Copy link
Member Author

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

Copy link

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!

@italopessoa italopessoa merged commit caf954e into main May 7, 2024
@italopessoa italopessoa deleted the add_domain_events branch May 7, 2024 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api documentation Improvements or additions to documentation
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

1 participant