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 #6

Merged
merged 8 commits into from
Jul 24, 2024
Merged

Dev #6

merged 8 commits into from
Jul 24, 2024

Conversation

Ayobami6
Copy link
Owner

@Ayobami6 Ayobami6 commented Jul 24, 2024

Summary by CodeRabbit

  • New Features
    • Introduced new methods for updating delivery status and acknowledgment in the order management system.
    • Added functionality for updating a rider's successful rides.
    • Implemented wallet crediting for users.
    • Enhanced the notification system with MongoDB integration.
  • Bug Fixes
    • Improved the fallback handling of JWT secret key for enhanced security.
  • Chores
    • Added dependency on MongoDB driver for data persistence.
    • Integrated RabbitMQ for asynchronous email verification notifications.

Copy link

coderabbitai bot commented Jul 24, 2024

Walkthrough

Recent changes enhance various components of the application, introducing new features for authentication, notifications, and order management. Key updates include the ability to manage successful rides for riders, facilitate user wallet transactions, and integrate MongoDB for persistent storage. Additionally, establishing a RabbitMQ broker connection supports asynchronous message handling, enriching user interactions and overall system capabilities.

Changes

Files Change Summary
common/auth/jwt.go Updated JWT secret key handling to use a default value of "secret" when JWT_SECRET is not set, impacting JWT token security.
common/proto/riders/riders.proto Added UpdateRiderSuccessfulRidesRequest and UpdateRiderResponse messages; introduced UpdateRiderSuccessfulRides RPC method in RiderService.
common/proto/users/users.proto Introduced CreditUserWallet RPC method for the UserService, allowing user wallet crediting alongside existing charge methods.
gateway/orders_client_handler.go Added HandleUpdateDeliveryStatus and HandleUpdateAcknowledgement handlers for order status updates via PATCH requests.
notifications/go.mod Introduced a new dependency on the MongoDB driver (version 1.16.0).
notifications/main.go Enhanced notification system with MongoDB integration, updating EmailData struct, adding new structs for order status and email verification.
orders/grpc_server_handler.go Added UpdateDeliveryStatus and UpdateAcknowledgement methods to the orderGrpcHandler, improving order management.
riders/grpc_server_handler.go Introduced UpdateRiderSuccessfulRides method to the riderGrpcHandler for updating successful ride data.
riders/repo.go Added UpdateRiderSuccessfulRides(riderID uint) error method to the RiderRepo interface.
riders/repo_impl.go Implemented UpdateRiderSuccessfulRides method in RiderRepoImpl to update successful ride data.
users/grpc_server_handler.go Updated NewUsersGrpcHandler to accept a RabbitMQ channel; added CreditUserWallet method for wallet transactions.
users/main.go Modified startUserService to connect to a RabbitMQ broker and updated the handler initialization to include the channel.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant OrderClientHandler
    participant RiderRepo
    participant NotificationService

    Client->>OrderClientHandler: PATCH /updateDeliveryStatus
    OrderClientHandler->>RiderRepo: Update rider's wallet
    OrderClientHandler->>NotificationService: Send update notification
    NotificationService-->>OrderClientHandler: Acknowledgment sent
    OrderClientHandler-->>Client: Delivery status updated
Loading
sequenceDiagram
    participant UserService
    participant RabbitMQ
    participant UserRepo

    UserService->>UserRepo: Credit user wallet
    UserRepo-->>UserService: Wallet credited
    UserService->>RabbitMQ: Send email verification
    RabbitMQ-->>UserService: Acknowledgment received
Loading

Poem

🐇 In the meadow where the code does bloom,
New features spring from the developer's room.
Wallets filled, rides updated with glee,
MongoDB's whispers, as sweet as can be.
Hop along, dear friends, let's celebrate today,
With rabbits and code, we leap and play! 🌼✨


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.

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

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

71-71: Ensure implementation and testing of the new RPC method.

The CreditUserWallet RPC method has been implemented but lacks corresponding test cases. It is crucial to add tests to verify its functionality.

  • Implementation found in users/grpc_server_handler.go.
  • No test cases found for CreditUserWallet.
Analysis chain

Ensure implementation and testing of the new RPC method.

The addition of the CreditUserWallet(ChargeRequest) returns (ChargeResponse) method requires corresponding implementations and tests. Verify that the method is implemented and tested.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation and testing of the `CreditUserWallet` RPC method.

# Test: Search for the implementation and testing of the `CreditUserWallet` method. Expect: Occurrences of `CreditUserWallet` in implementation and test files.
rg --type go 'CreditUserWallet'

Length of output: 2008


Script:

#!/bin/bash
# Description: Verify the testing of the `CreditUserWallet` RPC method.

# Test: Search for test cases related to the `CreditUserWallet` method. Expect: Occurrences of `CreditUserWallet` in test files.
rg --type go 'CreditUserWallet' --glob '*_test.go'

Length of output: 199


Script:

#!/bin/bash
# Description: Debug why files are being skipped by ripgrep.

# Test: Run ripgrep with the --debug flag to understand why no files are being searched.
rg --type go 'CreditUserWallet' --glob '*_test.go' --debug

Length of output: 13089


Script:

#!/bin/bash
# Description: Verify the testing of the `CreditUserWallet` RPC method by bypassing ignore rules.

# Test: Search for test cases related to the `CreditUserWallet` method, ignoring .gitignore and other ignore patterns.
rg --type go 'CreditUserWallet' --glob '*_test.go' --no-ignore

Length of output: 211


Script:

#!/bin/bash
# Description: Verify the testing of the `CreditUserWallet` RPC method by searching all Go files.

# Test: Search for occurrences of the `CreditUserWallet` method in all Go files.
rg --type go 'CreditUserWallet' --no-ignore

Length of output: 2020

riders/repo_impl.go (1)

125-132: Improve error logging.

The error logging could be improved to provide more context about the failure.

-    log.Printf("Unable to get rider %d\n", riderId)
+    log.Printf("Unable to get rider with ID %d: %v\n", riderId, err)
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 865b83b and 9781209.

Files ignored due to path filters (6)
  • common/proto/riders/riders.pb.go is excluded by !**/*.pb.go
  • common/proto/riders/riders_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
  • go.work.sum is excluded by !**/*.sum
  • notifications/go.sum is excluded by !**/*.sum
Files selected for processing (12)
  • common/auth/jwt.go (2 hunks)
  • common/proto/riders/riders.proto (2 hunks)
  • common/proto/users/users.proto (1 hunks)
  • gateway/orders_client_handler.go (3 hunks)
  • notifications/go.mod (1 hunks)
  • notifications/main.go (2 hunks)
  • orders/grpc_server_handler.go (1 hunks)
  • riders/grpc_server_handler.go (1 hunks)
  • riders/repo.go (1 hunks)
  • riders/repo_impl.go (1 hunks)
  • users/grpc_server_handler.go (5 hunks)
  • users/main.go (3 hunks)
Additional context used
Learnings (1)
riders/grpc_server_handler.go (1)
Learnt from: Ayobami6
PR: Ayobami6/pickitup_v2#3
File: riders/grpc_server_handler.go:85-112
Timestamp: 2024-07-23T10:57:14.435Z
Learning: Enhance error messages in the `GetRiderByUserID` method of `riderGrpcHandler` by providing more context, such as the user ID that caused the error.
Additional comments not posted (19)
notifications/go.mod (1)

5-5: Ensure the necessity and correct usage of the new dependency.

The inclusion of go.mongodb.org/mongo-driver v1.16.0 // indirect indicates that MongoDB operations might be introduced. Verify that this dependency is necessary and correctly used in the codebase.

Verification successful

Dependency usage verified

The go.mongodb.org/mongo-driver dependency is necessary and correctly used in the notifications service for connecting to a MongoDB database and performing operations.

  • notifications/main.go: Usage of mongo.Client and options.Client().ApplyURI for MongoDB operations.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the MongoDB driver in the codebase.

# Test: Search for the usage of the MongoDB driver. Expect: Occurrences of `mongo-driver` usage.
rg --type go 'go.mongodb.org/mongo-driver'

Length of output: 168


Script:

#!/bin/bash
# Description: Extract and review the usage of MongoDB driver imports in notifications/main.go

# Display the lines where mongo and options are used in notifications/main.go
rg 'mongo' notifications/main.go -A 10

Length of output: 3703

riders/repo.go (1)

13-13: Ensure all implementations of RiderRepo interface are updated.

The addition of the UpdateRiderSuccessfulRides(riderID uint) error method requires all implementations of the RiderRepo interface to be updated. Verify that all implementations are updated accordingly.

Verification successful

Verification complete: All implementations of the RiderRepo interface are updated.

  • The RiderRepoImpl struct in riders/repo_impl.go contains the UpdateRiderSuccessfulRides method, confirming that the interface implementation is up-to-date.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all implementations of the `RiderRepo` interface are updated.

# Test: Search for the implementations of the `RiderRepo` interface. Expect: Occurrences of `UpdateRiderSuccessfulRides` method in all implementations.
rg --type go 'UpdateRiderSuccessfulRides'

Length of output: 3824


Script:

#!/bin/bash
# Description: Verify that all implementations of the `RiderRepo` interface are updated with the `UpdateRiderSuccessfulRides` method.

# Find all structs implementing the `RiderRepo` interface.
rg --type go 'type .* struct' -A 5 | rg 'RiderRepo'

# Check if these structs contain the `UpdateRiderSuccessfulRides` method.
rg --type go 'func (.*\*.*) UpdateRiderSuccessfulRides' -A 5

Length of output: 942

common/proto/riders/riders.proto (3)

82-84: LGTM!

The UpdateRiderSuccessfulRidesRequest message definition is correct.


85-85: LGTM!

The UpdateRiderResponse message serves as a placeholder for future response data.


95-95: LGTM!

The UpdateRiderSuccessfulRides RPC method definition is correct.

users/main.go (3)

8-8: LGTM!

The import statement for the broker package is correct.


66-68: LGTM!

The connection to the RabbitMQ broker is correctly initialized and closed using defer statements.


85-85: LGTM!

The NewUsersGrpcHandler function call is correctly updated to include the RabbitMQ channel.

users/grpc_server_handler.go (1)

28-29: LGTM! Constructor changes are correct.

The constructor has been updated to accept an additional parameter ch *amqp.Channel.

notifications/main.go (8)

19-26: LGTM! BSON Tags for MongoDB Integration

The BSON tags are correctly added to the EmailData struct for MongoDB integration.


30-35: LGTM! New Struct with BSON Tags

The OrderStatusData struct is correctly introduced with BSON tags for MongoDB integration.


40-43: LGTM! New Struct with BSON Tags

The EmailVerify struct is correctly introduced with BSON tags for MongoDB integration.


55-65: LGTM! MongoDB Connection Established

The MongoDB connection is correctly established and passed to the relevant functions for data persistence.


95-117: LGTM! MongoDB Insertion for EmailData

The MongoDB insertion for EmailData is correctly implemented with proper error handling.


147-167: LGTM! MongoDB Insertion for OrderStatusData

The MongoDB insertion for OrderStatusData is correctly implemented with proper error handling.


194-213: LGTM! MongoDB Insertion for EmailVerify

The MongoDB insertion for EmailVerify is correctly implemented with proper error handling.


216-227: LGTM! MongoDB Connection Function

The connectMongoDB function is correctly implemented to establish a connection to MongoDB with proper error handling.

gateway/orders_client_handler.go (2)

230-347: LGTM! Delivery Status Update Handler

The HandleUpdateDeliveryStatus function is correctly implemented with proper validation, authorization checks, and notification handling.


351-369: LGTM! Acknowledgement Status Update Handler

The HandleUpdateAcknowledgement function is correctly implemented with proper validation and acknowledgment status update.

riders/grpc_server_handler.go Outdated Show resolved Hide resolved
orders/grpc_server_handler.go Show resolved Hide resolved
orders/grpc_server_handler.go Show resolved Hide resolved
users/grpc_server_handler.go Show resolved Hide resolved
common/auth/jwt.go Show resolved Hide resolved
common/auth/jwt.go Show resolved Hide resolved
users/grpc_server_handler.go Show resolved Hide resolved
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: 5

Outside diff range, codebase verification and nitpick comments (1)
gateway/riders_client_handler.go (1)

Line range hint 43-43: Reminder: Handle specific error types.

The TODO comment indicates that some error types need to be handled.

Do you want me to help handle specific error types or open a GitHub issue to track this task?

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9781209 and 077ccba.

Files selected for processing (2)
  • gateway/riders_client_handler.go (2 hunks)
  • riders/grpc_server_handler.go (2 hunks)
Additional context used
Learnings (2)
gateway/riders_client_handler.go (1)
Learnt from: Ayobami6
PR: Ayobami6/pickitup_v2#3
File: riders/grpc_server_handler.go:85-112
Timestamp: 2024-07-23T10:57:14.435Z
Learning: Enhance error messages in the `GetRiderByUserID` method of `riderGrpcHandler` by providing more context, such as the user ID that caused the error.
riders/grpc_server_handler.go (1)
Learnt from: Ayobami6
PR: Ayobami6/pickitup_v2#3
File: riders/grpc_server_handler.go:85-112
Timestamp: 2024-07-23T10:57:14.435Z
Learning: Enhance error messages in the `GetRiderByUserID` method of `riderGrpcHandler` by providing more context, such as the user ID that caused the error.
Additional comments not posted (7)
gateway/riders_client_handler.go (3)

27-27: LGTM!

The new route for fetching multiple riders is correctly added.


Line range hint 70-70: LGTM!

The function correctly retrieves a rider by ID and constructs a self URL for the rider.


108-123: LGTM!

The function correctly retrieves multiple riders and constructs self URLs for each rider.

riders/grpc_server_handler.go (4)

Line range hint 27-27: LGTM!

The function correctly creates a new rider in the repository and returns a response message.


Line range hint 53-53: LGTM!

The function correctly retrieves a rider by ID and constructs a riderPb.Rider object.


Line range hint 87-87: LGTM!

The function correctly retrieves a rider by user ID and constructs a riderPb.Rider object.


Line range hint 17-17: LGTM!

The function correctly initializes a new gRPC handler for the rider service.

gateway/riders_client_handler.go Show resolved Hide resolved
gateway/riders_client_handler.go Show resolved Hide resolved
gateway/riders_client_handler.go Show resolved Hide resolved
riders/grpc_server_handler.go Show resolved Hide resolved
riders/grpc_server_handler.go Show resolved Hide resolved
@Ayobami6 Ayobami6 merged commit a30fe51 into main Jul 24, 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
1 participant