diff --git a/Dentizone.Application/Interfaces/Order/IShippingService.cs b/Dentizone.Application/Interfaces/Order/IShippingService.cs new file mode 100644 index 0000000..6b1884d --- /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 +{ + public interface IShippingService + { + 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 new file mode 100644 index 0000000..22861cc --- /dev/null +++ b/Dentizone.Application/Services/ShippingService.cs @@ -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 + { + 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"); + } + } + } +} \ No newline at end of file diff --git a/Dentizone.Presentaion/Controllers/ShippingController.cs b/Dentizone.Presentaion/Controllers/ShippingController.cs new file mode 100644 index 0000000..db513ee --- /dev/null +++ b/Dentizone.Presentaion/Controllers/ShippingController.cs @@ -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 +{ + [Route("api/[controller]")] + [ApiController] + public class ShippingController(IShippingService shipmentActivity) : ControllerBase + { + [HttpPut] + public async Task UpdateItemShipmentStatus(string orderItemId, ShipmentActivityStatus newStatus, + string? comment) + { + await shipmentActivity.UpdateItemShipmentStatusAsync(orderItemId, newStatus, comment); + return Ok(); + } + } +} \ No newline at end of file