|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace PhpList\RestBundle\Subscription\Request; |
| 6 | + |
| 7 | +use OpenApi\Attributes as OA; |
| 8 | +use PhpList\Core\Domain\Subscription\Model\Filter\SubscriberFilter; |
| 9 | +use PhpList\RestBundle\Common\Request\RequestInterface; |
| 10 | +use Symfony\Component\Validator\Constraints as Assert; |
| 11 | + |
| 12 | +#[OA\Schema( |
| 13 | + schema: 'SubscribersFilterRequest', |
| 14 | + properties: [ |
| 15 | + new OA\Property( |
| 16 | + property: 'is_confirmed', |
| 17 | + description: 'Filter by confirmed status', |
| 18 | + type: 'boolean', |
| 19 | + nullable: true |
| 20 | + ), |
| 21 | + new OA\Property( |
| 22 | + property: 'is_blacklisted', |
| 23 | + description: 'Filter by blacklisted status', |
| 24 | + type: 'boolean', |
| 25 | + nullable: true |
| 26 | + ), |
| 27 | + new OA\Property( |
| 28 | + property: 'sort_by', |
| 29 | + description: 'Column to sort by', |
| 30 | + type: 'string', |
| 31 | + nullable: true |
| 32 | + ), |
| 33 | + new OA\Property( |
| 34 | + property: 'sort_direction', |
| 35 | + description: 'Sort direction', |
| 36 | + type: 'string', |
| 37 | + enum: ['asc', 'desc'], |
| 38 | + nullable: true |
| 39 | + ), |
| 40 | + new OA\Property( |
| 41 | + property: 'find_column', |
| 42 | + description: 'Column to search in (requires find_value)', |
| 43 | + type: 'string', |
| 44 | + nullable: true |
| 45 | + ), |
| 46 | + new OA\Property( |
| 47 | + property: 'find_value', |
| 48 | + description: 'Value to search for (requires find_column)', |
| 49 | + type: 'string', |
| 50 | + nullable: true |
| 51 | + ), |
| 52 | + ], |
| 53 | + type: 'object' |
| 54 | +)] |
| 55 | +class SubscribersFilterRequest implements RequestInterface |
| 56 | +{ |
| 57 | + #[Assert\Type(type: 'boolean')] |
| 58 | + public ?bool $isConfirmed = null; |
| 59 | + |
| 60 | + #[Assert\Type(type: 'boolean')] |
| 61 | + public ?bool $isBlacklisted = null; |
| 62 | + |
| 63 | + #[Assert\Type(type: 'string')] |
| 64 | + public ?string $sortBy = null; |
| 65 | + |
| 66 | + #[Assert\Choice(choices: ['asc', 'desc'])] |
| 67 | + public ?string $sortDirection = null; |
| 68 | + |
| 69 | + #[Assert\Type(type: 'string')] |
| 70 | + public ?string $findColumn = null; |
| 71 | + |
| 72 | + #[Assert\Type(type: 'string')] |
| 73 | + public ?string $findValue = null; |
| 74 | + |
| 75 | + public function getDto(): SubscriberFilter |
| 76 | + { |
| 77 | + $findColumn = $this->findColumn; |
| 78 | + $findValue = $this->findValue; |
| 79 | + if (($findColumn === null) xor ($findValue === null)) { |
| 80 | + $findColumn = null; |
| 81 | + $findValue = null; |
| 82 | + } |
| 83 | + |
| 84 | + return new SubscriberFilter( |
| 85 | + isConfirmed: $this->isConfirmed, |
| 86 | + isBlacklisted: $this->isBlacklisted, |
| 87 | + sortBy: $this->sortBy, |
| 88 | + sortDirection: $this->sortDirection, |
| 89 | + findColumn: $findColumn, |
| 90 | + findValue: $findValue, |
| 91 | + ); |
| 92 | + } |
| 93 | +} |
0 commit comments