| @@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration; | |||
| /** | |||
| * Auto-generated Migration: Please modify to your needs! | |||
| */ | |||
| final class Version20240327103616 extends AbstractMigration | |||
| final class Version20240328095507 extends AbstractMigration | |||
| { | |||
| public function getDescription(): string | |||
| { | |||
| @@ -40,9 +40,9 @@ use Symfony\Component\Validator\Constraints\NotBlank; | |||
| new Patch( | |||
| security: 'is_granted("EDIT", object)', | |||
| ), | |||
| new Delete( | |||
| security: 'is_granted("ROLE_ADMIN")', | |||
| ) | |||
| // new Delete( | |||
| // security: 'is_granted("ROLE_ADMIN")', | |||
| // ) | |||
| ], | |||
| security: 'is_granted("ROLE_USER")', | |||
| provider: EntityToDtoStateProvider::class, | |||
| @@ -28,18 +28,20 @@ use Symfony\Component\Validator\Constraints\NotBlank; | |||
| shortName: 'Contact', | |||
| operations: [ | |||
| new Get( | |||
| security: 'is_granted("ROLE_USER")' | |||
| ), | |||
| new GetCollection(), | |||
| new Post( | |||
| security: 'is_granted("ROLE_USER")', | |||
| ), | |||
| new Patch( | |||
| new GetCollection( | |||
| security: 'is_granted("ROLE_USER")', | |||
| ), | |||
| new Delete( | |||
| new Post( | |||
| security: 'is_granted("ROLE_ADMIN")', | |||
| ), | |||
| new Patch( | |||
| security: 'is_granted("ROLE_ADMIN")', | |||
| ) | |||
| ), | |||
| // new Delete( | |||
| // security: 'is_granted("ROLE_ADMIN")', | |||
| // ) | |||
| ], | |||
| order: ['lastName' => 'ASC'], | |||
| security: 'is_granted("ROLE_USER")', | |||
| @@ -82,6 +84,12 @@ class ContactApi | |||
| #[ApiProperty(writable: false)] | |||
| public array $posts = []; | |||
| #[ApiProperty(writable: false)] | |||
| public ?UserApi $createdBy = null; | |||
| #[ApiProperty(writable: false)] | |||
| public ?string $createdByName = null; | |||
| #[ApiProperty(writable: false)] | |||
| public ?\DateTimeImmutable $createdAt = null; | |||
| } | |||
| @@ -43,9 +43,9 @@ use Symfony\Component\Validator\Constraints\NotBlank; | |||
| new Patch( | |||
| security: 'is_granted("ROLE_USER")', | |||
| ), | |||
| new Delete( | |||
| security: 'is_granted("ROLE_ADMIN")', | |||
| ) | |||
| // new Delete( | |||
| // security: 'is_granted("ROLE_ADMIN")', | |||
| // ) | |||
| ], | |||
| security: 'is_granted("ROLE_USER")', | |||
| provider: EntityToDtoStateProvider::class, | |||
| @@ -58,12 +58,6 @@ class DocumentApi | |||
| #[ApiProperty(readable: false, writable: false, identifier: true)] | |||
| public ?int $id = null; | |||
| #[ApiProperty(writable: false)] | |||
| public ?UserApi $createdBy = null; | |||
| #[ApiProperty(writable: false)] | |||
| public ?string $createdByName = null; | |||
| #[NotBlank] | |||
| public ?string $name = null; | |||
| @@ -85,6 +79,12 @@ class DocumentApi | |||
| #[ApiProperty(writable: false)] | |||
| public ?string $documentUrl = null; | |||
| #[ApiProperty(writable: false)] | |||
| public ?UserApi $createdBy = null; | |||
| #[ApiProperty(writable: false)] | |||
| public ?string $createdByName = null; | |||
| #[ApiProperty(writable: false)] | |||
| public ?\DateTimeImmutable $createdAt = null; | |||
| } | |||
| @@ -34,14 +34,14 @@ use Symfony\Component\Validator\Constraints\NotBlank; | |||
| ), | |||
| new GetCollection(), | |||
| new Post( | |||
| security: 'is_granted("ROLE_USER")', | |||
| security: 'is_granted("ROLE_ADMIN")', | |||
| ), | |||
| new Patch( | |||
| security: 'is_granted("ROLE_USER")', | |||
| ), | |||
| new Delete( | |||
| security: 'is_granted("ROLE_ADMIN")', | |||
| ) | |||
| ), | |||
| // new Delete( | |||
| // security: 'is_granted("ROLE_ADMIN")', | |||
| // ) | |||
| ], | |||
| order: ['name' => 'ASC'], | |||
| security: 'is_granted("ROLE_USER")', | |||
| @@ -81,6 +81,12 @@ class PartnerApi | |||
| #[ApiProperty(writable: false)] | |||
| public ?string $logoUrl = null; | |||
| #[ApiProperty(writable: false)] | |||
| public ?UserApi $createdBy = null; | |||
| #[ApiProperty(writable: false)] | |||
| public ?string $createdByName = null; | |||
| #[ApiProperty(writable: false)] | |||
| public ?\DateTimeImmutable $createdAt = null; | |||
| @@ -44,9 +44,9 @@ use Symfony\Component\Validator\Constraints\NotBlank; | |||
| denormalizationContext: ['groups' => 'posting:patch'], | |||
| security: 'is_granted("EDIT", object)', | |||
| ), | |||
| new Delete( | |||
| security: 'is_granted("ROLE_ADMIN")', | |||
| ) | |||
| // new Delete( | |||
| // security: 'is_granted("ROLE_ADMIN")', | |||
| // ) | |||
| ], | |||
| order: ['createdAt' => 'DESC'], | |||
| security: 'is_granted("ROLE_USER")', | |||
| @@ -33,14 +33,14 @@ use Symfony\Component\Validator\Constraints\NotBlank; | |||
| ), | |||
| new GetCollection(), | |||
| new Post( | |||
| security: 'is_granted("ROLE_USER")', | |||
| security: 'is_granted("ROLE_ADMIN")', | |||
| ), | |||
| new Patch( | |||
| security: 'is_granted("ROLE_USER")', | |||
| ), | |||
| new Delete( | |||
| security: 'is_granted("ROLE_ADMIN")', | |||
| ) | |||
| ), | |||
| // new Delete( | |||
| // security: 'is_granted("ROLE_ADMIN")', | |||
| // ) | |||
| ], | |||
| order: ['name' => 'ASC'], | |||
| security: 'is_granted("ROLE_USER")', | |||
| @@ -66,6 +66,12 @@ class ProductApi | |||
| #[ApiProperty(writable: false)] | |||
| public ?string $imageUrl = null; | |||
| #[ApiProperty(writable: false)] | |||
| public ?UserApi $createdBy = null; | |||
| #[ApiProperty(writable: false)] | |||
| public ?string $createdByName = null; | |||
| public ?\DateTimeImmutable $createdAt = null; | |||
| } | |||
| @@ -37,9 +37,9 @@ use Symfony\Component\Validator\Constraints\NotBlank; | |||
| new Patch( | |||
| security: 'is_granted("EDIT", object)', | |||
| ), | |||
| new Delete( | |||
| security: 'is_granted("ROLE_ADMIN")', | |||
| ) | |||
| // new Delete( | |||
| // security: 'is_granted("ROLE_ADMIN")', | |||
| // ) | |||
| ], | |||
| order: ['createdAt' => 'DESC'], | |||
| security: 'is_granted("ROLE_USER")', | |||
| @@ -40,9 +40,9 @@ use Symfony\Component\Validator\Constraints as Assert; | |||
| new Patch( | |||
| security: 'is_granted("ROLE_USER")' | |||
| ), | |||
| new Delete( | |||
| security: 'is_granted("ROLE_USER")', | |||
| ) | |||
| // new Delete( | |||
| // security: 'is_granted("ROLE_USER")', | |||
| // ) | |||
| ], | |||
| order: ['dueAt' => 'DESC'], | |||
| security: 'is_granted("ROLE_USER")', | |||
| @@ -36,9 +36,9 @@ use Symfony\Component\Validator\Constraints\NotBlank; | |||
| new Patch( | |||
| security: 'is_granted("EDIT", object)', | |||
| ), | |||
| new Delete( | |||
| security: 'is_granted("ROLE_ADMIN")', | |||
| ) | |||
| // new Delete( | |||
| // security: 'is_granted("ROLE_ADMIN")', | |||
| // ) | |||
| ], | |||
| security: 'is_granted("ROLE_USER")', | |||
| provider: EntityToDtoStateProvider::class, | |||
| @@ -36,9 +36,9 @@ use Symfony\Component\Validator\Constraints as Assert; | |||
| security: 'is_granted("ROLE_ADMIN")', | |||
| validationContext: ['groups' => ['Default', 'postValidation']] | |||
| ), | |||
| new Patch( | |||
| security: 'is_granted("is_granted("EDIT", object)")' | |||
| ), | |||
| // new Patch( | |||
| // security: 'is_granted("is_granted("EDIT", object)")' | |||
| // ), | |||
| ], | |||
| security: 'is_granted("ROLE_USER")', | |||
| provider: EntityToDtoStateProvider::class, | |||
| @@ -9,6 +9,7 @@ namespace App\Controller; | |||
| use App\Entity\DocumentObject; | |||
| use App\Entity\User; | |||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | |||
| use Symfony\Component\HttpFoundation\Request; | |||
| use Symfony\Component\HttpKernel\Attribute\AsController; | |||
| @@ -24,7 +25,9 @@ final class CreateDocumentObjectAction extends AbstractController | |||
| throw new BadRequestHttpException('"file" is required'); | |||
| } | |||
| $mediaObject = new DocumentObject(); | |||
| $user = $this->getUser(); | |||
| assert($user instanceof User); | |||
| $mediaObject = new DocumentObject($user); | |||
| $mediaObject->file = $uploadedFile; | |||
| return $mediaObject; | |||
| @@ -9,6 +9,7 @@ namespace App\Controller; | |||
| use App\Entity\MediaObject; | |||
| use App\Entity\User; | |||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | |||
| use Symfony\Component\HttpFoundation\Request; | |||
| use Symfony\Component\HttpKernel\Attribute\AsController; | |||
| @@ -24,7 +25,9 @@ final class CreateMediaObjectAction extends AbstractController | |||
| throw new BadRequestHttpException('"file" is required'); | |||
| } | |||
| $mediaObject = new MediaObject(); | |||
| $user = $this->getUser(); | |||
| assert($user instanceof User); | |||
| $mediaObject = new MediaObject($user); | |||
| $mediaObject->file = $uploadedFile; | |||
| return $mediaObject; | |||
| @@ -52,7 +52,7 @@ class AppFixtures extends Fixture | |||
| } | |||
| } | |||
| MediaObjectUserFactory::createMany(20); | |||
| $adminD = UserFactory::createOne( | |||
| [ | |||
| 'email' => 'd.knudsen@spawntree.de', | |||
| @@ -62,6 +62,12 @@ class AppFixtures extends Fixture | |||
| ] | |||
| ); | |||
| $adminD->setRoles(['ROLE_ADMIN']); | |||
| MediaObjectUserFactory::createMany(20); | |||
| MediaObjectLogoFactory::createMany(50); | |||
| MediaObjectContactFactory::createMany(50); | |||
| MediaObjectProductFactory::createMany(50); | |||
| DocumentObjectFactory::createMany(50); | |||
| $adminD->setImage(MediaObjectUserFactory::random()->object()); | |||
| $adminF = UserFactory::createOne( | |||
| [ | |||
| @@ -69,24 +75,40 @@ class AppFixtures extends Fixture | |||
| 'firstName' => 'Florian', | |||
| 'lastName' => 'Eisenmenger', | |||
| 'password' => 'test', | |||
| 'image' => MediaObjectUserFactory::random() | |||
| ] | |||
| ); | |||
| $adminF->setRoles(['ROLE_ADMIN']); | |||
| UserFactory::createMany(10); | |||
| MediaObjectLogoFactory::createMany(50); | |||
| PartnerFactory::createMany(100); | |||
| MediaObjectContactFactory::createMany(50); | |||
| ContactFactory::createMany(200); | |||
| ProductFactory::createMany(100); | |||
| UserFactory::createMany(10, | |||
| [ | |||
| 'image' => MediaObjectUserFactory::random() | |||
| ] | |||
| ); | |||
| PartnerFactory::createMany(100, | |||
| [ | |||
| 'createdBy' => $adminD | |||
| ] | |||
| ); | |||
| ContactFactory::createMany(200, | |||
| [ | |||
| 'createdBy' => $adminD | |||
| ] | |||
| ); | |||
| ProductFactory::createMany(100, | |||
| [ | |||
| 'createdBy' => $adminD | |||
| ] | |||
| ); | |||
| SaleFactory::createMany(50); | |||
| PostingFactory::createMany(200); | |||
| CommentFactory::createMany(300); | |||
| MediaObjectProductFactory::createMany(50); | |||
| TaskFactory::createMany(50); | |||
| TaskNoteFactory::createMany(100); | |||
| PartnerFollowFactory::createMany(100); | |||
| DocumentObjectFactory::createMany(50); | |||
| DocumentFactory::createMany(50); | |||
| } | |||
| } | |||
| @@ -43,15 +43,19 @@ class Contact | |||
| #[ORM\Column(length: 255, nullable: true)] | |||
| private ?string $email = null; | |||
| #[ORM\JoinColumn(nullable: false)] | |||
| private ?User $createdBy = null; | |||
| #[ORM\Column] | |||
| private ?\DateTimeImmutable $createdAt = null; | |||
| #[ORM\OneToMany(mappedBy: 'contact', targetEntity: Posting::class)] | |||
| private Collection $posts; | |||
| public function __construct(Partner $partner) | |||
| public function __construct(Partner $partner, User $createdBy) | |||
| { | |||
| $this->partner = $partner; | |||
| $this->createdBy = $createdBy; | |||
| $this->createdAt = new \DateTimeImmutable(); | |||
| $this->posts = new ArrayCollection(); | |||
| } | |||
| @@ -153,6 +157,16 @@ class Contact | |||
| return $this; | |||
| } | |||
| public function getCreatedBy(): ?User | |||
| { | |||
| return $this->createdBy; | |||
| } | |||
| public function setCreatedBy(?User $createdBy): void | |||
| { | |||
| $this->createdBy = $createdBy; | |||
| } | |||
| public function getCreatedAt(): ?\DateTimeImmutable | |||
| { | |||
| return $this->createdAt; | |||
| @@ -72,11 +72,15 @@ class DocumentObject | |||
| #[ORM\Column(nullable: true)] | |||
| public ?string $filePath = null; | |||
| #[ORM\JoinColumn(nullable: false)] | |||
| private ?User $createdBy = null; | |||
| #[ORM\Column] | |||
| private ?\DateTimeImmutable $createdAt = null; | |||
| public function __construct() | |||
| public function __construct(User $createdBy) | |||
| { | |||
| $this->createdBy = $createdBy; | |||
| $this->createdAt = new \DateTimeImmutable(); | |||
| } | |||
| @@ -100,6 +104,11 @@ class DocumentObject | |||
| return $this->filePath; | |||
| } | |||
| public function getCreatedBy(): ?User | |||
| { | |||
| return $this->createdBy; | |||
| } | |||
| public function getCreatedAt(): ?\DateTimeImmutable | |||
| { | |||
| return $this->createdAt; | |||
| @@ -72,11 +72,15 @@ class MediaObject | |||
| #[ORM\Column(nullable: true)] | |||
| public ?string $filePath = null; | |||
| #[ORM\JoinColumn(nullable: false)] | |||
| private ?User $createdBy = null; | |||
| #[ORM\Column] | |||
| private ?\DateTimeImmutable $createdAt = null; | |||
| public function __construct() | |||
| public function __construct(User $createdBy) | |||
| { | |||
| $this->createdBy = $createdBy; | |||
| $this->createdAt = new \DateTimeImmutable(); | |||
| } | |||
| @@ -100,6 +104,11 @@ class MediaObject | |||
| return $this->filePath; | |||
| } | |||
| public function getCreatedBy(): ?User | |||
| { | |||
| return $this->createdBy; | |||
| } | |||
| public function getCreatedAt(): ?\DateTimeImmutable | |||
| { | |||
| return $this->createdAt; | |||
| @@ -44,17 +44,19 @@ class Partner | |||
| #[ORM\Column(length: 255, nullable: true)] | |||
| private ?string $website = null; | |||
| #[ORM\ManyToOne(targetEntity: MediaObject::class)] | |||
| #[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")] | |||
| private ?MediaObject $logo = null; | |||
| #[ORM\JoinColumn(nullable: false)] | |||
| private ?User $createdBy = null; | |||
| #[ORM\Column] | |||
| private ?\DateTimeImmutable $createdAt = null; | |||
| #[ORM\OneToMany(mappedBy: 'partner', targetEntity: Contact::class)] | |||
| private Collection $contacts; | |||
| #[ORM\ManyToOne(targetEntity: MediaObject::class)] | |||
| #[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")] | |||
| private ?MediaObject $logo = null; | |||
| //#[ORM\OneToMany(mappedBy: 'partner', targetEntity: Posting::class, orphanRemoval: true)] | |||
| #[ORM\OneToMany(mappedBy: 'partner', targetEntity: Posting::class)] | |||
| private Collection $postings; | |||
| @@ -67,8 +69,9 @@ class Partner | |||
| #[ORM\OneToMany(mappedBy: 'partner', targetEntity: PartnerFollow::class)] | |||
| private Collection $partnerFollows; | |||
| public function __construct() | |||
| public function __construct(User $createdBy) | |||
| { | |||
| $this->createdBy = $createdBy; | |||
| $this->createdAt = new \DateTimeImmutable(); | |||
| $this->contacts = new ArrayCollection(); | |||
| $this->postings = new ArrayCollection(); | |||
| @@ -177,6 +180,11 @@ class Partner | |||
| return $this->createdAt; | |||
| } | |||
| public function getCreatedBy(): ?User | |||
| { | |||
| return $this->createdBy; | |||
| } | |||
| public function setCreatedAt(?\DateTimeImmutable $createdAt): void | |||
| { | |||
| $this->createdAt = $createdAt; | |||
| @@ -26,6 +26,9 @@ class Product | |||
| #[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")] | |||
| private ?MediaObject $image = null; | |||
| #[ORM\JoinColumn(nullable: false)] | |||
| private ?User $createdBy = null; | |||
| #[ORM\Column] | |||
| private ?\DateTimeImmutable $createdAt = null; | |||
| @@ -35,8 +38,9 @@ class Product | |||
| #[ORM\OneToMany(mappedBy: 'product', targetEntity: Document::class)] | |||
| private Collection $documentObjects; | |||
| public function __construct() | |||
| public function __construct(User $createdBy) | |||
| { | |||
| $this->createdBy = $createdBy; | |||
| $this->createdAt = new \DateTimeImmutable(); | |||
| $this->sales = new ArrayCollection(); | |||
| $this->documentObjects = new ArrayCollection(); | |||
| @@ -83,6 +87,11 @@ class Product | |||
| return $this; | |||
| } | |||
| public function getCreatedBy(): ?User | |||
| { | |||
| return $this->createdBy; | |||
| } | |||
| public function getCreatedAt(): ?\DateTimeImmutable | |||
| { | |||
| return $this->createdAt; | |||
| @@ -55,7 +55,8 @@ final class ContactFactory extends ModelFactory | |||
| 'phone' => self::faker()->phoneNumber(), | |||
| 'email' => self::faker()->email(), | |||
| 'partner' => PartnerFactory::random(), | |||
| 'image' => MediaObjectContactFactory::random() | |||
| 'image' => MediaObjectContactFactory::random(), | |||
| 'createdBy' => UserFactory::random() | |||
| ]; | |||
| } | |||
| @@ -62,6 +62,7 @@ final class DocumentObjectFactory extends ModelFactory | |||
| $randBool = (bool)random_int(0, 1); | |||
| return [ | |||
| 'file' => new ReplacingFile($randomFile), | |||
| 'createdBy' => UserFactory::random() | |||
| ]; | |||
| } | |||
| @@ -62,7 +62,8 @@ final class MediaObjectContactFactory extends ModelFactory | |||
| } | |||
| return [ | |||
| 'file' => new ReplacingFile($randomFile) | |||
| 'file' => new ReplacingFile($randomFile), | |||
| 'createdBy' => UserFactory::random() | |||
| ]; | |||
| } | |||
| @@ -62,7 +62,8 @@ final class MediaObjectLogoFactory extends ModelFactory | |||
| } | |||
| return [ | |||
| 'file' => new ReplacingFile($randomFile) | |||
| 'file' => new ReplacingFile($randomFile), | |||
| 'createdBy' => UserFactory::random() | |||
| ]; | |||
| } | |||
| @@ -62,7 +62,8 @@ final class MediaObjectProductFactory extends ModelFactory | |||
| } | |||
| return [ | |||
| 'file' => new ReplacingFile($randomFile) | |||
| 'file' => new ReplacingFile($randomFile), | |||
| 'createdBy' => UserFactory::random() | |||
| ]; | |||
| } | |||
| @@ -62,7 +62,8 @@ final class MediaObjectUserFactory extends ModelFactory | |||
| } | |||
| return [ | |||
| 'file' => new ReplacingFile($randomFile) | |||
| 'file' => new ReplacingFile($randomFile), | |||
| 'createdBy' => UserFactory::random() | |||
| ]; | |||
| } | |||
| @@ -60,6 +60,7 @@ final class PartnerFactory extends ModelFactory | |||
| 'country' => self::faker()->randomElement(FakeValues::COUNTRIES), | |||
| 'logo' => MediaObjectLogoFactory::random(), | |||
| 'website' => 'https://spawntree.de/', | |||
| 'createdBy' => UserFactory::random() | |||
| ]; | |||
| } | |||
| @@ -51,6 +51,7 @@ final class ProductFactory extends ModelFactory | |||
| 'name' => self::faker()->randomElement(FakeValues::PRODUCTS), | |||
| 'description' => self::faker()->text(), | |||
| 'image' => MediaObjectProductFactory::createOne(), | |||
| 'createdBy' => UserFactory::random() | |||
| ]; | |||
| } | |||
| @@ -52,7 +52,7 @@ final class TaskFactory extends ModelFactory | |||
| return [ | |||
| 'headline' => self::faker()->randomElement(FakeValues::TASKS), | |||
| 'description' => self::faker()->sentence(), | |||
| 'createdBy' => UserFactory::new(), | |||
| 'createdBy' => UserFactory::random(), | |||
| 'assignedTo' => UserFactory::random(), | |||
| 'partner' => PartnerFactory::random(), | |||
| 'contact' => $randomBoolean ? ContactFactory::random() : null, | |||
| @@ -52,7 +52,6 @@ final class UserFactory extends ModelFactory | |||
| 'email' => self::faker()->email(), | |||
| 'firstName' => self::faker()->firstName(), | |||
| 'lastName' => self::faker()->lastName(), | |||
| 'image' => MediaObjectUserFactory::random(), | |||
| 'password' => "test", | |||
| 'roles' => [], | |||
| ]; | |||
| @@ -5,6 +5,7 @@ namespace App\Mapper; | |||
| use App\ApiResource\ContactApi; | |||
| use App\Entity\Contact; | |||
| use App\Entity\Partner; | |||
| use App\Entity\User; | |||
| use App\Repository\ContactRepository; | |||
| use App\Repository\PartnerRepository; | |||
| use Symfony\Bundle\SecurityBundle\Security; | |||
| @@ -17,6 +18,7 @@ class ContactApiToEntityMapper implements MapperInterface | |||
| { | |||
| public function __construct( | |||
| private ContactRepository $repository, | |||
| private Security $security, | |||
| private MicroMapperInterface $microMapper, | |||
| ) | |||
| { | |||
| @@ -31,13 +33,15 @@ class ContactApiToEntityMapper implements MapperInterface | |||
| if ($dto->id) { | |||
| $entity = $this->repository->find($dto->id); | |||
| } else { | |||
| $user = $this->security->getUser(); | |||
| assert($user instanceof User); | |||
| if ($dto->partner === null) { | |||
| throw new \Exception('Partner missing'); | |||
| } | |||
| $partner = $this->microMapper->map($dto->partner, Partner::class, [ | |||
| MicroMapperInterface::MAX_DEPTH => 1, | |||
| ]); | |||
| $entity = new Contact($partner); | |||
| $entity = new Contact($partner, $user); | |||
| } | |||
| @@ -5,6 +5,7 @@ namespace App\Mapper; | |||
| use App\ApiResource\ContactApi; | |||
| use App\ApiResource\PartnerApi; | |||
| use App\ApiResource\PostingApi; | |||
| use App\ApiResource\UserApi; | |||
| use App\Entity\Contact; | |||
| use App\Entity\Posting; | |||
| use App\Service\FileUrlService; | |||
| @@ -53,6 +54,10 @@ class ContactEntityToApiMapper implements MapperInterface | |||
| $dto->position = $entity->getPosition(); | |||
| $dto->phone = $entity->getPhone(); | |||
| $dto->email = $entity->getEmail(); | |||
| $dto->createdBy = $this->microMapper->map($entity->getCreatedBy(), UserApi::class, [ | |||
| MicroMapperInterface::MAX_DEPTH => 1, | |||
| ]); | |||
| $dto->createdByName = $entity->getCreatedBy()?->getFirstName() . ' ' . $entity->getCreatedBy()?->getLastName(); | |||
| $dto->createdAt = $entity->getCreatedAt(); | |||
| $dto->posts = array_map(function(Posting $posting) { | |||
| @@ -43,10 +43,6 @@ class DocumentEntityToApiMapper implements MapperInterface | |||
| assert($entity instanceof Document); | |||
| assert($dto instanceof DocumentApi); | |||
| $dto->createdBy = $this->microMapper->map($entity->getCreatedBy(), UserApi::class, [ | |||
| MicroMapperInterface::MAX_DEPTH => 1, | |||
| ]); | |||
| $dto->createdByName = $entity->getCreatedBy()?->getFirstName() . ' ' . $entity->getCreatedBy()?->getLastName(); | |||
| $dto->name = $entity->getName(); | |||
| $dto->description = $entity->getDescription(); | |||
| @@ -66,6 +62,11 @@ class DocumentEntityToApiMapper implements MapperInterface | |||
| $dto->documentObject = $entity->getDocumentObject(); | |||
| $dto->documentUrl = $this->fileUrlService->getFileUrl($entity->getDocumentObject()); | |||
| $dto->createdBy = $this->microMapper->map($entity->getCreatedBy(), UserApi::class, [ | |||
| MicroMapperInterface::MAX_DEPTH => 1, | |||
| ]); | |||
| $dto->createdByName = $entity->getCreatedBy()?->getFirstName() . ' ' . $entity->getCreatedBy()?->getLastName(); | |||
| $dto->createdAt = $entity->getCreatedAt(); | |||
| return $dto; | |||
| @@ -19,7 +19,8 @@ use Symfonycasts\MicroMapper\MicroMapperInterface; | |||
| class PartnerApiToEntityMapper implements MapperInterface | |||
| { | |||
| public function __construct( | |||
| private PartnerRepository $repository | |||
| private PartnerRepository $repository, | |||
| private Security $security, | |||
| ) | |||
| { | |||
| @@ -30,7 +31,14 @@ class PartnerApiToEntityMapper implements MapperInterface | |||
| $dto = $from; | |||
| assert($dto instanceof PartnerApi); | |||
| $entity = $dto->id ? $this->repository->find($dto->id) : new Partner(); | |||
| if ($dto->id) { | |||
| $entity = $this->repository->find($dto->id); | |||
| } else { | |||
| $user = $this->security->getUser(); | |||
| assert($user instanceof User); | |||
| $entity = new Partner($user); | |||
| } | |||
| if (!$entity) { | |||
| throw new \Exception('Partner not found'); | |||
| } | |||
| @@ -5,6 +5,7 @@ namespace App\Mapper; | |||
| use App\ApiResource\ContactApi; | |||
| use App\ApiResource\PartnerApi; | |||
| use App\ApiResource\PostingApi; | |||
| use App\ApiResource\UserApi; | |||
| use App\Entity\Contact; | |||
| use App\Entity\Partner; | |||
| use App\Entity\Posting; | |||
| @@ -52,6 +53,10 @@ class PartnerEntityToApiMapper implements MapperInterface | |||
| $dto->website = $entity->getWebsite(); | |||
| $dto->logo = $entity->getLogo(); | |||
| $dto->logoUrl = $this->fileUrlService->getFileUrl($entity->getLogo()); | |||
| $dto->createdBy = $this->microMapper->map($entity->getCreatedBy(), UserApi::class, [ | |||
| MicroMapperInterface::MAX_DEPTH => 1, | |||
| ]); | |||
| $dto->createdByName = $entity->getCreatedBy()?->getFirstName() . ' ' . $entity->getCreatedBy()?->getLastName(); | |||
| $dto->createdAt = $entity->getCreatedAt(); | |||
| $dto->posts = array_map(function(Posting $posting) { | |||
| return $this->microMapper->map($posting, PostingApi::class, [ | |||
| @@ -4,15 +4,19 @@ namespace App\Mapper; | |||
| use App\ApiResource\ProductApi; | |||
| use App\Entity\Product; | |||
| use App\Entity\User; | |||
| use App\Repository\ProductRepository; | |||
| use Symfony\Bundle\SecurityBundle\Security; | |||
| use Symfonycasts\MicroMapper\AsMapper; | |||
| use Symfonycasts\MicroMapper\MapperInterface; | |||
| use Symfonycasts\MicroMapper\MicroMapperInterface; | |||
| #[AsMapper(from: ProductApi::class, to: Product::class)] | |||
| class ProductApiToEntityMapper implements MapperInterface | |||
| { | |||
| public function __construct( | |||
| private ProductRepository $repository | |||
| private ProductRepository $repository, | |||
| private Security $security, | |||
| ) | |||
| { | |||
| @@ -23,9 +27,16 @@ class ProductApiToEntityMapper implements MapperInterface | |||
| $dto = $from; | |||
| assert($dto instanceof ProductApi); | |||
| $entity = $dto->id ? $this->repository->find($dto->id) : new Product(); | |||
| if ($dto->id) { | |||
| $entity = $this->repository->find($dto->id); | |||
| } else { | |||
| $user = $this->security->getUser(); | |||
| assert($user instanceof User); | |||
| $entity = new Product($user); | |||
| } | |||
| if (!$entity) { | |||
| throw new \Exception('Product not found'); | |||
| throw new \Exception('Partner not found'); | |||
| } | |||
| return $entity; | |||
| @@ -3,15 +3,18 @@ | |||
| namespace App\Mapper; | |||
| use App\ApiResource\ProductApi; | |||
| use App\ApiResource\UserApi; | |||
| use App\Entity\Product; | |||
| use App\Service\FileUrlService; | |||
| use Symfonycasts\MicroMapper\AsMapper; | |||
| use Symfonycasts\MicroMapper\MapperInterface; | |||
| use Symfonycasts\MicroMapper\MicroMapperInterface; | |||
| #[AsMapper(from: Product::class, to: ProductApi::class)] | |||
| class ProductEntityToApiMapper implements MapperInterface | |||
| { | |||
| public function __construct( | |||
| private MicroMapperInterface $microMapper, | |||
| private FileUrlService $fileUrlService | |||
| ) { | |||
| } | |||
| @@ -38,6 +41,10 @@ class ProductEntityToApiMapper implements MapperInterface | |||
| $dto->description = $entity->getDescription(); | |||
| $dto->image = $entity->getImage(); | |||
| $dto->imageUrl = $this->fileUrlService->getFileUrl($entity->getImage()); | |||
| $dto->createdBy = $this->microMapper->map($entity->getCreatedBy(), UserApi::class, [ | |||
| MicroMapperInterface::MAX_DEPTH => 1, | |||
| ]); | |||
| $dto->createdByName = $entity->getCreatedBy()?->getFirstName() . ' ' . $entity->getCreatedBy()?->getLastName(); | |||
| return $dto; | |||
| } | |||
| } | |||