Add proper length constraint validations to all string mapped ORM fields, so they show a nice validation error, instead of a 500 error

Fixes issue #544
This commit is contained in:
Jan Böhmer 2024-03-06 19:46:11 +01:00
parent 113e5b3bcd
commit dc7c13479c
17 changed files with 43 additions and 0 deletions

View file

@ -27,6 +27,7 @@ use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Embeddable;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints\Length;
#[Embeddable]
class EDACategoryInfo
@ -36,6 +37,7 @@ class EDACategoryInfo
*/
#[Column(type: Types::STRING, nullable: true)]
#[Groups(['full', 'category:read', 'category:write'])]
#[Length(max: 255)]
private ?string $reference_prefix = null;
/** @var bool|null Visibility of this part to EDA software in trinary logic. True=Visible, False=Invisible, Null=Auto */
@ -61,6 +63,7 @@ class EDACategoryInfo
/** @var string|null The KiCAD schematic symbol, which should be used (the path to the library) */
#[Column(type: Types::STRING, nullable: true)]
#[Groups(['full', 'category:read', 'category:write'])]
#[Length(max: 255)]
private ?string $kicad_symbol = null;
public function getReferencePrefix(): ?string

View file

@ -27,6 +27,7 @@ use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Embeddable;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints\Length;
#[Embeddable]
class EDAFootprintInfo
@ -34,6 +35,7 @@ class EDAFootprintInfo
/** @var string|null The KiCAD footprint, which should be used (the path to the library) */
#[Column(type: Types::STRING, nullable: true)]
#[Groups(['full', 'footprint:read', 'footprint:write'])]
#[Length(max: 255)]
private ?string $kicad_footprint = null;
public function getKicadFootprint(): ?string

View file

@ -27,6 +27,7 @@ use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Embeddable;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints\Length;
#[Embeddable]
class EDAPartInfo
@ -36,11 +37,13 @@ class EDAPartInfo
*/
#[Column(type: Types::STRING, nullable: true)]
#[Groups(['full', 'eda_info:read', 'eda_info:write'])]
#[Length(max: 255)]
private ?string $reference_prefix = null;
/** @var string|null The value, which should be shown together with the part (e.g. 470 for a 470 Ohm resistor) */
#[Column(type: Types::STRING, nullable: true)]
#[Groups(['full', 'eda_info:read', 'eda_info:write'])]
#[Length(max: 255)]
private ?string $value = null;
/** @var bool|null Visibility of this part to EDA software in trinary logic. True=Visible, False=Invisible, Null=Auto */
@ -66,11 +69,13 @@ class EDAPartInfo
/** @var string|null The KiCAD schematic symbol, which should be used (the path to the library) */
#[Column(type: Types::STRING, nullable: true)]
#[Groups(['full', 'eda_info:read', 'eda_info:write'])]
#[Length(max: 255)]
private ?string $kicad_symbol = null;
/** @var string|null The KiCAD footprint, which should be used (the path to the library) */
#[Column(type: Types::STRING, nullable: true)]
#[Groups(['full', 'eda_info:read', 'eda_info:write'])]
#[Length(max: 255)]
private ?string $kicad_footprint = null;
public function __construct()