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: delete product from database #33

Merged
merged 1 commit into from
May 2, 2024

Conversation

italopessoa
Copy link
Member

- #4
it still missing some validations to check whether the product exists or not
Copy link

coderabbitai bot commented May 2, 2024

Walkthrough

The recent updates primarily focus on enhancing the ProductRepositoryDapper by implementing the DeleteAsync method to support actual product deletion and modifying the ProductRepositoryDapperTest to handle product images more flexibly and to include tests for the new deletion functionality. These changes improve the robustness and functionality of the product management system.

Changes

File Path Change Summary
.../Repository/ProductRepositoryDapper.cs Updated DeleteAsync method to perform actual deletion asynchronously.
.../Repository/ProductRepositoryDapperTest.cs Modified image handling in Create_Success and added DeleteAsync_Success and DeleteAsync_Fail tests.

Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between e40825f and 0107f31.
Files selected for processing (2)
  • src/FIAP.TechChallenge.ByteMeBurger.Infrastructure/Repository/ProductRepositoryDapper.cs (1 hunks)
  • tests/FIAP.TechChallenge.ByteMeBurger.Infrastructure.Test/Repository/ProductRepositoryDapperTest.cs (2 hunks)
Additional Context Used
Path-based Instructions (2)
src/FIAP.TechChallenge.ByteMeBurger.Infrastructure/Repository/ProductRepositoryDapper.cs (1)

Pattern **/*.cs: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.

tests/FIAP.TechChallenge.ByteMeBurger.Infrastructure.Test/Repository/ProductRepositoryDapperTest.cs (1)

Pattern **/*.cs: Validate all files and structures against Domain Driven Design principles and Ports & Adapters architecture pattern.

Additional comments not posted (3)
tests/FIAP.TechChallenge.ByteMeBurger.Infrastructure.Test/Repository/ProductRepositoryDapperTest.cs (3)

Line range hint 30-51: Changes in the Create_Success method are correctly implemented.

The modifications to handle product images as a list and the updated SQL command reflect the changes in the main repository code. The assertions are appropriately checking the results, ensuring the method behaves as expected.


55-68: The DeleteAsync_Success method is well-implemented.

The test correctly sets up the expected behavior using a mock and verifies that the deletion operation returns true, indicating that the deletion was successful.


70-83: The DeleteAsync_Fail method correctly handles the failure scenario.

This test method appropriately sets up a scenario where no rows are affected by the deletion operation, and it correctly asserts that the result should be false, indicating the operation did not succeed as expected.


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: 1

Comment on lines +40 to +44
public async Task<bool> DeleteAsync(Guid productId)
{
throw new NotImplementedException();
var affectedRows = await _dbConnection.ExecuteAsync("delete from Products where Id = @Id;",
new { Id = productId });
return affectedRows == 1;
Copy link

@coderabbitai coderabbitai bot May 2, 2024

Choose a reason for hiding this comment

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

Implement error handling and logging for the DeleteAsync method.

While the method correctly executes the deletion and checks the number of affected rows, it currently lacks any form of error handling or logging. This could lead to situations where errors during the database operation are silently ignored, making debugging difficult. Consider wrapping the database operation in a try-catch block and logging the error before rethrowing or handling it appropriately.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey, thanks for the feedback, could you please Open a follow-up GitHub issue with details and the sample code?
Thanks

Copy link

Choose a reason for hiding this comment

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

@italopessoa, I've successfully created a follow-up GitHub issue to address the need for error handling and logging in the DeleteAsync method. You can review and adjust the details as necessary in the issue here. Thank you for facilitating this enhancement!

Analysis chain

Once the issue is created, I will provide the user with the issue number and URL for their reference.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Create a new GitHub issue with details and sample code for error handling in DeleteAsync method

gh issue create \
  --title "Implement error handling and logging in DeleteAsync method" \
  --body "In the `DeleteAsync` method of the `ProductRepositoryDapper` class, there is currently no error handling or logging implemented. This can lead to situations where errors during the database operation are silently ignored, making debugging difficult. It is crucial to wrap the database operation in a try-catch block and log the error before rethrowing or handling it appropriately.

### Suggested Enhancement
\`\`\`csharp
public async Task<bool> DeleteAsync(Guid productId)
{
    try
    {
        var affectedRows = await _dbConnection.ExecuteAsync(\"delete from Products where Id = @Id;\", new { Id = productId });
        return affectedRows == 1;
    }
    catch (Exception ex)
    {
        // Log the exception details here
        throw; // Rethrow the exception or handle it as needed
    }
}
\`\`\`

### Context
This issue is linked to PR #33 and the discussion can be found [here](https://github.com/soat-fiap/FIAP.TechChallenge.ByteMeBurger/pull/33#discussion_r1587674739).

@italopessoa, please review the details and adjust as necessary." \
  --repo soat-fiap/FIAP.TechChallenge.ByteMeBurger

Length of output: 1432

@italopessoa italopessoa merged commit a4b7feb into main May 2, 2024
1 check passed
@italopessoa italopessoa deleted the 4-add-new-endpoint-to-delete-a-product branch May 2, 2024 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api enhancement New feature or request Phase 1 Containers in Software Architecture
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add new endpoint to delete a product
1 participant