Refactor inventory commands and queries for improved clarity and consistency
Build and Deploy / build (push) Failing after 2m12s

- Updated ProductType enum values to be more descriptive (RegularProduct, DiscountProduct).
- Removed unnecessary Success and Message properties from response DTOs in AddStock and AdjustStock commands.
- Renamed Note property to Reason in AdjustStock and RecordLoss commands, and added ReferenceNumber.
- Changed InventoryItemId to Id in UpdateInventorySettingsCommand for consistency.
- Updated pagination properties in various queries (PageIndex to Page).
- Enhanced GetAllInventoryItemsQuery and GetLowStockItemsQuery to include sorting options.
- Updated InventoryProfile mappings to reflect changes in DTOs and Protobuf definitions.
- Adjusted Protobuf definitions to align with new property names and structures.
This commit is contained in:
masoodafar-web
2026-01-03 15:38:22 +03:30
parent 989f4a799a
commit f027fd0b06
18 changed files with 196 additions and 197 deletions
@@ -2,12 +2,13 @@ namespace BackOffice.BFF.Application.InventoryCQ.Queries.GetAllInventoryItems;
public record GetAllInventoryItemsQuery : IRequest<GetAllInventoryItemsResponseDto>
{
public int PageIndex { get; init; } = 1;
public int Page { get; init; } = 1;
public int PageSize { get; init; } = 20;
public long? WarehouseId { get; init; }
public int? ProductType { get; init; } // 1=Regular, 2=Discount
public bool? LowStockOnly { get; init; }
public string? SearchTerm { get; init; }
public int? ProductType { get; init; } // 1=RegularProduct, 2=DiscountProduct
public string? Search { get; init; }
public string? SortBy { get; init; }
public bool SortDesc { get; init; }
}
public class GetAllInventoryItemsResponseDto
@@ -23,7 +24,8 @@ public class InventoryItemDto
public long? ProductId { get; set; }
public long? DiscountProductId { get; set; }
public int ProductType { get; set; }
public string ProductName { get; set; } = string.Empty;
public string ProductTitle { get; set; } = string.Empty;
public long ProductPrice { get; set; }
public int Quantity { get; set; }
public int ReservedQuantity { get; set; }
public int AvailableQuantity { get; set; }
@@ -34,5 +36,6 @@ public class InventoryItemDto
public DateTime? LastSoldAt { get; set; }
public long WarehouseId { get; set; }
public string WarehouseName { get; set; } = string.Empty;
public bool IsLowStock => Quantity <= LowStockThreshold;
public bool IsLowStock { get; set; }
public DateTime? Created { get; set; }
}
@@ -16,7 +16,7 @@ public class GetAllInventoryItemsQueryHandler : IRequestHandler<GetAllInventoryI
{
var protoRequest = new GetAllInventoryItemsRequest
{
Page = request.PageIndex,
Page = request.Page,
PageSize = request.PageSize
};
@@ -26,8 +26,13 @@ public class GetAllInventoryItemsQueryHandler : IRequestHandler<GetAllInventoryI
if (request.ProductType.HasValue)
protoRequest.ProductType = (ProductType)request.ProductType.Value;
if (!string.IsNullOrWhiteSpace(request.SearchTerm))
protoRequest.Search = request.SearchTerm;
if (!string.IsNullOrWhiteSpace(request.Search))
protoRequest.Search = request.Search;
if (!string.IsNullOrWhiteSpace(request.SortBy))
protoRequest.SortBy = request.SortBy;
protoRequest.SortDesc = request.SortDesc;
var response = await _context.Inventory.GetAllInventoryItemsAsync(protoRequest, cancellationToken: cancellationToken);
@@ -38,7 +43,7 @@ public class GetAllInventoryItemsQueryHandler : IRequestHandler<GetAllInventoryI
{
TotalCount = response.TotalCount,
PageSize = request.PageSize,
CurrentPage = request.PageIndex,
CurrentPage = request.Page,
TotalPage = (int)Math.Ceiling((double)response.TotalCount / request.PageSize)
},
Items = response.Items.Select(i => new InventoryItemDto
@@ -47,7 +52,8 @@ public class GetAllInventoryItemsQueryHandler : IRequestHandler<GetAllInventoryI
ProductId = i.ProductId,
DiscountProductId = i.DiscountProductId,
ProductType = (int)i.ProductType,
ProductName = i.ProductTitle,
ProductTitle = i.ProductTitle,
ProductPrice = i.ProductPrice,
Quantity = i.Quantity,
ReservedQuantity = i.ReservedQuantity,
AvailableQuantity = i.AvailableQuantity,
@@ -57,7 +63,9 @@ public class GetAllInventoryItemsQueryHandler : IRequestHandler<GetAllInventoryI
LastRestockedAt = i.LastRestockedAt?.ToDateTime(),
LastSoldAt = i.LastSoldAt?.ToDateTime(),
WarehouseId = i.WarehouseId,
WarehouseName = i.WarehouseName
WarehouseName = i.WarehouseName,
IsLowStock = i.Quantity <= i.LowStockThreshold,
Created = i.Created?.ToDateTime()
}).ToList()
};
}
@@ -2,7 +2,7 @@ namespace BackOffice.BFF.Application.InventoryCQ.Queries.GetAllWarehouses;
public record GetAllWarehousesQuery : IRequest<GetAllWarehousesResponseDto>
{
public bool? ActiveOnly { get; init; }
public bool? IsActive { get; init; }
}
public class GetAllWarehousesResponseDto
@@ -19,4 +19,6 @@ public class WarehouseDto
public string? Address { get; set; }
public bool IsDefault { get; set; }
public bool IsActive { get; set; }
public DateTime? Created { get; set; }
public DateTime? LastModified { get; set; }
}
@@ -15,9 +15,9 @@ public class GetAllWarehousesQueryHandler : IRequestHandler<GetAllWarehousesQuer
{
var protoRequest = new CMSMicroservice.Protobuf.Protos.Inventory.GetAllWarehousesRequest();
if (request.ActiveOnly.HasValue)
if (request.IsActive.HasValue)
{
protoRequest.IsActive = request.ActiveOnly.Value;
protoRequest.IsActive = request.IsActive.Value;
}
var response = await _context.Inventory.GetAllWarehousesAsync(protoRequest, cancellationToken: cancellationToken);
@@ -32,7 +32,9 @@ public class GetAllWarehousesQueryHandler : IRequestHandler<GetAllWarehousesQuer
Code = w.Code,
Address = w.Address,
IsDefault = w.IsDefault,
IsActive = w.IsActive
IsActive = w.IsActive,
Created = w.Created?.ToDateTime(),
LastModified = w.LastModified?.ToDateTime()
}).ToList()
};
}
@@ -1,32 +1,17 @@
using BackOffice.BFF.Application.InventoryCQ.Queries.GetAllInventoryItems;
namespace BackOffice.BFF.Application.InventoryCQ.Queries.GetLowStockItems;
public record GetLowStockItemsQuery : IRequest<GetLowStockItemsResponseDto>
{
public int? Threshold { get; init; }
public long? WarehouseId { get; init; }
public int? ProductType { get; init; } // 1=Regular, 2=Discount
public int Count { get; init; } = 50;
public int? ProductType { get; init; } // 1=RegularProduct, 2=DiscountProduct
public int Page { get; init; } = 1;
public int PageSize { get; init; } = 20;
}
public class GetLowStockItemsResponseDto
{
public int TotalCount { get; set; }
public List<LowStockItemDto> Items { get; set; } = new();
}
public class LowStockItemDto
{
public long Id { get; set; }
public long? ProductId { get; set; }
public long? DiscountProductId { get; set; }
public int ProductType { get; set; }
public string ProductName { get; set; } = string.Empty;
public int Quantity { get; set; }
public int ReservedQuantity { get; set; }
public int AvailableQuantity { get; set; }
public int LowStockThreshold { get; set; }
public int ReorderPoint { get; set; }
public long WarehouseId { get; set; }
public string WarehouseName { get; set; } = string.Empty;
public int DeficitAmount => LowStockThreshold - Quantity; // چقدر کم داریم
public List<InventoryItemDto> Items { get; set; } = new();
}
@@ -1,3 +1,4 @@
using BackOffice.BFF.Application.InventoryCQ.Queries.GetAllInventoryItems;
using CMSMicroservice.Protobuf.Protos.Inventory;
namespace BackOffice.BFF.Application.InventoryCQ.Queries.GetLowStockItems;
@@ -15,8 +16,8 @@ public class GetLowStockItemsQueryHandler : IRequestHandler<GetLowStockItemsQuer
{
var protoRequest = new GetLowStockItemsRequest
{
Page = 1,
PageSize = request.Count
Page = request.Page,
PageSize = request.PageSize
};
if (request.WarehouseId.HasValue)
@@ -30,20 +31,23 @@ public class GetLowStockItemsQueryHandler : IRequestHandler<GetLowStockItemsQuer
return new GetLowStockItemsResponseDto
{
TotalCount = response.TotalCount,
Items = response.Items.Select(i => new LowStockItemDto
Items = response.Items.Select(i => new GetAllInventoryItems.InventoryItemDto
{
Id = i.Id,
ProductId = i.ProductId,
DiscountProductId = i.DiscountProductId,
ProductType = (int)i.ProductType,
ProductName = i.ProductTitle,
ProductTitle = i.ProductTitle,
ProductPrice = i.ProductPrice,
Quantity = i.Quantity,
ReservedQuantity = i.ReservedQuantity,
AvailableQuantity = i.AvailableQuantity,
LowStockThreshold = i.LowStockThreshold,
ReorderPoint = i.ReorderPoint,
MaxStockLevel = i.MaxStockLevel,
WarehouseId = i.WarehouseId,
WarehouseName = i.WarehouseName
WarehouseName = i.WarehouseName,
IsLowStock = true
}).ToList()
};
}
@@ -8,7 +8,7 @@ public record GetStockMovementsQuery : IRequest<GetStockMovementsResponseDto>
public int? MovementType { get; init; }
public DateTime? FromDate { get; init; }
public DateTime? ToDate { get; init; }
public int PageIndex { get; init; } = 1;
public int Page { get; init; } = 1;
public int PageSize { get; init; } = 20;
}
@@ -23,9 +23,7 @@ public class StockMovementDto
{
public long Id { get; set; }
public long InventoryItemId { get; set; }
public string ProductName { get; set; } = string.Empty;
public int MovementType { get; set; }
public string MovementTypeName { get; set; } = string.Empty;
public int Quantity { get; set; }
public int QuantityBefore { get; set; }
public int QuantityAfter { get; set; }
@@ -34,6 +32,6 @@ public class StockMovementDto
public string? ReferenceNumber { get; set; }
public string? Note { get; set; }
public long? PerformedByUserId { get; set; }
public string? PerformedByUserName { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime Created { get; set; }
public string ProductTitle { get; set; } = string.Empty;
}
@@ -16,7 +16,7 @@ public class GetStockMovementsQueryHandler : IRequestHandler<GetStockMovementsQu
{
var protoRequest = new GetStockMovementsRequest
{
Page = request.PageIndex,
Page = request.Page,
PageSize = request.PageSize
};
@@ -47,16 +47,14 @@ public class GetStockMovementsQueryHandler : IRequestHandler<GetStockMovementsQu
{
TotalCount = response.TotalCount,
PageSize = request.PageSize,
CurrentPage = request.PageIndex,
CurrentPage = request.Page,
TotalPage = (int)Math.Ceiling((double)response.TotalCount / request.PageSize)
},
Movements = response.Movements.Select(m => new StockMovementDto
{
Id = m.Id,
InventoryItemId = m.InventoryItemId,
ProductName = m.ProductTitle,
MovementType = (int)m.MovementType,
MovementTypeName = GetMovementTypeName(m.MovementType),
Quantity = m.Quantity,
QuantityBefore = m.QuantityBefore,
QuantityAfter = m.QuantityAfter,
@@ -65,8 +63,8 @@ public class GetStockMovementsQueryHandler : IRequestHandler<GetStockMovementsQu
ReferenceNumber = string.IsNullOrEmpty(m.ReferenceNumber) ? null : m.ReferenceNumber,
Note = string.IsNullOrEmpty(m.Note) ? null : m.Note,
PerformedByUserId = m.PerformedByUserId,
PerformedByUserName = null,
CreatedAt = m.Created?.ToDateTime() ?? DateTime.MinValue
Created = m.Created?.ToDateTime() ?? DateTime.MinValue,
ProductTitle = m.ProductTitle
}).ToList()
};
}