diff --git a/config/packages/doctrine.yaml b/config/packages/doctrine.yaml index 6c57caf..f79ea2c 100644 --- a/config/packages/doctrine.yaml +++ b/config/packages/doctrine.yaml @@ -9,7 +9,8 @@ doctrine: profiling_collect_backtrace: '%kernel.debug%' orm: validate_xml_mapping: true - naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware + naming_strategy: doctrine.orm.naming_strategy.default + quote_strategy: doctrine.orm.quote_strategy.default identity_generation_preferences: Doctrine\DBAL\Platforms\PostgreSQLPlatform: identity auto_mapping: true diff --git a/scripts/insert_profiles.sql b/scripts/insert_profiles.sql index e5fe79b..f71bfb7 100644 --- a/scripts/insert_profiles.sql +++ b/scripts/insert_profiles.sql @@ -1,5 +1,5 @@ -INSERT INTO public.profiles (id, firstname, lastname, isactive, createdat, updatedat) +INSERT INTO public.profiles (id, firstname, lastname, email, isactive, createdat, updatedat) VALUES - ('admin-default-profile', 'Admin', 'General', true, '2025-09-23 13:09:47.804', '2025-09-23 13:09:47.804'), - ('cmhab2j3x003g47v77xhnm1ff', 'Elodie', 'Souriau', true, '2025-10-28 08:29:25.437', '2025-10-28 08:29:25.437') + ('admin-default-profile', 'Admin', 'General', 'admin@admin.fr', true, '2025-09-23 13:09:47.804', '2025-09-23 13:09:47.804'), + ('cmhab2j3x003g47v77xhnm1ff', 'Elodie', 'Souriau', 'elodie@gg.fr', true, '2025-10-28 08:29:25.437', '2025-10-28 08:29:25.437') ON CONFLICT (id) DO NOTHING; diff --git a/src/Controller/MachineSkeletonController.php b/src/Controller/MachineSkeletonController.php index bf614fc..dcadb9b 100644 --- a/src/Controller/MachineSkeletonController.php +++ b/src/Controller/MachineSkeletonController.php @@ -400,13 +400,27 @@ class MachineSkeletonController extends AbstractController private function normalizeMachine(Machine $machine): array { + $site = $machine->getSite(); + $typeMachine = $machine->getTypeMachine(); + return [ 'id' => $machine->getId(), 'name' => $machine->getName(), 'reference' => $machine->getReference(), 'prix' => $machine->getPrix(), - 'siteId' => $machine->getSite()->getId(), - 'typeMachineId' => $machine->getTypeMachine()?->getId(), + 'siteId' => $site->getId(), + 'site' => [ + 'id' => $site->getId(), + 'name' => $site->getName(), + ], + 'typeMachineId' => $typeMachine?->getId(), + 'typeMachine' => $typeMachine ? [ + 'id' => $typeMachine->getId(), + 'name' => $typeMachine->getName(), + 'category' => $typeMachine->getCategory(), + 'description' => $typeMachine->getDescription(), + ] : null, + 'constructeurs' => $this->normalizeConstructeurs($machine->getConstructeurs()), 'documents' => null, 'customFieldValues' => null, ]; diff --git a/src/Doctrine/QuoteStrategy/AlwaysQuoteStrategy.php b/src/Doctrine/QuoteStrategy/AlwaysQuoteStrategy.php new file mode 100644 index 0000000..e7d42b0 --- /dev/null +++ b/src/Doctrine/QuoteStrategy/AlwaysQuoteStrategy.php @@ -0,0 +1,110 @@ +quoteSingleIdentifier($class->fieldMappings[$fieldName]->columnName); + } + + public function getTableName(ClassMetadata $class, AbstractPlatform $platform): string + { + $tableName = $platform->quoteSingleIdentifier($class->table['name']); + + if (! empty($class->table['schema'])) { + return $platform->quoteSingleIdentifier($class->table['schema']) . '.' . $tableName; + } + + return $tableName; + } + + public function getSequenceName(array $definition, ClassMetadata $class, AbstractPlatform $platform): string + { + return implode('.', array_map( + static fn (string $part) => $platform->quoteSingleIdentifier($part), + explode('.', $definition['sequenceName']), + )); + } + + public function getJoinTableName( + ManyToManyOwningSideMapping $association, + ClassMetadata $class, + AbstractPlatform $platform, + ): string { + $schema = ''; + + if (isset($association->joinTable->schema)) { + $schema = $platform->quoteSingleIdentifier($association->joinTable->schema) . '.'; + } + + return $schema . $platform->quoteSingleIdentifier($association->joinTable->name); + } + + public function getJoinColumnName(JoinColumnMapping $joinColumn, ClassMetadata $class, AbstractPlatform $platform): string + { + return $platform->quoteSingleIdentifier($joinColumn->name); + } + + public function getReferencedJoinColumnName( + JoinColumnMapping $joinColumn, + ClassMetadata $class, + AbstractPlatform $platform, + ): string { + return $platform->quoteSingleIdentifier($joinColumn->referencedColumnName); + } + + public function getIdentifierColumnNames(ClassMetadata $class, AbstractPlatform $platform): array + { + $quotedColumnNames = []; + + foreach ($class->identifier as $fieldName) { + if (isset($class->fieldMappings[$fieldName])) { + $quotedColumnNames[] = $this->getColumnName($fieldName, $class, $platform); + continue; + } + + $assoc = $class->associationMappings[$fieldName]; + assert($assoc->isToOneOwningSide()); + $joinColumns = $assoc->joinColumns; + $assocQuotedColumnNames = array_map( + static fn (JoinColumnMapping $joinColumn) => $platform->quoteSingleIdentifier($joinColumn->name), + $joinColumns, + ); + + $quotedColumnNames = array_merge($quotedColumnNames, $assocQuotedColumnNames); + } + + return $quotedColumnNames; + } + + public function getColumnAlias( + string $columnName, + int $counter, + AbstractPlatform $platform, + ClassMetadata|null $class = null, + ): string { + return $this->getSQLResultCasing($platform, $columnName . '_' . $counter); + } +} diff --git a/src/Entity/Profile.php b/src/Entity/Profile.php index 02cd15e..fd943c3 100644 --- a/src/Entity/Profile.php +++ b/src/Entity/Profile.php @@ -45,17 +45,17 @@ class Profile implements UserInterface, PasswordAuthenticatedUserInterface #[Groups(['profile:read', 'profile:write'])] private ?string $email = null; - #[ORM\Column(type: 'string', length: 100, name: 'firstName')] + #[ORM\Column(type: 'string', length: 100, name: 'firstname')] #[Assert\NotBlank] #[Groups(['profile:read', 'profile:write'])] private string $firstName; - #[ORM\Column(type: 'string', length: 100, name: 'lastName')] + #[ORM\Column(type: 'string', length: 100, name: 'lastname')] #[Assert\NotBlank] #[Groups(['profile:read', 'profile:write'])] private string $lastName; - #[ORM\Column(type: 'boolean', options: ['default' => true], name: 'isActive')] + #[ORM\Column(type: 'boolean', options: ['default' => true], name: 'isactive')] #[Groups(['profile:read', 'profile:write'])] private bool $isActive = true; @@ -73,11 +73,11 @@ class Profile implements UserInterface, PasswordAuthenticatedUserInterface #[Groups(['profile:write'])] private ?string $password = null; - #[ORM\Column(type: 'datetime_immutable', name: 'createdAt')] + #[ORM\Column(type: 'datetime_immutable', name: 'createdat')] #[Groups(['profile:read'])] private DateTimeImmutable $createdAt; - #[ORM\Column(type: 'datetime_immutable', name: 'updatedAt')] + #[ORM\Column(type: 'datetime_immutable', name: 'updatedat')] #[Groups(['profile:read'])] private DateTimeImmutable $updatedAt; diff --git a/src/Entity/TypeMachine.php b/src/Entity/TypeMachine.php index 77f3648..0cf0e85 100644 --- a/src/Entity/TypeMachine.php +++ b/src/Entity/TypeMachine.php @@ -50,7 +50,7 @@ class TypeMachine #[Groups(['type_machine:read', 'type_machine:write'])] private ?string $description = null; - #[ORM\Column(type: Types::STRING, length: 255, nullable: true, name: 'maintenanceFrequency')] + #[ORM\Column(type: Types::STRING, length: 255, nullable: true)] #[Groups(['type_machine:read', 'type_machine:write'])] private ?string $category = null; @@ -58,11 +58,11 @@ class TypeMachine #[Groups(['type_machine:read', 'type_machine:write'])] private ?string $maintenanceFrequency = null; - #[ORM\Column(type: Types::JSON, nullable: true, name: 'criticalParts')] + #[ORM\Column(type: Types::JSON, nullable: true)] #[Groups(['type_machine:read', 'type_machine:write'])] private ?array $components = null; - #[ORM\Column(type: Types::JSON, nullable: true, name: 'machinePieces')] + #[ORM\Column(type: Types::JSON, nullable: true)] #[Groups(['type_machine:read', 'type_machine:write'])] private ?array $criticalParts = null;