From 1d3d69a0fba3578c1e20db9fb3689b099e9e60d3 Mon Sep 17 00:00:00 2001 From: Habib Fatkhul Rohman Date: Wed, 26 Nov 2025 10:50:59 +0700 Subject: [PATCH] refactor: rename GetByProductAndClient to GetLatestByProductAndClient for clarity in inventory storage repository --- .../service/inventory_receipt_service.go | 2 +- .../inventory_storage_repository.go | 4 +- .../product/repository/product_repository.go | 44 +++++++++---------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/modules/inventory_receipt/service/inventory_receipt_service.go b/modules/inventory_receipt/service/inventory_receipt_service.go index b537742..3061ef1 100644 --- a/modules/inventory_receipt/service/inventory_receipt_service.go +++ b/modules/inventory_receipt/service/inventory_receipt_service.go @@ -59,7 +59,7 @@ func (s *inventoryReceiptService) OnComplete(ctx context.Context, id string) (dt tx.Rollback() return dtodomain.InventoryReceiptResponse{}, err } - existing, err := s.invStorageRepository.GetByProductAndClient(ctx, tx, product.ID.String(), receipt.ClientID.String()) + existing, err := s.invStorageRepository.GetLatestByProductAndClient(ctx, tx, product.ID.String(), receipt.ClientID.String()) if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { tx.Rollback() return dtodomain.InventoryReceiptResponse{}, err diff --git a/modules/inventory_storage/repository/inventory_storage_repository.go b/modules/inventory_storage/repository/inventory_storage_repository.go index e39fa5b..80e5c6b 100644 --- a/modules/inventory_storage/repository/inventory_storage_repository.go +++ b/modules/inventory_storage/repository/inventory_storage_repository.go @@ -16,7 +16,7 @@ type InventoryStorageRepository interface { Update(ctx context.Context, tx *gorm.DB, inventoryStorage entities.InventoryStorageEntity) (entities.InventoryStorageEntity, error) Delete(ctx context.Context, tx *gorm.DB, inventoryStorageId string) error BulkCreate(ctx context.Context, tx *gorm.DB, inventoryStorages []entities.InventoryStorageEntity) error - GetByProductAndClient(ctx context.Context, tx *gorm.DB, productId string, clientId string) (entities.InventoryStorageEntity, error) + GetLatestByProductAndClient(ctx context.Context, tx *gorm.DB, productId string, clientId string) (entities.InventoryStorageEntity, error) GetStoragesByProductAndClient(ctx context.Context, tx *gorm.DB, productId string, clientId string) ([]entities.InventoryStorageEntity, error) } @@ -45,7 +45,7 @@ func (r *inventoryStorageRepository) GetStoragesByProductAndClient(ctx context.C } // GetByProductAndClient implements InventoryStorageRepository. -func (r *inventoryStorageRepository) GetByProductAndClient(ctx context.Context, tx *gorm.DB, productId string, clientId string) (entities.InventoryStorageEntity, error) { +func (r *inventoryStorageRepository) GetLatestByProductAndClient(ctx context.Context, tx *gorm.DB, productId string, clientId string) (entities.InventoryStorageEntity, error) { if tx == nil { tx = r.db } diff --git a/modules/product/repository/product_repository.go b/modules/product/repository/product_repository.go index dd43ba9..132a1bc 100644 --- a/modules/product/repository/product_repository.go +++ b/modules/product/repository/product_repository.go @@ -168,27 +168,27 @@ func (r *productRepository) GetById(ctx context.Context, tx *gorm.DB, productId Preload("MaxStockUom"). Preload("LeadTimeUom"). Preload("UomToUom"). - Preload("CrossReferences"). - Preload("CrossReferences.Vendor"). - Preload("InventoryStorages"). - Preload("InventoryStorages.Client"). - Preload("InventoryStorages.Product"). - Preload("InventoryStorages.Aisle"). - Preload("InventoryStorages.Uom"). - Preload("InventoryStorages.InvReceipt"). - Preload("InventoryStorages.InvRequest"). - Preload("InventoryTransactions"). - Preload("InventoryTransactions.Client"). - Preload("InventoryTransactions.Aisle"). - Preload("InventoryTransactions.InvReceipt"). - Preload("InventoryTransactions.InvReceipt.ReceiptLines"). - Preload("InventoryTransactions.InvReceipt.ReceiptLines.Product"). - Preload("InventoryTransactions.InvIssue"). - Preload("InventoryTransactions.InvIssue.IssueLines"). - Preload("InventoryTransactions.InvIssue.IssueLines.Product"). - Preload("InventoryTransactions.InvMove"). - Preload("InventoryTransactions.InvMove.MovementLines"). - Preload("InventoryTransactions.InvMove.MovementLines.Product"). + // Preload("CrossReferences"). + // Preload("CrossReferences.Vendor"). + // Preload("InventoryStorages"). + // Preload("InventoryStorages.Client"). + // Preload("InventoryStorages.Product"). + // Preload("InventoryStorages.Aisle"). + // Preload("InventoryStorages.Uom"). + // Preload("InventoryStorages.InvReceipt"). + // Preload("InventoryStorages.InvRequest"). + // Preload("InventoryTransactions"). + // Preload("InventoryTransactions.Client"). + // Preload("InventoryTransactions.Aisle"). + // Preload("InventoryTransactions.InvReceipt"). + // Preload("InventoryTransactions.InvReceipt.ReceiptLines"). + // Preload("InventoryTransactions.InvReceipt.ReceiptLines.Product"). + // Preload("InventoryTransactions.InvIssue"). + // Preload("InventoryTransactions.InvIssue.IssueLines"). + // Preload("InventoryTransactions.InvIssue.IssueLines.Product"). + // Preload("InventoryTransactions.InvMove"). + // Preload("InventoryTransactions.InvMove.MovementLines"). + // Preload("InventoryTransactions.InvMove.MovementLines.Product"). First(&product, "id = ?", productId).Error; err != nil { return product, err } @@ -200,7 +200,7 @@ func (r *productRepository) GetAll(ctx context.Context, filter query.ProductFilt var total int64 db := r.db.Model(&entities.MProductEntity{}) db = query.ApplyProductFilters(db, filter) - if err := db.Count(&total).Error; err != nil { + if err := db.Preload("Client").Preload("Category").Preload("Uom").Preload("DimUom").Preload("WeightUom").Preload("VolumeUom").Preload("MinStockUom").Preload("MaxStockUom").Preload("LeadTimeUom").Preload("UomToUom").Count(&total).Error; err != nil { return nil, 0, err } err := db.Limit(filter.PerPage).Offset(filter.Page).Find(&products).Error