mirror of
https://forge.chapril.org/tykayn/caisse-bliss
synced 2025-06-20 01:44:42 +02:00
list products with DTO
This commit is contained in:
parent
cd4b678002
commit
0d672d5447
7 changed files with 57 additions and 11 deletions
|
@ -61,10 +61,21 @@ class GroupOfProducts
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getProducts(): ?object
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getProductsDTO(): array
|
||||
{
|
||||
return $this->products;
|
||||
$productsDTO = [];
|
||||
foreach ($this->products as $product) {
|
||||
$productsDTO[] = $product->toArray();
|
||||
}
|
||||
return $productsDTO;
|
||||
}
|
||||
public function getProducts(): ?object
|
||||
{
|
||||
return $this->products;
|
||||
}
|
||||
|
||||
public function setProducts(object $products): static
|
||||
{
|
||||
|
|
|
@ -11,6 +11,7 @@ use Doctrine\Common\Collections\Collection;
|
|||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Filter\UserProductsFilter;
|
||||
use App\DTO\UserDTO;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
|
||||
#[ApiResource(paginationEnabled: false)]
|
||||
#[UserProductsFilter]
|
||||
|
@ -23,9 +24,11 @@ class Product
|
|||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
#[Groups(['default', 'relation'])]
|
||||
private ?string $name = null;
|
||||
|
||||
#[ORM\Column]
|
||||
#[Groups(['default', 'relation'])]
|
||||
private ?float $price = null;
|
||||
|
||||
#[ORM\Column]
|
||||
|
@ -190,4 +193,14 @@ class Product
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'price' => $this->price,
|
||||
// Ajoutez d'autres propriétés si nécessaire
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue