From 681cf821a6542fcf996d7d3d67cc8829a52b9702 Mon Sep 17 00:00:00 2001 From: DeepnaPooja Date: Tue, 29 Sep 2026 11:43:10 +0530 Subject: [PATCH] Add delivery task listing endpoint --- .../DeliveryRide/DeliveryTaskController.cs | 13 +++++++++++- .../DeliveryRide/DeliveryTaskRepository.cs | 21 +++++++++++++++++++ .../DeliveryRide/DeliveryTaskService.cs | 7 +++++++ .../DeliveryRide/IDeliveryTaskRepository.cs | 2 ++ Distribution/Models/Item.cs | 3 +++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/Distribution/Features/DeliveryRide/DeliveryTaskController.cs b/Distribution/Features/DeliveryRide/DeliveryTaskController.cs index 919155e..1690ba0 100644 --- a/Distribution/Features/DeliveryRide/DeliveryTaskController.cs +++ b/Distribution/Features/DeliveryRide/DeliveryTaskController.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Mvc; +using Distribution.Models; +using Microsoft.AspNetCore.Mvc; namespace Distribution.Features.DeliveryRide; @@ -26,6 +27,16 @@ public class DeliveryTaskController(DeliveryTaskService service) : ControllerBas return Ok(result); } + [HttpGet("delivery-tasks")] + public async Task GetAll( + [FromQuery] DeliveryTaskStatus? status, + [FromQuery] int page = 1, + [FromQuery] int pageSize = 20) + { + var result = await service.GetAllAsync(status, page, pageSize); + return Ok(result); + } + [HttpGet("delivery-tasks/{id:guid}")] public async Task GetById(Guid id) { diff --git a/Distribution/Features/DeliveryRide/DeliveryTaskRepository.cs b/Distribution/Features/DeliveryRide/DeliveryTaskRepository.cs index e096063..d119678 100644 --- a/Distribution/Features/DeliveryRide/DeliveryTaskRepository.cs +++ b/Distribution/Features/DeliveryRide/DeliveryTaskRepository.cs @@ -26,6 +26,27 @@ public class DeliveryTaskRepository(AppDBContext context) : IDeliveryTaskReposit .OrderBy(t => t.Sequence) .ToListAsync(); + public Task> GetAllAsync(DeliveryTaskStatus? status, int page, int pageSize) + { + var query = context.DeliveryTasks + .Include(t => t.ShopPO) + .ThenInclude(o => o.Store) + .Include(t => t.ShopPO) + .ThenInclude(o => o.Items.Where(i => i.IsActive)) + .ThenInclude(i => i.Item) + .AsQueryable(); + if (status.HasValue) query = query.Where(t => t.Status == status.Value); + return query.OrderByDescending(t => t.CreatedAt) + .Skip((page - 1) * pageSize).Take(pageSize).ToListAsync(); + } + + public Task GetCountAsync(DeliveryTaskStatus? status) + { + var query = context.DeliveryTasks.AsQueryable(); + if (status.HasValue) query = query.Where(t => t.Status == status.Value); + return query.CountAsync(); + } + public async Task ExistsForOrderAndRideAsync(Guid shopPOId, Guid rideId) => await context.DeliveryTasks .AnyAsync(t => t.FK_ShopPOId == shopPOId && t.FK_RideId == rideId); diff --git a/Distribution/Features/DeliveryRide/DeliveryTaskService.cs b/Distribution/Features/DeliveryRide/DeliveryTaskService.cs index 18596fa..ce645bd 100644 --- a/Distribution/Features/DeliveryRide/DeliveryTaskService.cs +++ b/Distribution/Features/DeliveryRide/DeliveryTaskService.cs @@ -87,6 +87,13 @@ public class DeliveryTaskService( return tasks.Select(ToResponse).ToList(); } + public async Task> GetAllAsync(DeliveryTaskStatus? status, int page, int pageSize) + { + var items = await repo.GetAllAsync(status, page, pageSize); + var total = await repo.GetCountAsync(status); + return new PagedResponse(page, pageSize, total, items.Select(ToResponse).ToList()); + } + public async Task GetByIdAsync(Guid id) { var task = await repo.GetByIdAsync(id); diff --git a/Distribution/Features/DeliveryRide/IDeliveryTaskRepository.cs b/Distribution/Features/DeliveryRide/IDeliveryTaskRepository.cs index e96be2b..519ccce 100644 --- a/Distribution/Features/DeliveryRide/IDeliveryTaskRepository.cs +++ b/Distribution/Features/DeliveryRide/IDeliveryTaskRepository.cs @@ -6,6 +6,8 @@ public interface IDeliveryTaskRepository { Task GetByIdAsync(Guid id); Task> GetByRideIdAsync(Guid rideId); + Task> GetAllAsync(DeliveryTaskStatus? status, int page, int pageSize); + Task GetCountAsync(DeliveryTaskStatus? status); Task ExistsForOrderAndRideAsync(Guid orderId, Guid rideId); Task AddAsync(DeliveryTask task); void Update(DeliveryTask task); diff --git a/Distribution/Models/Item.cs b/Distribution/Models/Item.cs index 5aeecd9..f38de1c 100644 --- a/Distribution/Models/Item.cs +++ b/Distribution/Models/Item.cs @@ -26,6 +26,9 @@ namespace Distribution.Models public decimal? SalePrice { get; set; } + /// Warehouse quantity threshold below which the item shows up in low-stock alerts; null disables alerting for this item. + public decimal? ReorderLevel { get; set; } + /// Cost/purchase price, used to value free-goods scheme redemptions for getSchemeROI. public decimal? CostPrice { get; set; }