Daniel 2 år sedan
förälder
incheckning
f7f83a7e4d
8 ändrade filer med 31 tillägg och 10 borttagningar
  1. +1
    -1
      config/packages/lexik_jwt_authentication.yaml
  2. +4
    -4
      src/ApiResource/ContactApi.php
  3. +5
    -0
      src/Entity/User.php
  4. +7
    -1
      src/Mapper/ContactEntityToApiMapper.php
  5. +2
    -1
      src/Mapper/UserApiToEntityMapper.php
  6. +7
    -0
      src/State/EntityClassDtoStateProcessor.php
  7. +4
    -2
      src/State/EntityToDtoStateProvider.php
  8. +1
    -1
      tests/Functional/UserResourceTest.php

+ 1
- 1
config/packages/lexik_jwt_authentication.yaml Visa fil

@@ -2,4 +2,4 @@ lexik_jwt_authentication:
secret_key: '%env(resolve:JWT_SECRET_KEY)%'
public_key: '%env(resolve:JWT_PUBLIC_KEY)%'
pass_phrase: '%env(JWT_PASSPHRASE)%'
token_ttl: 3600
token_ttl: 36000

+ 4
- 4
src/ApiResource/ContactApi.php Visa fil

@@ -10,9 +10,9 @@ namespace App\ApiResource;
use ApiPlatform\Doctrine\Orm\State\Options;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use App\Entity\Contact;
use App\Entity\MediaObject;
use App\Entity\Partner;
use App\Enum\PartnerType;
use App\State\EntityClassDtoStateProcessor;
use App\State\EntityToDtoStateProvider;
use ApiPlatform\Metadata\Delete;
@@ -43,7 +43,7 @@ use Symfony\Component\Validator\Constraints\NotBlank;
security: 'is_granted("ROLE_USER")',
provider: EntityToDtoStateProvider::class,
processor: EntityClassDtoStateProcessor::class,
stateOptions: new Options(entityClass: Partner::class),
stateOptions: new Options(entityClass: Contact::class),
)]
class ContactApi
{
@@ -56,11 +56,11 @@ class ContactApi
#[NotBlank]
public ?string $lastName = null;

public ?Partner $partner = null;
public ?PartnerApi $partner = null;

public ?\DateTimeInterface $birthday = null;

public ?MediaObject $image = null;
public ?MediaObject $image = null;

public ?string $position = null;



+ 5
- 0
src/Entity/User.php Visa fil

@@ -160,6 +160,11 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
return $this->postings;
}

public function setPostings(Collection $postings): void
{
$this->postings = $postings;
}

public function addUserPost(Posting $post): static
{
if (!$this->postings->contains($post)) {


+ 7
- 1
src/Mapper/ContactEntityToApiMapper.php Visa fil

@@ -3,7 +3,9 @@
namespace App\Mapper;

use App\ApiResource\ContactApi;
use App\ApiResource\PartnerApi;
use App\Entity\Contact;
use App\Entity\Partner;
use Symfonycasts\MicroMapper\AsMapper;
use Symfonycasts\MicroMapper\MapperInterface;
use Symfonycasts\MicroMapper\MicroMapperInterface;
@@ -37,7 +39,11 @@ class ContactEntityToApiMapper implements MapperInterface

$dto->firstName = $entity->getFirstName();
$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->image = $entity->getImage();
$dto->position = $entity->getPosition();


+ 2
- 1
src/Mapper/UserApiToEntityMapper.php Visa fil

@@ -6,6 +6,7 @@ use App\ApiResource\UserApi;
use App\Entity\User;
use App\Entity\Posting;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfonycasts\MicroMapper\AsMapper;
@@ -51,7 +52,7 @@ class UserApiToEntityMapper implements MapperInterface
$entity->setPassword($this->userPasswordHasher->hashPassword($entity, $dto->password));
}

$userPostsEntities = [];
$userPostsEntities = new ArrayCollection();
foreach ($dto->postings as $userPostApi) {
$userPostsEntities[] = $this->microMapper->map($userPostApi, Posting::class, [
MicroMapperInterface::MAX_DEPTH => 0,


+ 7
- 0
src/State/EntityClassDtoStateProcessor.php Visa fil

@@ -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 = [])
{
$stateOptions = $operation->getStateOptions();


+ 4
- 2
src/State/EntityToDtoStateProvider.php Visa fil

@@ -12,7 +12,7 @@ use ApiPlatform\State\ProviderInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfonycasts\MicroMapper\MicroMapperInterface;

class EntityToDtoStateProvider implements ProviderInterface
class EntityToDtoStateProvider implements ProviderInterface
{
public function __construct(
#[Autowire(service: CollectionProvider::class)] private ProviderInterface $collectionProvider,
@@ -54,6 +54,8 @@ class EntityToDtoStateProvider implements ProviderInterface

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);
}
}

+ 1
- 1
tests/Functional/UserResourceTest.php Visa fil

@@ -36,7 +36,7 @@ class UserResourceTest extends KernelTestCase
$json->assertMissing('password');
$json->assertMissing('id');
})
->post('/login', [
->post('/auth', [
'json' => [
'email' => 'draggin_in_the_morning@coffee.com',
'password' => 'password',


Laddar…
Avbryt
Spara