refactor: rename GetByProductAndClient to GetLatestByProductAndClient for clarity in inventory storage repository
Deploy Application / deploy (push) Successful in 24s Details

This commit is contained in:
Habib Fatkhul Rohman 2025-11-26 10:50:59 +07:00
parent 2ef6052a2c
commit 1d3d69a0fb
3 changed files with 25 additions and 25 deletions

View File

@ -59,7 +59,7 @@ func (s *inventoryReceiptService) OnComplete(ctx context.Context, id string) (dt
tx.Rollback() tx.Rollback()
return dtodomain.InventoryReceiptResponse{}, err 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) { if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
tx.Rollback() tx.Rollback()
return dtodomain.InventoryReceiptResponse{}, err return dtodomain.InventoryReceiptResponse{}, err

View File

@ -16,7 +16,7 @@ type InventoryStorageRepository interface {
Update(ctx context.Context, tx *gorm.DB, inventoryStorage entities.InventoryStorageEntity) (entities.InventoryStorageEntity, error) Update(ctx context.Context, tx *gorm.DB, inventoryStorage entities.InventoryStorageEntity) (entities.InventoryStorageEntity, error)
Delete(ctx context.Context, tx *gorm.DB, inventoryStorageId string) error Delete(ctx context.Context, tx *gorm.DB, inventoryStorageId string) error
BulkCreate(ctx context.Context, tx *gorm.DB, inventoryStorages []entities.InventoryStorageEntity) 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) 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. // 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 { if tx == nil {
tx = r.db tx = r.db
} }

View File

@ -168,27 +168,27 @@ func (r *productRepository) GetById(ctx context.Context, tx *gorm.DB, productId
Preload("MaxStockUom"). Preload("MaxStockUom").
Preload("LeadTimeUom"). Preload("LeadTimeUom").
Preload("UomToUom"). Preload("UomToUom").
Preload("CrossReferences"). // Preload("CrossReferences").
Preload("CrossReferences.Vendor"). // Preload("CrossReferences.Vendor").
Preload("InventoryStorages"). // Preload("InventoryStorages").
Preload("InventoryStorages.Client"). // Preload("InventoryStorages.Client").
Preload("InventoryStorages.Product"). // Preload("InventoryStorages.Product").
Preload("InventoryStorages.Aisle"). // Preload("InventoryStorages.Aisle").
Preload("InventoryStorages.Uom"). // Preload("InventoryStorages.Uom").
Preload("InventoryStorages.InvReceipt"). // Preload("InventoryStorages.InvReceipt").
Preload("InventoryStorages.InvRequest"). // Preload("InventoryStorages.InvRequest").
Preload("InventoryTransactions"). // Preload("InventoryTransactions").
Preload("InventoryTransactions.Client"). // Preload("InventoryTransactions.Client").
Preload("InventoryTransactions.Aisle"). // Preload("InventoryTransactions.Aisle").
Preload("InventoryTransactions.InvReceipt"). // Preload("InventoryTransactions.InvReceipt").
Preload("InventoryTransactions.InvReceipt.ReceiptLines"). // Preload("InventoryTransactions.InvReceipt.ReceiptLines").
Preload("InventoryTransactions.InvReceipt.ReceiptLines.Product"). // Preload("InventoryTransactions.InvReceipt.ReceiptLines.Product").
Preload("InventoryTransactions.InvIssue"). // Preload("InventoryTransactions.InvIssue").
Preload("InventoryTransactions.InvIssue.IssueLines"). // Preload("InventoryTransactions.InvIssue.IssueLines").
Preload("InventoryTransactions.InvIssue.IssueLines.Product"). // Preload("InventoryTransactions.InvIssue.IssueLines.Product").
Preload("InventoryTransactions.InvMove"). // Preload("InventoryTransactions.InvMove").
Preload("InventoryTransactions.InvMove.MovementLines"). // Preload("InventoryTransactions.InvMove.MovementLines").
Preload("InventoryTransactions.InvMove.MovementLines.Product"). // Preload("InventoryTransactions.InvMove.MovementLines.Product").
First(&product, "id = ?", productId).Error; err != nil { First(&product, "id = ?", productId).Error; err != nil {
return product, err return product, err
} }
@ -200,7 +200,7 @@ func (r *productRepository) GetAll(ctx context.Context, filter query.ProductFilt
var total int64 var total int64
db := r.db.Model(&entities.MProductEntity{}) db := r.db.Model(&entities.MProductEntity{})
db = query.ApplyProductFilters(db, filter) 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 return nil, 0, err
} }
err := db.Limit(filter.PerPage).Offset(filter.Page).Find(&products).Error err := db.Limit(filter.PerPage).Offset(filter.Page).Find(&products).Error