소스 검색

Refactoring repositories #1084

feature/souke
Guillaume Bourgeois 1 년 전
부모
커밋
9a51fb6eb2
2개의 변경된 파일26개의 추가작업 그리고 10개의 파일을 삭제
  1. +10
    -10
      common/logic/Distribution/ProductDistribution/Repository/ProductDistributionRepository.php
  2. +16
    -0
      common/logic/Distribution/ProductDistribution/Repository/ProductDistributionRepositoryQuery.php

+ 10
- 10
common/logic/Distribution/ProductDistribution/Repository/ProductDistributionRepository.php 파일 보기

@@ -28,23 +28,23 @@ class ProductDistributionRepository extends AbstractRepository

public function findOneProductDistribution(Distribution $distribution, Product $product): ?ProductDistribution
{
return ProductDistribution::searchOne([
'id_distribution' => $distribution->id,
'id_product' => $product->id
]);
return $this->createDefaultQuery()
->filterByDistribution($distribution)
->filterByProduct($product)
->findOne();
}

public function findProductDistributionsByDistribution(Distribution $distribution): array
{
return ProductDistribution::searchAll([
'id_distribution' => $distribution->id
]) ;
return $this->createDefaultQuery()
->filterByDistribution($distribution)
->find();
}

public function countProductDistributionsByDistribution(Distribution $distribution): int
{
return ProductDistribution::searchCount([
'id_distribution' => $distribution->id
]);
return $this->createDefaultQuery()
->filterByDistribution($distribution)
->count();
}
}

+ 16
- 0
common/logic/Distribution/ProductDistribution/Repository/ProductDistributionRepositoryQuery.php 파일 보기

@@ -3,8 +3,10 @@
namespace common\logic\Distribution\ProductDistribution\Repository;

use common\logic\AbstractRepositoryQuery;
use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Distribution\ProductDistribution\Model\ProductDistribution;
use common\logic\Distribution\ProductDistribution\Service\ProductDistributionDefinition;
use common\logic\Product\Product\Model\Product;
use yii\db\ActiveQuery;

class ProductDistributionRepositoryQuery extends AbstractRepositoryQuery
@@ -15,4 +17,18 @@ class ProductDistributionRepositoryQuery extends AbstractRepositoryQuery
{
$this->loadDefinition(ProductDistributionDefinition::class);
}

public function filterByDistribution(Distribution $distribution): self
{
$this->andWhere(['id_distribution' => $distribution->id]);

return $this;
}

public function filterByProduct(Product $product): self
{
$this->andWhere(['id_product' => $product->id]);

return $this;
}
}

Loading…
취소
저장