-
-
Notifications
You must be signed in to change notification settings - Fork 635
Expand file tree
/
Copy pathPromoCodeRepository.php
More file actions
52 lines (44 loc) · 1.52 KB
/
PromoCodeRepository.php
File metadata and controls
52 lines (44 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace HiEvents\Repository\Eloquent;
use HiEvents\DomainObjects\Generated\PromoCodeDomainObjectAbstract;
use HiEvents\DomainObjects\PromoCodeDomainObject;
use HiEvents\Http\DTO\QueryParamsDTO;
use HiEvents\Models\PromoCode;
use HiEvents\Repository\Interfaces\PromoCodeRepositoryInterface;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Database\Eloquent\Builder;
/**
* @extends BaseRepository<PromoCodeDomainObject>
*/
class PromoCodeRepository extends BaseRepository implements PromoCodeRepositoryInterface
{
protected function getModel(): string
{
return PromoCode::class;
}
public function getDomainObject(): string
{
return PromoCodeDomainObject::class;
}
public function findByEventId(int $eventId, QueryParamsDTO $params): LengthAwarePaginator
{
$where = [
[PromoCodeDomainObjectAbstract::EVENT_ID, '=', $eventId]
];
if ($params->query) {
$where[] = static function (Builder $builder) use ($params) {
$builder
->orWhere(PromoCodeDomainObjectAbstract::CODE, 'ilike', '%' . $params->query . '%');
};
}
$this->model = $this->model->orderBy(
column: $params->sort_by ?? PromoCodeDomainObject::getDefaultSort(),
direction: $params->sort_direction ?? 'desc',
);
return $this->paginateWhere(
where: $where,
limit: $params->per_page,
page: $params->page,
);
}
}