| @@ -2,4 +2,4 @@ lexik_jwt_authentication: | |||||
| secret_key: '%env(resolve:JWT_SECRET_KEY)%' | secret_key: '%env(resolve:JWT_SECRET_KEY)%' | ||||
| public_key: '%env(resolve:JWT_PUBLIC_KEY)%' | public_key: '%env(resolve:JWT_PUBLIC_KEY)%' | ||||
| pass_phrase: '%env(JWT_PASSPHRASE)%' | pass_phrase: '%env(JWT_PASSPHRASE)%' | ||||
| token_ttl: 3600 | |||||
| token_ttl: 36000 | |||||
| @@ -10,9 +10,9 @@ namespace App\ApiResource; | |||||
| use ApiPlatform\Doctrine\Orm\State\Options; | use ApiPlatform\Doctrine\Orm\State\Options; | ||||
| use ApiPlatform\Metadata\ApiProperty; | use ApiPlatform\Metadata\ApiProperty; | ||||
| use ApiPlatform\Metadata\ApiResource; | use ApiPlatform\Metadata\ApiResource; | ||||
| use App\Entity\Contact; | |||||
| use App\Entity\MediaObject; | use App\Entity\MediaObject; | ||||
| use App\Entity\Partner; | use App\Entity\Partner; | ||||
| use App\Enum\PartnerType; | |||||
| use App\State\EntityClassDtoStateProcessor; | use App\State\EntityClassDtoStateProcessor; | ||||
| use App\State\EntityToDtoStateProvider; | use App\State\EntityToDtoStateProvider; | ||||
| use ApiPlatform\Metadata\Delete; | use ApiPlatform\Metadata\Delete; | ||||
| @@ -43,7 +43,7 @@ use Symfony\Component\Validator\Constraints\NotBlank; | |||||
| security: 'is_granted("ROLE_USER")', | security: 'is_granted("ROLE_USER")', | ||||
| provider: EntityToDtoStateProvider::class, | provider: EntityToDtoStateProvider::class, | ||||
| processor: EntityClassDtoStateProcessor::class, | processor: EntityClassDtoStateProcessor::class, | ||||
| stateOptions: new Options(entityClass: Partner::class), | |||||
| stateOptions: new Options(entityClass: Contact::class), | |||||
| )] | )] | ||||
| class ContactApi | class ContactApi | ||||
| { | { | ||||
| @@ -56,11 +56,11 @@ class ContactApi | |||||
| #[NotBlank] | #[NotBlank] | ||||
| public ?string $lastName = null; | public ?string $lastName = null; | ||||
| public ?Partner $partner = null; | |||||
| public ?PartnerApi $partner = null; | |||||
| public ?\DateTimeInterface $birthday = null; | public ?\DateTimeInterface $birthday = null; | ||||
| public ?MediaObject $image = null; | |||||
| public ?MediaObject $image = null; | |||||
| public ?string $position = null; | public ?string $position = null; | ||||
| @@ -160,6 +160,11 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface | |||||
| return $this->postings; | return $this->postings; | ||||
| } | } | ||||
| public function setPostings(Collection $postings): void | |||||
| { | |||||
| $this->postings = $postings; | |||||
| } | |||||
| public function addUserPost(Posting $post): static | public function addUserPost(Posting $post): static | ||||
| { | { | ||||
| if (!$this->postings->contains($post)) { | if (!$this->postings->contains($post)) { | ||||
| @@ -3,7 +3,9 @@ | |||||
| namespace App\Mapper; | namespace App\Mapper; | ||||
| use App\ApiResource\ContactApi; | use App\ApiResource\ContactApi; | ||||
| use App\ApiResource\PartnerApi; | |||||
| use App\Entity\Contact; | use App\Entity\Contact; | ||||
| use App\Entity\Partner; | |||||
| use Symfonycasts\MicroMapper\AsMapper; | use Symfonycasts\MicroMapper\AsMapper; | ||||
| use Symfonycasts\MicroMapper\MapperInterface; | use Symfonycasts\MicroMapper\MapperInterface; | ||||
| use Symfonycasts\MicroMapper\MicroMapperInterface; | use Symfonycasts\MicroMapper\MicroMapperInterface; | ||||
| @@ -37,7 +39,11 @@ class ContactEntityToApiMapper implements MapperInterface | |||||
| $dto->firstName = $entity->getFirstName(); | $dto->firstName = $entity->getFirstName(); | ||||
| $dto->lastName = $entity->getLastName(); | $dto->lastName = $entity->getLastName(); | ||||
| $dto->partner = $entity->getPartner(); | |||||
| $dto->partner = $this->microMapper->map( | |||||
| $entity->getPartner(), PartnerApi::class, [ | |||||
| MicroMapperInterface::MAX_DEPTH => 0, | |||||
| ] | |||||
| ); | |||||
| $dto->birthday = $entity->getBirthday(); | $dto->birthday = $entity->getBirthday(); | ||||
| $dto->image = $entity->getImage(); | $dto->image = $entity->getImage(); | ||||
| $dto->position = $entity->getPosition(); | $dto->position = $entity->getPosition(); | ||||
| @@ -6,6 +6,7 @@ use App\ApiResource\UserApi; | |||||
| use App\Entity\User; | use App\Entity\User; | ||||
| use App\Entity\Posting; | use App\Entity\Posting; | ||||
| use App\Repository\UserRepository; | use App\Repository\UserRepository; | ||||
| use Doctrine\Common\Collections\ArrayCollection; | |||||
| use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; | use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; | ||||
| use Symfony\Component\PropertyAccess\PropertyAccessorInterface; | use Symfony\Component\PropertyAccess\PropertyAccessorInterface; | ||||
| use Symfonycasts\MicroMapper\AsMapper; | use Symfonycasts\MicroMapper\AsMapper; | ||||
| @@ -51,7 +52,7 @@ class UserApiToEntityMapper implements MapperInterface | |||||
| $entity->setPassword($this->userPasswordHasher->hashPassword($entity, $dto->password)); | $entity->setPassword($this->userPasswordHasher->hashPassword($entity, $dto->password)); | ||||
| } | } | ||||
| $userPostsEntities = []; | |||||
| $userPostsEntities = new ArrayCollection(); | |||||
| foreach ($dto->postings as $userPostApi) { | foreach ($dto->postings as $userPostApi) { | ||||
| $userPostsEntities[] = $this->microMapper->map($userPostApi, Posting::class, [ | $userPostsEntities[] = $this->microMapper->map($userPostApi, Posting::class, [ | ||||
| MicroMapperInterface::MAX_DEPTH => 0, | MicroMapperInterface::MAX_DEPTH => 0, | ||||
| @@ -22,6 +22,13 @@ class EntityClassDtoStateProcessor implements ProcessorInterface | |||||
| } | } | ||||
| /** | |||||
| * @param mixed $data | |||||
| * @param Operation $operation | |||||
| * @param array $uriVariables | |||||
| * @param array $context | |||||
| * @return mixed|void|null | |||||
| */ | |||||
| public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []) | public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []) | ||||
| { | { | ||||
| $stateOptions = $operation->getStateOptions(); | $stateOptions = $operation->getStateOptions(); | ||||
| @@ -12,7 +12,7 @@ use ApiPlatform\State\ProviderInterface; | |||||
| use Symfony\Component\DependencyInjection\Attribute\Autowire; | use Symfony\Component\DependencyInjection\Attribute\Autowire; | ||||
| use Symfonycasts\MicroMapper\MicroMapperInterface; | use Symfonycasts\MicroMapper\MicroMapperInterface; | ||||
| class EntityToDtoStateProvider implements ProviderInterface | |||||
| class EntityToDtoStateProvider implements ProviderInterface | |||||
| { | { | ||||
| public function __construct( | public function __construct( | ||||
| #[Autowire(service: CollectionProvider::class)] private ProviderInterface $collectionProvider, | #[Autowire(service: CollectionProvider::class)] private ProviderInterface $collectionProvider, | ||||
| @@ -54,6 +54,8 @@ class EntityToDtoStateProvider implements ProviderInterface | |||||
| private function mapEntityToDto(object $entity, string $resourceClass): object | private function mapEntityToDto(object $entity, string $resourceClass): object | ||||
| { | { | ||||
| return $this->microMapper->map($entity, $resourceClass); | |||||
| $test = $this->microMapper->map($entity, $resourceClass); | |||||
| return $test; | |||||
| //return $this->microMapper->map($entity, $resourceClass); | |||||
| } | } | ||||
| } | } | ||||
| @@ -36,7 +36,7 @@ class UserResourceTest extends KernelTestCase | |||||
| $json->assertMissing('password'); | $json->assertMissing('password'); | ||||
| $json->assertMissing('id'); | $json->assertMissing('id'); | ||||
| }) | }) | ||||
| ->post('/login', [ | |||||
| ->post('/auth', [ | |||||
| 'json' => [ | 'json' => [ | ||||
| 'email' => 'draggin_in_the_morning@coffee.com', | 'email' => 'draggin_in_the_morning@coffee.com', | ||||
| 'password' => 'password', | 'password' => 'password', | ||||