Refactor inventory commands and queries for improved clarity and consistency
Build and Deploy / build (push) Failing after 2m12s
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:
@@ -3,7 +3,7 @@ namespace BackOffice.BFF.Application.InventoryCQ.Commands.AddStock;
|
||||
public record AddStockCommand : IRequest<AddStockResponseDto>
|
||||
{
|
||||
public long ProductId { get; init; }
|
||||
public int ProductType { get; init; } // 1=Regular, 2=Discount
|
||||
public int ProductType { get; init; } // 1=RegularProduct, 2=DiscountProduct
|
||||
public int Quantity { get; init; }
|
||||
public string? ReferenceNumber { get; init; }
|
||||
public string? Note { get; init; }
|
||||
@@ -12,8 +12,6 @@ public record AddStockCommand : IRequest<AddStockResponseDto>
|
||||
|
||||
public class AddStockResponseDto
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public long InventoryItemId { get; set; }
|
||||
public int NewQuantity { get; set; }
|
||||
public string? Message { get; set; }
|
||||
}
|
||||
|
||||
+1
-3
@@ -33,10 +33,8 @@ public class AddStockCommandHandler : IRequestHandler<AddStockCommand, AddStockR
|
||||
|
||||
return new AddStockResponseDto
|
||||
{
|
||||
Success = true,
|
||||
InventoryItemId = response.InventoryItemId,
|
||||
NewQuantity = response.NewQuantity,
|
||||
Message = "ورود کالا با موفقیت ثبت شد"
|
||||
NewQuantity = response.NewQuantity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+4
-6
@@ -3,17 +3,15 @@ namespace BackOffice.BFF.Application.InventoryCQ.Commands.AdjustStock;
|
||||
public record AdjustStockCommand : IRequest<AdjustStockResponseDto>
|
||||
{
|
||||
public long ProductId { get; init; }
|
||||
public int ProductType { get; init; } // 1=Regular, 2=Discount
|
||||
public int ProductType { get; init; } // 1=RegularProduct, 2=DiscountProduct
|
||||
public int NewQuantity { get; init; }
|
||||
public string? Note { get; init; }
|
||||
public long? WarehouseId { get; init; }
|
||||
public string? Reason { get; init; }
|
||||
public string? ReferenceNumber { get; init; }
|
||||
}
|
||||
|
||||
public class AdjustStockResponseDto
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public int OldQuantity { get; set; }
|
||||
public int PreviousQuantity { get; set; }
|
||||
public int NewQuantity { get; set; }
|
||||
public int Difference { get; set; }
|
||||
public string? Message { get; set; }
|
||||
}
|
||||
|
||||
+7
-6
@@ -20,18 +20,19 @@ public class AdjustStockCommandHandler : IRequestHandler<AdjustStockCommand, Adj
|
||||
NewQuantity = request.NewQuantity
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.Note))
|
||||
protoRequest.Reason = request.Note;
|
||||
if (!string.IsNullOrWhiteSpace(request.Reason))
|
||||
protoRequest.Reason = request.Reason;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.ReferenceNumber))
|
||||
protoRequest.ReferenceNumber = request.ReferenceNumber;
|
||||
|
||||
var response = await _context.Inventory.AdjustStockAsync(protoRequest, cancellationToken: cancellationToken);
|
||||
|
||||
return new AdjustStockResponseDto
|
||||
{
|
||||
Success = true,
|
||||
OldQuantity = response.PreviousQuantity,
|
||||
PreviousQuantity = response.PreviousQuantity,
|
||||
NewQuantity = response.NewQuantity,
|
||||
Difference = response.Difference,
|
||||
Message = "تعدیل موجودی با موفقیت انجام شد"
|
||||
Difference = response.Difference
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ namespace BackOffice.BFF.Application.InventoryCQ.Commands.RecordLoss;
|
||||
public record RecordLossCommand : IRequest<bool>
|
||||
{
|
||||
public long ProductId { get; init; }
|
||||
public int ProductType { get; init; } // 1=Regular, 2=Discount
|
||||
public int ProductType { get; init; } // 1=RegularProduct, 2=DiscountProduct
|
||||
public int Quantity { get; init; }
|
||||
public int LossType { get; init; } // 40=Loss, 41=Damaged, 42=Expired
|
||||
public string? Note { get; init; }
|
||||
public long? WarehouseId { get; init; }
|
||||
public string? Reason { get; init; }
|
||||
public string? ReferenceNumber { get; init; }
|
||||
}
|
||||
|
||||
+5
-2
@@ -21,8 +21,11 @@ public class RecordLossCommandHandler : IRequestHandler<RecordLossCommand, bool>
|
||||
LossType = (StockMovementType)request.LossType
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.Note))
|
||||
protoRequest.Reason = request.Note;
|
||||
if (!string.IsNullOrWhiteSpace(request.Reason))
|
||||
protoRequest.Reason = request.Reason;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.ReferenceNumber))
|
||||
protoRequest.ReferenceNumber = request.ReferenceNumber;
|
||||
|
||||
await _context.Inventory.RecordLossAsync(protoRequest, cancellationToken: cancellationToken);
|
||||
return true;
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ namespace BackOffice.BFF.Application.InventoryCQ.Commands.UpdateInventorySetting
|
||||
|
||||
public record UpdateInventorySettingsCommand : IRequest<bool>
|
||||
{
|
||||
public long InventoryItemId { get; init; }
|
||||
public long Id { get; init; }
|
||||
public int LowStockThreshold { get; init; }
|
||||
public int ReorderPoint { get; init; }
|
||||
public int MaxStockLevel { get; init; }
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ public class UpdateInventorySettingsCommandHandler : IRequestHandler<UpdateInven
|
||||
{
|
||||
var protoRequest = new UpdateInventorySettingsRequest
|
||||
{
|
||||
Id = request.InventoryItemId,
|
||||
Id = request.Id,
|
||||
LowStockThreshold = request.LowStockThreshold,
|
||||
ReorderPoint = request.ReorderPoint,
|
||||
MaxStockLevel = request.MaxStockLevel
|
||||
|
||||
+9
-6
@@ -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; }
|
||||
}
|
||||
|
||||
+14
-6
@@ -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()
|
||||
};
|
||||
}
|
||||
|
||||
+3
-1
@@ -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; }
|
||||
}
|
||||
|
||||
+5
-3
@@ -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()
|
||||
};
|
||||
}
|
||||
|
||||
+6
-21
@@ -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();
|
||||
}
|
||||
|
||||
+9
-5
@@ -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()
|
||||
};
|
||||
}
|
||||
|
||||
+3
-5
@@ -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;
|
||||
}
|
||||
|
||||
+4
-6
@@ -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()
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user