fix(schema): aligner mappings et sortie machine

This commit is contained in:
2026-01-15 13:42:29 +01:00
parent 2c3fbb093a
commit ea45ce9d0a
6 changed files with 139 additions and 14 deletions

View File

@@ -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,
];

View File

@@ -0,0 +1,110 @@
<?php
declare(strict_types=1);
namespace App\Doctrine\QuoteStrategy;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\ORM\Internal\SQLResultCasing;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\JoinColumnMapping;
use Doctrine\ORM\Mapping\ManyToManyOwningSideMapping;
use Doctrine\ORM\Mapping\QuoteStrategy;
use function array_map;
use function array_merge;
use function assert;
use function explode;
use function implode;
/**
* Quote all identifiers to preserve camelCase column names in Postgres.
*/
final class AlwaysQuoteStrategy implements QuoteStrategy
{
use SQLResultCasing;
public function getColumnName(string $fieldName, ClassMetadata $class, AbstractPlatform $platform): string
{
return $platform->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);
}
}

View File

@@ -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;

View File

@@ -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;