-
Notifications
You must be signed in to change notification settings - Fork 1
Shipping update service #103
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Dentizone.Domain.Enums; | ||
|
|
||
| namespace Dentizone.Application.Interfaces.Order | ||
| { | ||
| public interface IShippingService | ||
| { | ||
| Task UpdateItemShipmentStatusAsync(string orderItemId, ShipmentActivityStatus newStatus, | ||
| string? comments); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,63 @@ | ||||||||||||||||||||||
| using System; | ||||||||||||||||||||||
| using System.Collections.Generic; | ||||||||||||||||||||||
| using System.Linq; | ||||||||||||||||||||||
| using System.Linq.Expressions; | ||||||||||||||||||||||
| using System.Text; | ||||||||||||||||||||||
| using System.Threading.Tasks; | ||||||||||||||||||||||
| using Dentizone.Application.Interfaces; | ||||||||||||||||||||||
| using Dentizone.Application.Interfaces.Order; | ||||||||||||||||||||||
| using Dentizone.Application.Services.Authentication; | ||||||||||||||||||||||
| using Dentizone.Domain.Entity; | ||||||||||||||||||||||
| using Dentizone.Domain.Enums; | ||||||||||||||||||||||
| using Dentizone.Domain.Exceptions; | ||||||||||||||||||||||
| using Dentizone.Domain.Interfaces.Mail; | ||||||||||||||||||||||
| using Dentizone.Domain.Interfaces.Repositories; | ||||||||||||||||||||||
| using Microsoft.Extensions.Hosting; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| namespace Dentizone.Application.Services | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| internal class ShippingService( | ||||||||||||||||||||||
| IOrderItemRepository orderItemRepository, | ||||||||||||||||||||||
| IShipmentActivityRepository shipmentActivityRepository, | ||||||||||||||||||||||
| IMailService mailService, | ||||||||||||||||||||||
| AuthService authService) | ||||||||||||||||||||||
| : IShippingService | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| public async Task UpdateItemShipmentStatusAsync(string orderItemId, ShipmentActivityStatus newStatus, | ||||||||||||||||||||||
| string? comments) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| //search in DataBase if orderItemId found or not? | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| var item = await orderItemRepository.FindBy( | ||||||||||||||||||||||
| oi => oi.Id == orderItemId, | ||||||||||||||||||||||
| [oi => oi.ShipmentActivities]); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (item == null) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| throw new NotFoundException("Not Found"); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
|
Comment on lines
+35
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| var shipmentActivity = new ShipmentActivity | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| ItemId = orderItemId, | ||||||||||||||||||||||
| Status = newStatus, | ||||||||||||||||||||||
| ActivityDescription = comments | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
| await shipmentActivityRepository.CreateAsync(shipmentActivity); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| 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"); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,21 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| using Dentizone.Application.Interfaces.Order; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| using Dentizone.Domain.Enums; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| using Dentizone.Domain.Interfaces.Repositories; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| using Microsoft.AspNetCore.Http; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| using Microsoft.AspNetCore.Mvc; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace Dentizone.Presentaion.Controllers | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix typo in namespace. The namespace contains a typo: "Presentaion" should be "Presentation". -namespace Dentizone.Presentaion.Controllers
+namespace Dentizone.Presentation.Controllers📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| [Route("api/[controller]")] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| [ApiController] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| public class ShippingController(IShippingService shipmentActivity) : ControllerBase | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| [HttpPut] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||||||||||||||||||||||||||||||||||||||||||||||
| public async Task<IActionResult> UpdateItemShipmentStatus(string orderItemId, ShipmentActivityStatus newStatus, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| string? comment) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| await shipmentActivity.UpdateItemShipmentStatusAsync(orderItemId, newStatus, comment); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return Ok(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
gitnasr marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+14
to
+19
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.