feat: add /me endpoint

This commit is contained in:
Maël Gangloff
2024-07-18 12:36:01 +02:00
parent 9d88599d86
commit 2efc3da018
4 changed files with 54 additions and 7 deletions

View File

@@ -2,6 +2,10 @@
namespace App\Entity;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use App\Controller\MeController;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
@@ -9,10 +13,22 @@ use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Attribute\Groups;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_EMAIL', fields: ['email'])]
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
#[ApiResource(
operations: [
new Get(
uriTemplate: '/me',
controller: MeController::class,
paginationEnabled: false,
normalizationContext: ["groups" => "user:list"],
read: false
)
]
)]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
@@ -21,12 +37,14 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
private ?int $id = null;
#[ORM\Column(length: 180)]
#[Groups(['user:list'])]
private ?string $email = null;
/**
* @var array The user roles
*/
#[ORM\Column]
#[Groups(['user:list'])]
private array $roles = [];
/**