This commit is contained in:
2026-05-13 22:30:55 +07:00
parent 4130cb66df
commit 3b62504798
3 changed files with 30 additions and 7 deletions
@@ -23,16 +23,28 @@ type ProductOutletPriceProcessor interface {
}
type ProductOutletPriceProcessorImpl struct {
repo repository.ProductOutletPriceRepository
repo repository.ProductOutletPriceRepository
productRepo ProductRepository
outletRepo OutletRepository
}
func NewProductOutletPriceProcessorImpl(repo repository.ProductOutletPriceRepository) *ProductOutletPriceProcessorImpl {
func NewProductOutletPriceProcessorImpl(repo repository.ProductOutletPriceRepository, productRepo ProductRepository, outletRepo OutletRepository) *ProductOutletPriceProcessorImpl {
return &ProductOutletPriceProcessorImpl{
repo: repo,
repo: repo,
productRepo: productRepo,
outletRepo: outletRepo,
}
}
func (p *ProductOutletPriceProcessorImpl) Upsert(ctx context.Context, req *models.CreateProductOutletPriceRequest) (*models.ProductOutletPrice, error) {
if _, err := p.productRepo.GetByID(ctx, req.ProductID); err != nil {
return nil, fmt.Errorf("product not found: %w", err)
}
if _, err := p.outletRepo.GetByID(ctx, req.OutletID); err != nil {
return nil, fmt.Errorf("outlet not found: %w", err)
}
entity := &entities.ProductOutletPrice{
ProductID: req.ProductID,
OutletID: req.OutletID,
@@ -43,7 +55,12 @@ func (p *ProductOutletPriceProcessorImpl) Upsert(ctx context.Context, req *model
return nil, fmt.Errorf("failed to upsert product outlet price: %w", err)
}
return mappers.ProductOutletPriceEntityToModel(entity), nil
actual, err := p.repo.GetByProductAndOutlet(ctx, req.ProductID, req.OutletID)
if err != nil {
return nil, fmt.Errorf("failed to retrieve upserted product outlet price: %w", err)
}
return mappers.ProductOutletPriceEntityToModel(actual), nil
}
func (p *ProductOutletPriceProcessorImpl) GetByProductAndOutlet(ctx context.Context, productID, outletID uuid.UUID) (*models.ProductOutletPrice, error) {