src/BusinessFeature/Yclients/Dto/ServiceDto.php line 11

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Slivki\BusinessFeature\Yclients\Dto;
  4. use OpenApi\Annotations as OA;
  5. use JsonSerializable;
  6. use Slivki\BusinessFeature\Yclients\HttpClient\Response\ServiceResponse;
  7. final class ServiceDto implements JsonSerializable
  8. {
  9.     /**
  10.      * @OA\Property(
  11.      *     property="id",
  12.      *     type="integer",
  13.      *     description="Идентификатор услуги",
  14.      * ),
  15.      *
  16.      * @var int
  17.      */
  18.     private int $id;
  19.     /**
  20.      * @OA\Property(
  21.      *     property="title",
  22.      *     type="string",
  23.      *     description="Название услуги",
  24.      * ),
  25.      *
  26.      * @var string
  27.      */
  28.     private string $title;
  29.     /**
  30.      * @OA\Property(
  31.      *     property="category_id",
  32.      *     type="integer",
  33.      *     description="Идентификатор категории",
  34.      * ),
  35.      *
  36.      * @var int
  37.      */
  38.     private int $categoryId;
  39.     /**
  40.      * @OA\Property(
  41.      *     property="price_min",
  42.      *     type="number",
  43.      *     description="Минимальная цена",
  44.      * ),
  45.      *
  46.      * @var float
  47.      */
  48.     private float $priceMin;
  49.     /**
  50.      * @OA\Property(
  51.      *     property="price_max",
  52.      *     type="number",
  53.      *     description="Максимальная цена",
  54.      * ),
  55.      *
  56.      * @var float
  57.      */
  58.     private float $priceMax;
  59.     /**
  60.      * @OA\Property(
  61.      *     property="external_link",
  62.      *     type="string",
  63.      *     description="Ссылка на внешний ресурс",
  64.      * ),
  65.      *
  66.      * @var string|null
  67.      */
  68.     private ?string $externalLink;
  69.     public function __construct(
  70.         int $id,
  71.         string $title,
  72.         int $categoryId,
  73.         float $priceMin,
  74.         float $priceMax,
  75.         ?string $externalLink
  76.     ) {
  77.         $this->id $id;
  78.         $this->title $title;
  79.         $this->categoryId $categoryId;
  80.         $this->priceMin $priceMin;
  81.         $this->priceMax $priceMax;
  82.         $this->externalLink $externalLink;
  83.     }
  84.     public static function createFromResponse(ServiceResponse $response, ?string $externalLink): self
  85.     {
  86.         return new self(
  87.             $response->getId(),
  88.             $response->getTitle(),
  89.             $response->getCategoryId(),
  90.             $response->getPriceMin(),
  91.             $response->getPriceMax(),
  92.             $externalLink
  93.         );
  94.     }
  95.     public function jsonSerialize(): array
  96.     {
  97.         return [
  98.             'id' => $this->id,
  99.             'title' => $this->title,
  100.             'category_id' => $this->categoryId,
  101.             'price_min' => $this->priceMin,
  102.             'price_max' => $this->priceMax,
  103.             'external_link' => $this->externalLink,
  104.         ];
  105.     }
  106. }