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

Dev #16

Merged
merged 3 commits into from
Aug 22, 2024
Merged

Dev #16

merged 3 commits into from
Aug 22, 2024

Conversation

Ayobami6
Copy link
Owner

@Ayobami6 Ayobami6 commented Aug 22, 2024

Summary by CodeRabbit

  • New Features

    • Introduced functionality to cancel pending orders.
    • Added a new endpoint for users to cancel their orders via the app.
    • Enhanced user control over order management with improved cancellation mechanisms.
  • Bug Fixes

    • Improved error handling for order cancellation requests.
  • Documentation

    • Updated documentation to reflect new methods and message types related to order cancellation.

Copy link

coderabbitai bot commented Aug 22, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The updates introduce new message types and RPC methods in the orders.proto file, enabling order cancellation functionalities. Additional route handlers and gRPC methods have been implemented in the gateway and orders directories to handle order cancellations effectively. This enhances the overall order management capabilities within the system.

Changes

Files Change Summary
common/proto/orders/orders.proto Added CancelPendingOrderRequest, CancelPendingOrderResponse, and CancelPendingOrder RPC method.
gateway/orders_client_handler.go Implemented CancelOrder route handler to manage order cancellation via HTTP.
orders/grpc_server_handler.go Introduced CancelPendingOrder method for gRPC handling of pending order cancellations.
orders/repo.go Added CancelOrder(orderId uint) error method to the OrderRepo interface.
orders/repo_impl.go Implemented CancelOrder(orderId uint) error method in OrderRepoImpl for order cancellation logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant WebApp
    participant OrderClientHandler
    participant OrderService
    participant OrderRepo

    User->>WebApp: Request Order Cancellation
    WebApp->>OrderClientHandler: DELETE /orders/{id}/cancel
    OrderClientHandler->>OrderService: CancelPendingOrder(CancelPendingOrderRequest)
    OrderService->>OrderRepo: CancelOrder(orderId)
    OrderRepo-->>OrderService: Success/Error
    OrderService-->>OrderClientHandler: CancelPendingOrderResponse
    OrderClientHandler-->>User: Confirmation Message
Loading

🐰 In the fields where we hop and play,
New features come to brighten the day!
Orders can vanish with a flick of a paw,
Users rejoice, they’ll cheer and they'll awe!
Cancellations swift, like the breeze in the air,
Our code is now nimble, with features to spare! 🌼✨


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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

CodeRabbit Configuration 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.

@Ayobami6 Ayobami6 linked an issue Aug 22, 2024 that may be closed by this pull request
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

Outside diff range, codebase verification and nitpick comments (7)
common/proto/orders/orders.proto (1)

60-61: Consider adding fields to CancelPendingOrderRequest.

The CancelPendingOrderRequest message is currently empty. Consider adding fields if additional data is required for order cancellation.

gateway/users_client_handler.go (2)

120-133: Ensure comprehensive error handling in ResendOTP.

The ResendOTP function includes basic error handling. Consider adding more specific error messages or logging for better debugging.


136-150: Ensure comprehensive error handling in GetWalletBalance.

The GetWalletBalance function includes basic error handling. Consider adding more specific error messages or logging for better debugging.

users/grpc_server_handler.go (4)

243-244: Enhance error logging with more context.

Providing more context in error logs can help with debugging. Include relevant information like the email address or operation being performed.

Apply this diff to improve error logging:

        log.Println("Generate Code Failed for email:", email, "Error:", err)
        log.Println("Failed to marshal data for email:", email, "Error:", err)
        log.Println("Failed to publish a message for email:", email, "Error:", err)

Also applies to: 270-271, 281-282


294-295: Add error logging for user retrieval failure.

Logging errors when a user is not found can help with monitoring and debugging.

Apply this diff to add error logging:

    if err!= nil {
+        log.Printf("User not found for ID: %d, Error: %v", userId, err)
        return nil, errors.New("user not found")
    }

Line range hint 212-213: Improve error logging for OTP retrieval failure.

Adding more context to error logs can aid in debugging.

Apply this diff to improve error logging:

    if err!= nil {
+        log.Printf("Failed to get cached OTP for email: %s, Error: %v", email, err)
        return nil, errors.New("failed to get cached otp")
    }

Line range hint 226-228: Handle wallet credit errors more effectively.

Currently, the error is logged but not returned. Consider returning the error to the caller for better error handling.

Apply this diff to handle the error more effectively:

    if err!= nil {
        log.Println(err.Error())
+        return nil, errors.New("failed to credit user wallet")
    }
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9f97fb6 and 2185394.

Files ignored due to path filters (4)
  • common/proto/orders/orders.pb.go is excluded by !**/*.pb.go
  • common/proto/orders/orders_grpc.pb.go is excluded by !**/*.pb.go
  • common/proto/users/users.pb.go is excluded by !**/*.pb.go
  • common/proto/users/users_grpc.pb.go is excluded by !**/*.pb.go
Files selected for processing (4)
  • common/proto/orders/orders.proto (1 hunks)
  • common/proto/users/users.proto (2 hunks)
  • gateway/users_client_handler.go (2 hunks)
  • users/grpc_server_handler.go (1 hunks)
Additional comments not posted (8)
common/proto/orders/orders.proto (2)

62-64: Ensure CancelPendingOrderResponse message is sufficient.

The CancelPendingOrderResponse contains only a message field. Ensure this is sufficient for the response or consider adding more fields if needed.


73-73: RPC method CancelPendingOrder looks good.

The addition of the CancelPendingOrder RPC method enhances the service's functionality.

common/proto/users/users.proto (5)

74-76: Verify the necessity of OTPResendPayload fields.

The OTPResendPayload contains only an email field. Ensure this is sufficient for the OTP resend functionality.


78-80: Ensure OTPResendResponse message is sufficient.

The OTPResendResponse contains only a message field. Ensure this is sufficient for the response or consider adding more fields if needed.


82-84: Verify the necessity of WalletBalanceRequest fields.

The WalletBalanceRequest contains only a user_id field. Ensure this is sufficient for the wallet balance inquiry functionality.


86-89: Ensure WalletBalanceResponse message is sufficient.

The WalletBalanceResponse contains balance and message fields. Ensure this is sufficient for the response or consider adding more fields if needed.


99-100: RPC methods ResendOTP and GetWalletBalance look good.

The addition of the ResendOTP and GetWalletBalance RPC methods enhances the service's functionality.

gateway/users_client_handler.go (1)

30-31: New routes for OTP resending and wallet balance inquiries are well-placed.

The new routes for OTP resending and wallet balance inquiries are correctly registered in the router.

Comment on lines +257 to +258
log.Fatalf("Failed to declare queue: %v", err)
Copy link

Choose a reason for hiding this comment

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

Avoid using log.Fatalf in server code.

Using log.Fatalf will terminate the program if the queue declaration fails. Consider returning an error instead to allow the server to continue running.

Apply this diff to handle the error without terminating the program:

        if err!= nil {
-            log.Fatalf("Failed to declare queue: %v", err)
+            log.Printf("Failed to declare queue: %v", err)
+            return nil, errors.New("failed to declare queue")
        }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if err!= nil {
log.Fatalf("Failed to declare queue: %v", err)
if err!= nil {
log.Printf("Failed to declare queue: %v", err)
return nil, errors.New("failed to declare queue")

@Ayobami6 Ayobami6 merged commit dcfaee5 into main Aug 22, 2024
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.

Implement resend email notification
1 participant