feat(mappings): add InventoryProfile for mapping Inventory entities to Protobuf DTOs
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 1m41s
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 1m41s
This commit is contained in:
@@ -0,0 +1,63 @@
|
|||||||
|
using CMSMicroservice.Domain.Entities;
|
||||||
|
using CMSMicroservice.Protobuf.Protos.Inventory;
|
||||||
|
using Google.Protobuf.WellKnownTypes;
|
||||||
|
using ProtoProductType = CMSMicroservice.Protobuf.Protos.Inventory.ProductType;
|
||||||
|
using DomainProductType = CMSMicroservice.Domain.Enums.ProductType;
|
||||||
|
using ProtoStockMovementType = CMSMicroservice.Protobuf.Protos.Inventory.StockMovementType;
|
||||||
|
using DomainStockMovementType = CMSMicroservice.Domain.Enums.StockMovementType;
|
||||||
|
|
||||||
|
namespace CMSMicroservice.WebApi.Common.Mappings;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Mapster profile برای Inventory entities به Protobuf DTOs
|
||||||
|
/// </summary>
|
||||||
|
public class InventoryProfile : IRegister
|
||||||
|
{
|
||||||
|
void IRegister.Register(TypeAdapterConfig config)
|
||||||
|
{
|
||||||
|
// Warehouse Entity به WarehouseDto
|
||||||
|
config.NewConfig<Warehouse, WarehouseDto>()
|
||||||
|
.Map(dest => dest.Id, src => src.Id)
|
||||||
|
.Map(dest => dest.Name, src => src.Name)
|
||||||
|
.Map(dest => dest.Code, src => src.Code ?? string.Empty)
|
||||||
|
.Map(dest => dest.Address, src => src.Address ?? string.Empty)
|
||||||
|
.Map(dest => dest.IsDefault, src => src.IsDefault)
|
||||||
|
.Map(dest => dest.IsActive, src => src.IsActive);
|
||||||
|
|
||||||
|
// InventoryItem Entity به InventoryItemDto
|
||||||
|
config.NewConfig<InventoryItem, InventoryItemDto>()
|
||||||
|
.Map(dest => dest.Id, src => src.Id)
|
||||||
|
.Map(dest => dest.WarehouseId, src => src.WarehouseId)
|
||||||
|
.Map(dest => dest.WarehouseName, src => src.Warehouse != null ? src.Warehouse.Name : string.Empty)
|
||||||
|
.Map(dest => dest.ProductId, src => src.ProductId.HasValue ? new Int64Value { Value = src.ProductId.Value } : null)
|
||||||
|
.Map(dest => dest.DiscountProductId, src => src.DiscountProductId.HasValue ? new Int64Value { Value = src.DiscountProductId.Value } : null)
|
||||||
|
.Map(dest => dest.ProductType, src => (ProtoProductType)src.ProductType)
|
||||||
|
.Map(dest => dest.Quantity, src => src.Quantity)
|
||||||
|
.Map(dest => dest.ReservedQuantity, src => src.ReservedQuantity)
|
||||||
|
.Map(dest => dest.AvailableQuantity, src => src.AvailableQuantity)
|
||||||
|
.Map(dest => dest.LowStockThreshold, src => src.LowStockThreshold)
|
||||||
|
.Map(dest => dest.ReorderPoint, src => src.ReorderPoint)
|
||||||
|
.Map(dest => dest.MaxStockLevel, src => src.MaxStockLevel)
|
||||||
|
.Map(dest => dest.LastRestockedAt, src => src.LastRestockedAt.HasValue ? Timestamp.FromDateTime(src.LastRestockedAt.Value.ToUniversalTime()) : null)
|
||||||
|
.Map(dest => dest.LastSoldAt, src => src.LastSoldAt.HasValue ? Timestamp.FromDateTime(src.LastSoldAt.Value.ToUniversalTime()) : null)
|
||||||
|
.Map(dest => dest.ProductTitle, src => src.Product != null ? src.Product.Title : (src.DiscountProduct != null ? src.DiscountProduct.Title : string.Empty))
|
||||||
|
.Map(dest => dest.ProductPrice, src => src.Product != null ? src.Product.Price : (src.DiscountProduct != null ? src.DiscountProduct.Price : 0))
|
||||||
|
.Map(dest => dest.Created, src => Timestamp.FromDateTime(src.Created.ToUniversalTime()));
|
||||||
|
|
||||||
|
// StockMovement Entity به StockMovementDto
|
||||||
|
config.NewConfig<StockMovement, StockMovementDto>()
|
||||||
|
.Map(dest => dest.Id, src => src.Id)
|
||||||
|
.Map(dest => dest.InventoryItemId, src => src.InventoryItemId)
|
||||||
|
.Map(dest => dest.MovementType, src => (ProtoStockMovementType)src.MovementType)
|
||||||
|
.Map(dest => dest.Quantity, src => src.Quantity)
|
||||||
|
.Map(dest => dest.QuantityBefore, src => src.QuantityBefore)
|
||||||
|
.Map(dest => dest.QuantityAfter, src => src.QuantityAfter)
|
||||||
|
.Map(dest => dest.Note, src => src.Note ?? string.Empty)
|
||||||
|
.Map(dest => dest.ReferenceNumber, src => src.ReferenceNumber ?? string.Empty)
|
||||||
|
.Map(dest => dest.OrderId, src => src.OrderId.HasValue ? new Int64Value { Value = src.OrderId.Value } : null)
|
||||||
|
.Map(dest => dest.DiscountOrderId, src => src.DiscountOrderId.HasValue ? new Int64Value { Value = src.DiscountOrderId.Value } : null)
|
||||||
|
.Map(dest => dest.PerformedByUserId, src => src.PerformedByUserId.HasValue ? new Int64Value { Value = src.PerformedByUserId.Value } : null)
|
||||||
|
.Map(dest => dest.Created, src => Timestamp.FromDateTime(src.Created.ToUniversalTime()))
|
||||||
|
.Map(dest => dest.ProductTitle, src => src.InventoryItem != null && src.InventoryItem.Product != null ? src.InventoryItem.Product.Title : (src.InventoryItem != null && src.InventoryItem.DiscountProduct != null ? src.InventoryItem.DiscountProduct.Title : string.Empty));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user