refs #375. Corregidos errores con Uuid
parent
68ea45a1f9
commit
1350735e5c
|
@ -5,6 +5,8 @@ api_platform:
|
|||
path_segment_name_generator: 'api_platform.path_segment_name_generator.dash'
|
||||
formats:
|
||||
jsonld: ['application/ld+json', 'application/json']
|
||||
patch_formats:
|
||||
jsonld: ['application/ld+json', 'application/json']
|
||||
mapping:
|
||||
paths: ['%kernel.project_dir%/config/api_platform', '%kernel.project_dir%/src/Dto']
|
||||
defaults:
|
||||
|
|
|
@ -6,11 +6,13 @@ use App\Repository\UserRepository;
|
|||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
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;
|
||||
|
||||
#[ORM\Entity(repositoryClass: UserRepository::class)]
|
||||
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_USERNAME', fields: ['username'])]
|
||||
#[UniqueEntity(fields: ['username'], message: 'There is already an account with this username')]
|
||||
class User extends AbstractEntity implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
{
|
||||
use ToggleableTrait;
|
||||
|
|
|
@ -12,16 +12,21 @@ use ApiPlatform\Validator\ValidatorInterface;
|
|||
use App\Dto\Input\UserInput;
|
||||
use App\Dto\Output\UserOutput;
|
||||
use App\Repository\UserRepository;
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
|
||||
class UserProcessor implements ProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private UserRepository $userRepository,
|
||||
private ValidatorInterface $validator
|
||||
private readonly UserRepository $userRepository,
|
||||
private readonly ValidatorInterface $validator,
|
||||
private readonly UserPasswordHasherInterface $userPasswordHasher
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = [])
|
||||
{
|
||||
switch ($operation){
|
||||
|
@ -34,6 +39,9 @@ class UserProcessor implements ProcessorInterface
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function processCreateOrUpdate($data, Operation $operation, array $uriVariables = [], array $context = []): UserOutput
|
||||
{
|
||||
if (!($data instanceof UserInput)) {
|
||||
|
@ -42,10 +50,13 @@ class UserProcessor implements ProcessorInterface
|
|||
|
||||
$entity = null;
|
||||
if (isset($uriVariables['uuid'])) {
|
||||
$entity = $this->userRepository->findOneByUuid($uriVariables['id']);
|
||||
$entity = $this->userRepository->findOneByUuid($uriVariables['uuid']);
|
||||
}
|
||||
|
||||
$user = $data->createOrUpdateEntity($entity);
|
||||
|
||||
$user->setPassword($this->userPasswordHasher->hashPassword($user, $data->password));
|
||||
|
||||
$this->validator->validate($user);
|
||||
$this->userRepository->save($user);
|
||||
|
||||
|
@ -54,7 +65,7 @@ class UserProcessor implements ProcessorInterface
|
|||
|
||||
private function processDelete($data, Operation $operation, array $uriVariables = [], array $context = []): null
|
||||
{
|
||||
$user = $this->userRepository->findOneByUuid($uriVariables['id']);
|
||||
$user = $this->userRepository->findOneByUuid($uriVariables['uuid']);
|
||||
$this->userRepository->delete($user);
|
||||
|
||||
return null;
|
||||
|
|
|
@ -63,7 +63,7 @@ class UserProvider implements ProviderInterface
|
|||
if (isset($uriVariables['uuid'])) {
|
||||
$item = $this->itemProvider->provide($operation, $uriVariables, $context);
|
||||
|
||||
return !$item ? new UserInput($item) : null;
|
||||
return $item !== null ? new UserInput($item) : null;
|
||||
}
|
||||
|
||||
return new UserInput();
|
||||
|
|
Loading…
Reference in New Issue