Improved serialized fields

This commit is contained in:
Jan Böhmer 2023-03-12 01:12:35 +01:00
parent b99e6c9a21
commit 2c67586873
18 changed files with 84 additions and 1 deletions

View file

@ -26,6 +26,7 @@ use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Validator\Constraints\Selectable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
trait BasicPropertyTrait
@ -33,12 +34,14 @@ trait BasicPropertyTrait
/**
* @var string A text describing what this part does
* @ORM\Column(type="text")
* @Groups({"simple", "extended", "full"})
*/
protected string $description = '';
/**
* @var string A comment/note related to this part
* @ORM\Column(type="text")
* @Groups({"extended", "full"})
*/
protected string $comment = '';
@ -51,6 +54,7 @@ trait BasicPropertyTrait
/**
* @var bool true, if the part is marked as favorite
* @ORM\Column(type="boolean")
* @Groups({"extended", "full"})
*/
protected bool $favorite = false;
@ -61,6 +65,7 @@ trait BasicPropertyTrait
* @ORM\JoinColumn(name="id_category", referencedColumnName="id", nullable=false)
* @Selectable()
* @Assert\NotNull(message="validator.select_valid_category")
* @Groups({"simple", "extended", "full"})
*/
protected ?Category $category = null;
@ -69,6 +74,7 @@ trait BasicPropertyTrait
* @ORM\ManyToOne(targetEntity="Footprint")
* @ORM\JoinColumn(name="id_footprint", referencedColumnName="id")
* @Selectable()
* @Groups({"simple", "extended", "full"})
*/
protected ?Footprint $footprint = null;

View file

@ -26,6 +26,7 @@ use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\PartLot;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
@ -38,6 +39,7 @@ trait InstockTrait
* @ORM\OneToMany(targetEntity="PartLot", mappedBy="part", cascade={"persist", "remove"}, orphanRemoval=true)
* @Assert\Valid()
* @ORM\OrderBy({"amount" = "DESC"})
* @Groups({"extended", "full"})
*/
protected $partLots;
@ -46,6 +48,7 @@ trait InstockTrait
* Given in the partUnit.
* @ORM\Column(type="float")
* @Assert\PositiveOrZero()
* @Groups({"extended", "full"})
*/
protected float $minamount = 0;
@ -53,6 +56,7 @@ trait InstockTrait
* @var ?MeasurementUnit the unit in which the part's amount is measured
* @ORM\ManyToOne(targetEntity="MeasurementUnit")
* @ORM\JoinColumn(name="id_part_unit", referencedColumnName="id", nullable=true)
* @Groups({"extended", "full"})
*/
protected ?MeasurementUnit $partUnit = null;

View file

@ -26,6 +26,7 @@ use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Part;
use App\Validator\Constraints\Selectable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
@ -45,12 +46,14 @@ trait ManufacturerTrait
* @var string the url to the part on the manufacturer's homepage
* @ORM\Column(type="string")
* @Assert\Url()
* @Groups({"full"})
*/
protected string $manufacturer_product_url = '';
/**
* @var string The product number used by the manufacturer. If this is set to "", the name field is used.
* @ORM\Column(type="string")
* @Groups({"extended", "full"})
*/
protected string $manufacturer_product_number = '';
@ -58,6 +61,7 @@ trait ManufacturerTrait
* @var string The production status of this part. Can be one of the specified ones.
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Choice({"announced", "active", "nrfnd", "eol", "discontinued", ""})
* @Groups({"extended", "full"})
*/
protected ?string $manufacturing_status = '';

View file

@ -24,6 +24,7 @@ namespace App\Entity\Parts\PartTraits;
use App\Entity\PriceInformations\Orderdetail;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use function count;
use Doctrine\Common\Collections\Collection;
@ -39,6 +40,7 @@ trait OrderTrait
* @ORM\OneToMany(targetEntity="App\Entity\PriceInformations\Orderdetail", mappedBy="part", cascade={"persist", "remove"}, orphanRemoval=true)
* @Assert\Valid()
* @ORM\OrderBy({"supplierpartnr" = "ASC"})
* @Groups({"extended", "full"})
*/
protected $orderdetails;