Skip to content

Shipping update service#103

Merged
gitnasr merged 3 commits intodevfrom
ShippingUpdateService
Jun 28, 2025
Merged

Shipping update service#103
gitnasr merged 3 commits intodevfrom
ShippingUpdateService

Conversation

@mariamalaa98
Copy link
Copy Markdown
Contributor

@mariamalaa98 mariamalaa98 commented Jun 27, 2025

Description by Korbit AI

What change is being made?

Introduce a new ShippingService to update shipment status and notify involved parties, add IShippingService interface, and create ShippingController for handling shipment updates via API.

Why are these changes being made?

The new service and controller are implemented to streamline the process of updating shipment statuses and ensure both sellers and buyers are promptly notified via email regarding status changes. This addresses the need for efficient communication in the shipping workflow.

Is this description stale? Ask me to generate a new description by commenting /korbit-generate-pr-description

Summary by CodeRabbit

  • New Features
    • Introduced a new API endpoint to update the shipment status of individual order items.
    • Email notifications are now sent to both sellers and buyers when an order item's shipment status is updated.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jun 27, 2025

Walkthrough

A new shipping management feature has been introduced. This includes an IShippingService interface, its implementation in ShippingService, and a new ShippingController API endpoint. The system allows updating the shipment status of an order item, persists shipment activity, and sends email notifications to both buyer and seller upon status change.

Changes

File(s) Change Summary
Dentizone.Application/Interfaces/Order/IShippingService.cs Added IShippingService interface with UpdateItemShipmentStatusAsync method.
Dentizone.Application/Services/ShippingService.cs Added ShippingService class implementing IShippingService, with logic for updating shipment status and sending notifications.
Dentizone.Presentaion/Controllers/ShippingController.cs Added ShippingController with a PUT endpoint to update shipment status via IShippingService.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ShippingController
    participant ShippingService
    participant OrderItemRepository
    participant ShipmentActivityRepository
    participant AuthService
    participant MailService

    Client->>ShippingController: PUT /api/shipping/UpdateItemShipmentStatus(orderItemId, newStatus, comment)
    ShippingController->>ShippingService: UpdateItemShipmentStatusAsync(orderItemId, newStatus, comment)
    ShippingService->>OrderItemRepository: GetOrderItemWithShipmentActivities(orderItemId)
    OrderItemRepository-->>ShippingService: OrderItem (or NotFound)
    alt OrderItem found
        ShippingService->>ShipmentActivityRepository: AddAsync(new ShipmentActivity)
        ShipmentActivityRepository-->>ShippingService: persisted ShipmentActivity
        ShippingService->>AuthService: GetUserById(sellerId)
        ShippingService->>AuthService: GetUserById(buyerId)
        AuthService-->>ShippingService: SellerUser
        AuthService-->>ShippingService: BuyerUser
        ShippingService->>MailService: SendEmail(seller, status update)
        ShippingService->>MailService: SendEmail(buyer, status update)
    else OrderItem not found
        ShippingService-->>ShippingController: throws NotFoundException
    end
    ShippingService-->>ShippingController: (void)
    ShippingController-->>Client: 200 OK
Loading

Poem

🐇
A parcel hops from here to there,
Its status changed with utmost care.
Emails sent, both far and near,
To seller, buyer—news is clear!
Controllers, services, all in sync,
Shipping updates in a blink.
The rabbit cheers, “No missing link!”

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

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

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Status
Readability Poorly Formatted Email Message ▹ view
Functionality Missing await operator for async operation ▹ view ✅ Fix detected
Functionality Async Method Returns Void ▹ view ✅ Fix detected
Design Mixed notification and status update responsibilities ▹ view
Functionality Missing response payload for status update ▹ view
Error Handling Non-Specific Exception Type ▹ view ✅ Fix detected
Documentation Redundant Comment ▹ view
Performance Unnecessary Eager Loading ▹ view
Error Handling Unsafe Async Void Method ▹ view ✅ Fix detected
Files scanned
File Path Reviewed
Dentizone.Application/Interfaces/Order/IShippingService.cs
Dentizone.Presentaion/Controllers/ShippingController.cs
Dentizone.Application/Services/ShippingService.cs

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

Copy link
Copy Markdown
Contributor

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

🧹 Nitpick comments (3)
Dentizone.Application/Interfaces/Order/IShippingService.cs (1)

1-5: Remove unused using statements.

These using statements are not utilized in the interface definition.

-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Threading.Tasks;
Dentizone.Presentaion/Controllers/ShippingController.cs (1)

3-3: Remove unused using statement.

The repository namespace is not used in this controller.

-using Dentizone.Domain.Interfaces.Repositories;
Dentizone.Application/Services/ShippingService.cs (1)

1-6: Remove unused using statements.

Several using statements are not utilized in this file.

-using System;
-using System.Collections.Generic;
-using System.Linq;
using System.Linq.Expressions;
-using System.Text;
using System.Threading.Tasks;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7c770c6 and 5846e05.

📒 Files selected for processing (3)
  • Dentizone.Application/Interfaces/Order/IShippingService.cs (1 hunks)
  • Dentizone.Application/Services/ShippingService.cs (1 hunks)
  • Dentizone.Presentaion/Controllers/ShippingController.cs (1 hunks)
🔇 Additional comments (1)
Dentizone.Application/Services/ShippingService.cs (1)

37-39: ```shell
#!/bin/bash

Check if EF Core lazy loading proxies are enabled in the DbContext setup or registration

Search for UseLazyLoadingProxies in the infrastructure code

rg -R "UseLazyLoadingProxies" --type cs

Search for AddDbContext to see how the context is configured

rg -R "AddDbContext" --type cs


</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

[ApiController]
public class ShippingController(IShippingService shipmentActivity) : ControllerBase
{
[HttpPut]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add route template to the HttpPut attribute.

The PUT endpoint should have a route template to properly define the API path.

-        [HttpPut]
+        [HttpPut("update-status")]
🤖 Prompt for AI Agents
In Dentizone.Presentaion/Controllers/ShippingController.cs at line 13, the
HttpPut attribute lacks a route template, which is necessary to define the API
endpoint path. Add a route template string inside the HttpPut attribute, for
example [HttpPut("your-route")], to specify the URL path this PUT method will
handle.

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Dentizone.Presentaion.Controllers
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix typo in namespace.

The namespace contains a typo: "Presentaion" should be "Presentation".

-namespace Dentizone.Presentaion.Controllers
+namespace Dentizone.Presentation.Controllers
📝 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
namespace Dentizone.Presentaion.Controllers
namespace Dentizone.Presentation.Controllers
🤖 Prompt for AI Agents
In Dentizone.Presentaion/Controllers/ShippingController.cs at line 7, correct
the typo in the namespace declaration by changing
"Dentizone.Presentaion.Controllers" to "Dentizone.Presentation.Controllers" to
fix the spelling error.

- Modified `IShippingService` to add optional `comments` parameter in `UpdateItemShipmentStatusAsync`, changing return type to `Task`.
- Updated `ShippingService` to remove `IOrderRepository` and handle the new `comments` parameter, constructing `ShipmentActivity` with it.
- Adjusted `ShippingController` to await the updated service method and pass the new `comment` parameter.
- Added necessary using directives in `IShippingService.cs` and `ShippingService.cs`.
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

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

♻️ Duplicate comments (4)
Dentizone.Presentaion/Controllers/ShippingController.cs (2)

7-7: Fix typo in namespace.

The namespace contains a typo: "Presentaion" should be "Presentation".

-namespace Dentizone.Presentaion.Controllers
+namespace Dentizone.Presentation.Controllers

13-13: Add route template to HttpPut attribute.

The PUT endpoint should have a route template to properly define the API path.

-        [HttpPut]
+        [HttpPut("update-status")]
Dentizone.Application/Services/ShippingService.cs (2)

50-59: Add null checks for navigation properties.

Accessing item.Post.SellerId and item.Order.BuyerId without null checks can cause NullReferenceException.

+                if (item.Post?.SellerId == null || item.Order?.BuyerId == null)
+                {
+                    throw new InvalidOperationException($"Order item '{orderItemId}' is missing required seller or buyer information");
+                }
+
                 var seller = await authService.GetById(item.Post.SellerId);


                 await mailService.Send(seller.Email, $"the Status has been changed to {newStatus}",
                     "New status update");

                 var buyer = await authService.GetById(item.Order.BuyerId);

                 await mailService.Send(buyer.Email, $"the Status has been changed to {newStatus}",
                     "New status update");

20-23: Use interface type for AuthService dependency.

For better testability and adherence to SOLID principles, inject AuthService as an interface.

     internal class ShippingService(
         IOrderItemRepository orderItemRepository,
         IShipmentActivityRepository shipmentActivityRepository,
         IMailService mailService,
-        AuthService authService)
+        IAuthService authService)
         : IShippingService
🧹 Nitpick comments (4)
Dentizone.Presentaion/Controllers/ShippingController.cs (1)

3-3: Remove unused import.

The Dentizone.Domain.Interfaces.Repositories import is not used in this controller.

-using Dentizone.Domain.Interfaces.Repositories;
Dentizone.Application/Services/ShippingService.cs (3)

31-33: Remove unnecessary eager loading.

The ShipmentActivities are included in the query but never used in the method.

             var item = await orderItemRepository.FindBy(
-                oi => oi.Id == orderItemId,
-                [oi => oi.ShipmentActivities]);
+                oi => oi.Id == orderItemId);

53-59: Improve email message formatting and consider error handling.

The email messages have inconsistent capitalization and could be more professional.

-                await mailService.Send(seller.Email, $"the Status has been changed to {newStatus}",
-                    "New status update");
+                await mailService.Send(seller.Email, 
+                    $"The shipment status for order item {orderItemId} has been updated to {newStatus}",
+                    "Shipment Status Update");

                 var buyer = await authService.GetById(item.Order.BuyerId);

-                await mailService.Send(buyer.Email, $"the Status has been changed to {newStatus}",
-                    "New status update");
+                await mailService.Send(buyer.Email, 
+                    $"The shipment status for your order has been updated to {newStatus}",
+                    "Shipment Status Update");

26-61: Consider transaction handling for data consistency.

If email sending fails after creating the shipment activity, the system will be in an inconsistent state. Consider implementing transactional behavior or compensating actions.

Consider wrapping the database operation and email notifications in a transaction scope, or implement a saga pattern where email failures can be retried or logged without affecting the shipment status update.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5846e05 and 010e270.

📒 Files selected for processing (3)
  • Dentizone.Application/Interfaces/Order/IShippingService.cs (1 hunks)
  • Dentizone.Application/Services/ShippingService.cs (1 hunks)
  • Dentizone.Presentaion/Controllers/ShippingController.cs (1 hunks)
🔇 Additional comments (1)
Dentizone.Application/Interfaces/Order/IShippingService.cs (1)

10-14: Interface design looks good!

The async method properly returns Task and has well-defined parameters. The optional comments parameter provides good flexibility for tracking shipment updates.

Comment on lines +14 to +19
public async Task<IActionResult> UpdateItemShipmentStatus(string orderItemId, ShipmentActivityStatus newStatus,
string? comment)
{
await shipmentActivity.UpdateItemShipmentStatusAsync(orderItemId, newStatus, comment);
return Ok();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling and return response data.

The endpoint should handle potential exceptions and return meaningful response data to the client.

         public async Task<IActionResult> UpdateItemShipmentStatus(string orderItemId, ShipmentActivityStatus newStatus,
             string? comment)
         {
-            await shipmentActivity.UpdateItemShipmentStatusAsync(orderItemId, newStatus, comment);
-            return Ok();
+            try
+            {
+                await shipmentActivity.UpdateItemShipmentStatusAsync(orderItemId, newStatus, comment);
+                return Ok(new { orderItemId, status = newStatus, message = "Shipment status updated successfully" });
+            }
+            catch (NotFoundException ex)
+            {
+                return NotFound(new { error = ex.Message });
+            }
+            catch (Exception ex)
+            {
+                // Log the exception
+                return StatusCode(500, new { error = "An error occurred while updating shipment status" });
+            }
         }
📝 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
public async Task<IActionResult> UpdateItemShipmentStatus(string orderItemId, ShipmentActivityStatus newStatus,
string? comment)
{
await shipmentActivity.UpdateItemShipmentStatusAsync(orderItemId, newStatus, comment);
return Ok();
}
public async Task<IActionResult> UpdateItemShipmentStatus(string orderItemId, ShipmentActivityStatus newStatus,
string? comment)
{
try
{
await shipmentActivity.UpdateItemShipmentStatusAsync(orderItemId, newStatus, comment);
return Ok(new { orderItemId, status = newStatus, message = "Shipment status updated successfully" });
}
catch (NotFoundException ex)
{
return NotFound(new { error = ex.Message });
}
catch (Exception ex)
{
// Log the exception
return StatusCode(500, new { error = "An error occurred while updating shipment status" });
}
}
🤖 Prompt for AI Agents
In Dentizone.Presentaion/Controllers/ShippingController.cs around lines 14 to
19, the UpdateItemShipmentStatus method lacks error handling and does not return
any response data. Wrap the call to
shipmentActivity.UpdateItemShipmentStatusAsync in a try-catch block to handle
potential exceptions. On success, return a meaningful success response, and on
failure, catch exceptions and return an appropriate error response with relevant
details to the client.

Comment on lines +35 to +40
if (item == null)
{
throw new NotFoundException("Not Found");
}
else
{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve exception message and remove unnecessary else block.

Use a more descriptive exception message and remove the redundant else block after throw.

             if (item == null)
             {
-                throw new NotFoundException("Not Found");
+                throw new NotFoundException($"Order item with ID '{orderItemId}' was not found");
             }
-            else
-            {

Also remove the corresponding closing brace at line 61:

-            }
📝 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 (item == null)
{
throw new NotFoundException("Not Found");
}
else
{
if (item == null)
{
throw new NotFoundException($"Order item with ID '{orderItemId}' was not found");
}
🤖 Prompt for AI Agents
In Dentizone.Application/Services/ShippingService.cs between lines 35 and 40,
replace the generic "Not Found" message in the NotFoundException with a more
descriptive message indicating what was not found. Remove the else block
following the throw statement since it is redundant, and also remove the
corresponding closing brace at line 61 to maintain proper code structure.

@gitnasr gitnasr self-requested a review June 28, 2025 10:32
@gitnasr gitnasr merged commit 2fea245 into dev Jun 28, 2025
2 of 3 checks passed
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.

2 participants