feat: add POST watchlist endpoint

This commit is contained in:
Maël Gangloff
2024-07-18 13:40:49 +02:00
parent 2efc3da018
commit 1533469441
4 changed files with 81 additions and 15 deletions

View File

@@ -3,6 +3,9 @@
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use App\Repository\WatchListRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
@@ -13,15 +16,26 @@ use Symfony\Component\Uid\Uuid;
#[ORM\Entity(repositoryClass: WatchListRepository::class)]
#[ApiResource(
shortName: 'Watchlist',
normalizationContext: ['groups' => 'watchlist:item', 'domain:list'],
denormalizationContext: ['groups' => 'watchlist:item', 'domain:list'],
paginationEnabled: false
operations: [
new GetCollection(
routeName: 'watchlist_get_all_mine', normalizationContext: ['groups' => 'watchlist:list'],
name: 'get_all_mine',
),
new Get(
normalizationContext: ['groups' => 'watchlist:item']
),
new Post(
routeName: 'watchlist_create', normalizationContext: ['groups' => 'watchlist:list'],
denormalizationContext: ['groups' => 'watchlist:create'],
name: 'create'
)
],
)]
class WatchList
{
#[ORM\Id]
#[ORM\Column(length: 36)]
#[Groups(['watchlist:item'])]
#[Groups(['watchlist:item', 'watchlist:list'])]
private string $token;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'watchLists')]
@@ -35,7 +49,7 @@ class WatchList
#[ORM\JoinTable(name: 'watch_lists_domains',
joinColumns: [new ORM\JoinColumn(name: 'watch_list_token', referencedColumnName: 'token')],
inverseJoinColumns: [new ORM\JoinColumn(name: 'domain_ldh_name', referencedColumnName: 'ldh_name')])]
#[Groups(['watchlist:item'])]
#[Groups(['watchlist:item', 'watchlist:create'])]
private Collection $domains;
public function __construct()