Add delivery task listing endpoint

This commit is contained in:
2026-09-29 11:43:10 +05:30
parent ee50f0932d
commit 681cf821a6
5 changed files with 45 additions and 1 deletions
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc; using Distribution.Models;
using Microsoft.AspNetCore.Mvc;
namespace Distribution.Features.DeliveryRide; namespace Distribution.Features.DeliveryRide;
@@ -26,6 +27,16 @@ public class DeliveryTaskController(DeliveryTaskService service) : ControllerBas
return Ok(result); return Ok(result);
} }
[HttpGet("delivery-tasks")]
public async Task<IActionResult> 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}")] [HttpGet("delivery-tasks/{id:guid}")]
public async Task<IActionResult> GetById(Guid id) public async Task<IActionResult> GetById(Guid id)
{ {
@@ -26,6 +26,27 @@ public class DeliveryTaskRepository(AppDBContext context) : IDeliveryTaskReposit
.OrderBy(t => t.Sequence) .OrderBy(t => t.Sequence)
.ToListAsync(); .ToListAsync();
public Task<List<DeliveryTask>> 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<int> 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<bool> ExistsForOrderAndRideAsync(Guid shopPOId, Guid rideId) => public async Task<bool> ExistsForOrderAndRideAsync(Guid shopPOId, Guid rideId) =>
await context.DeliveryTasks await context.DeliveryTasks
.AnyAsync(t => t.FK_ShopPOId == shopPOId && t.FK_RideId == rideId); .AnyAsync(t => t.FK_ShopPOId == shopPOId && t.FK_RideId == rideId);
@@ -87,6 +87,13 @@ public class DeliveryTaskService(
return tasks.Select(ToResponse).ToList(); return tasks.Select(ToResponse).ToList();
} }
public async Task<PagedResponse<DeliveryTaskResponse>> GetAllAsync(DeliveryTaskStatus? status, int page, int pageSize)
{
var items = await repo.GetAllAsync(status, page, pageSize);
var total = await repo.GetCountAsync(status);
return new PagedResponse<DeliveryTaskResponse>(page, pageSize, total, items.Select(ToResponse).ToList());
}
public async Task<DeliveryTaskResponse?> GetByIdAsync(Guid id) public async Task<DeliveryTaskResponse?> GetByIdAsync(Guid id)
{ {
var task = await repo.GetByIdAsync(id); var task = await repo.GetByIdAsync(id);
@@ -6,6 +6,8 @@ public interface IDeliveryTaskRepository
{ {
Task<DeliveryTask?> GetByIdAsync(Guid id); Task<DeliveryTask?> GetByIdAsync(Guid id);
Task<List<DeliveryTask>> GetByRideIdAsync(Guid rideId); Task<List<DeliveryTask>> GetByRideIdAsync(Guid rideId);
Task<List<DeliveryTask>> GetAllAsync(DeliveryTaskStatus? status, int page, int pageSize);
Task<int> GetCountAsync(DeliveryTaskStatus? status);
Task<bool> ExistsForOrderAndRideAsync(Guid orderId, Guid rideId); Task<bool> ExistsForOrderAndRideAsync(Guid orderId, Guid rideId);
Task AddAsync(DeliveryTask task); Task AddAsync(DeliveryTask task);
void Update(DeliveryTask task); void Update(DeliveryTask task);
+3
View File
@@ -26,6 +26,9 @@ namespace Distribution.Models
public decimal? SalePrice { get; set; } public decimal? SalePrice { get; set; }
/// <summary>Warehouse quantity threshold below which the item shows up in low-stock alerts; null disables alerting for this item.</summary>
public decimal? ReorderLevel { get; set; }
/// <summary>Cost/purchase price, used to value free-goods scheme redemptions for getSchemeROI.</summary> /// <summary>Cost/purchase price, used to value free-goods scheme redemptions for getSchemeROI.</summary>
public decimal? CostPrice { get; set; } public decimal? CostPrice { get; set; }