From 61587cbb2e3f686f2b59674025bf3f715ca23988 Mon Sep 17 00:00:00 2001 From: Mariam Alaa Date: Fri, 27 Jun 2025 00:27:46 +0300 Subject: [PATCH 1/3] astor yarab --- .../Interfaces/Order/IShippingService.cs | 15 ++++ .../Services/ShippingService.cs | 69 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 Dentizone.Application/Interfaces/Order/IShippingService.cs create mode 100644 Dentizone.Application/Services/ShippingService.cs diff --git a/Dentizone.Application/Interfaces/Order/IShippingService.cs b/Dentizone.Application/Interfaces/Order/IShippingService.cs new file mode 100644 index 0000000..59577bd --- /dev/null +++ b/Dentizone.Application/Interfaces/Order/IShippingService.cs @@ -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 +{ + internal interface IShippingService + { + + void UpdateItemShipmentStatusAsync(string orderItemId, ShipmentActivityStatus newStatus); + } +} diff --git a/Dentizone.Application/Services/ShippingService.cs b/Dentizone.Application/Services/ShippingService.cs new file mode 100644 index 0000000..a0566fa --- /dev/null +++ b/Dentizone.Application/Services/ShippingService.cs @@ -0,0 +1,69 @@ +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.Interfaces.Mail; +using Dentizone.Domain.Interfaces.Repositories; +using Microsoft.Extensions.Hosting; + +namespace Dentizone.Application.Services { + internal class ShippingService : IShippingService + { + private readonly IOrderItemRepository _orderItemRepository; + private readonly IOrderRepository _orderRepository; + private readonly IShipmentActivityRepository _shipmentActivityRepository; + private readonly IMailService _mailService; + private readonly AuthService _authService; + + public ShippingService(IOrderItemRepository orderItemRepository, IOrderRepository orderRepository, IShipmentActivityRepository shipmentActivityRepository, IMailService mailService, AuthService authService) + { + _mailService = mailService; + _orderItemRepository = orderItemRepository; + _orderRepository = orderRepository; + _shipmentActivityRepository = shipmentActivityRepository; + _authService = authService; + } + public async void UpdateItemShipmentStatusAsync(string orderItemId, ShipmentActivityStatus newStatus) + { + //search in DataBase if orderItemId found or not? + + OrderItem? item = await _orderItemRepository.FindBy( + oi => oi.Id == orderItemId, + new Expression>[] { oi => oi.ShipmentActivities }); + + if (item == null) { + throw new Exception("Not Found"); + } + else + { + ShipmentActivity shipmentActivity = new ShipmentActivity(); + shipmentActivity.Id = orderItemId; + shipmentActivity.Status = newStatus; + _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"); + + } + + + } + } +} From 5846e05bf0c819d6119b4bb6c14a4715e1313d04 Mon Sep 17 00:00:00 2001 From: Mariam Alaa Date: Fri, 27 Jun 2025 21:41:03 +0300 Subject: [PATCH 2/3] Shipping Controller --- .../Interfaces/Order/IShippingService.cs | 2 +- .../Controllers/ShippingController.cs | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 Dentizone.Presentaion/Controllers/ShippingController.cs diff --git a/Dentizone.Application/Interfaces/Order/IShippingService.cs b/Dentizone.Application/Interfaces/Order/IShippingService.cs index 59577bd..28bf037 100644 --- a/Dentizone.Application/Interfaces/Order/IShippingService.cs +++ b/Dentizone.Application/Interfaces/Order/IShippingService.cs @@ -7,7 +7,7 @@ namespace Dentizone.Application.Interfaces.Order { - internal interface IShippingService + public interface IShippingService { void UpdateItemShipmentStatusAsync(string orderItemId, ShipmentActivityStatus newStatus); diff --git a/Dentizone.Presentaion/Controllers/ShippingController.cs b/Dentizone.Presentaion/Controllers/ShippingController.cs new file mode 100644 index 0000000..a3b3723 --- /dev/null +++ b/Dentizone.Presentaion/Controllers/ShippingController.cs @@ -0,0 +1,24 @@ +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 +{ + [Route("api/[controller]")] + [ApiController] + public class ShippingController(IShippingService shipmentActivity) : ControllerBase + { + [HttpPut] + + public async Task UpdateItemShipmentStatus (string orderItemId, ShipmentActivityStatus newStatus) + { + shipmentActivity.UpdateItemShipmentStatusAsync(orderItemId, newStatus); + return Ok(); + + } + + + } +} From 010e27062d642e22440ebd28601188a3fcb64935 Mon Sep 17 00:00:00 2001 From: Mahmoud Nasr <239.nasr@gmail.com> Date: Sat, 28 Jun 2025 13:26:23 +0300 Subject: [PATCH 3/3] Enhance shipping status update with comments support - 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`. --- .../Interfaces/Order/IShippingService.cs | 8 +-- .../Services/ShippingService.cs | 72 +++++++++---------- .../Controllers/ShippingController.cs | 11 ++- 3 files changed, 41 insertions(+), 50 deletions(-) diff --git a/Dentizone.Application/Interfaces/Order/IShippingService.cs b/Dentizone.Application/Interfaces/Order/IShippingService.cs index 28bf037..6b1884d 100644 --- a/Dentizone.Application/Interfaces/Order/IShippingService.cs +++ b/Dentizone.Application/Interfaces/Order/IShippingService.cs @@ -7,9 +7,9 @@ namespace Dentizone.Application.Interfaces.Order { - public interface IShippingService + public interface IShippingService { - - void UpdateItemShipmentStatusAsync(string orderItemId, ShipmentActivityStatus newStatus); + Task UpdateItemShipmentStatusAsync(string orderItemId, ShipmentActivityStatus newStatus, + string? comments); } -} +} \ No newline at end of file diff --git a/Dentizone.Application/Services/ShippingService.cs b/Dentizone.Application/Services/ShippingService.cs index a0566fa..22861cc 100644 --- a/Dentizone.Application/Services/ShippingService.cs +++ b/Dentizone.Application/Services/ShippingService.cs @@ -9,61 +9,55 @@ 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 : IShippingService +namespace Dentizone.Application.Services +{ + internal class ShippingService( + IOrderItemRepository orderItemRepository, + IShipmentActivityRepository shipmentActivityRepository, + IMailService mailService, + AuthService authService) + : IShippingService { - private readonly IOrderItemRepository _orderItemRepository; - private readonly IOrderRepository _orderRepository; - private readonly IShipmentActivityRepository _shipmentActivityRepository; - private readonly IMailService _mailService; - private readonly AuthService _authService; - - public ShippingService(IOrderItemRepository orderItemRepository, IOrderRepository orderRepository, IShipmentActivityRepository shipmentActivityRepository, IMailService mailService, AuthService authService) - { - _mailService = mailService; - _orderItemRepository = orderItemRepository; - _orderRepository = orderRepository; - _shipmentActivityRepository = shipmentActivityRepository; - _authService = authService; - } - public async void UpdateItemShipmentStatusAsync(string orderItemId, ShipmentActivityStatus newStatus) + public async Task UpdateItemShipmentStatusAsync(string orderItemId, ShipmentActivityStatus newStatus, + string? comments) { //search in DataBase if orderItemId found or not? - - OrderItem? item = await _orderItemRepository.FindBy( - oi => oi.Id == orderItemId, - new Expression>[] { oi => oi.ShipmentActivities }); - if (item == null) { - throw new Exception("Not Found"); + var item = await orderItemRepository.FindBy( + oi => oi.Id == orderItemId, + [oi => oi.ShipmentActivities]); + + if (item == null) + { + throw new NotFoundException("Not Found"); } else { - ShipmentActivity shipmentActivity = new ShipmentActivity(); - shipmentActivity.Id = orderItemId; - shipmentActivity.Status = newStatus; - _shipmentActivityRepository.CreateAsync(shipmentActivity); - - - var seller = await _authService.GetById(item.Post.SellerId); - - + var shipmentActivity = new ShipmentActivity + { + ItemId = orderItemId, + Status = newStatus, + ActivityDescription = comments + }; + await shipmentActivityRepository.CreateAsync(shipmentActivity); - await _mailService.Send(seller.Email, $"the Status has been changed to {newStatus}", - "New status update"); - var buyer = await _authService.GetById(item.Order.BuyerId); + var seller = await authService.GetById(item.Post.SellerId); - await _mailService.Send(buyer.Email, $"the Status has been changed to {newStatus}", - "New status update"); - } + 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"); + } } } -} +} \ No newline at end of file diff --git a/Dentizone.Presentaion/Controllers/ShippingController.cs b/Dentizone.Presentaion/Controllers/ShippingController.cs index a3b3723..db513ee 100644 --- a/Dentizone.Presentaion/Controllers/ShippingController.cs +++ b/Dentizone.Presentaion/Controllers/ShippingController.cs @@ -11,14 +11,11 @@ namespace Dentizone.Presentaion.Controllers public class ShippingController(IShippingService shipmentActivity) : ControllerBase { [HttpPut] - - public async Task UpdateItemShipmentStatus (string orderItemId, ShipmentActivityStatus newStatus) + public async Task UpdateItemShipmentStatus(string orderItemId, ShipmentActivityStatus newStatus, + string? comment) { - shipmentActivity.UpdateItemShipmentStatusAsync(orderItemId, newStatus); + await shipmentActivity.UpdateItemShipmentStatusAsync(orderItemId, newStatus, comment); return Ok(); - } - - } -} +} \ No newline at end of file