Added simple endpoint for basic part infos and partlots

This commit is contained in:
Jan Böhmer 2023-09-03 23:58:09 +02:00
parent e04b635c98
commit 09acca950d
9 changed files with 77 additions and 28 deletions

View file

@ -22,6 +22,7 @@ declare(strict_types=1);
namespace App\Entity\Parts\PartTraits;
use ApiPlatform\Metadata\ApiProperty;
use App\Entity\Parts\InfoProviderReference;
use Doctrine\DBAL\Types\Types;
use App\Entity\Parts\Part;
@ -37,14 +38,14 @@ trait AdvancedPropertyTrait
/**
* @var bool Determines if this part entry needs review (for example, because it is work in progress)
*/
#[Groups(['extended', 'full', 'import'])]
#[Groups(['extended', 'full', 'import', 'part:read', 'part:write'])]
#[ORM\Column(type: Types::BOOLEAN)]
protected bool $needs_review = false;
/**
* @var string a comma separated list of tags, associated with the part
*/
#[Groups(['extended', 'full', 'import'])]
#[Groups(['extended', 'full', 'import', 'part:read', 'part:write'])]
#[ORM\Column(type: Types::TEXT)]
protected string $tags = '';
@ -52,7 +53,7 @@ trait AdvancedPropertyTrait
* @var float|null how much a single part unit weighs in grams
*/
#[Assert\PositiveOrZero]
#[Groups(['extended', 'full', 'import'])]
#[Groups(['extended', 'full', 'import', 'part:read', 'part:write'])]
#[ORM\Column(type: Types::FLOAT, nullable: true)]
protected ?float $mass = null;
@ -60,14 +61,15 @@ trait AdvancedPropertyTrait
* @var string|null The internal part number of the part
*/
#[Assert\Length(max: 100)]
#[Groups(['extended', 'full', 'import'])]
#[ORM\Column(type: Types::STRING, length: 100, nullable: true, unique: true)]
#[Groups(['extended', 'full', 'import', 'part:read', 'part:write'])]
#[ORM\Column(type: Types::STRING, length: 100, unique: true, nullable: true)]
protected ?string $ipn = null;
/**
* @var InfoProviderReference The reference to the info provider, that provided the information about this part
*/
#[ORM\Embedded(class: InfoProviderReference::class, columnPrefix: 'provider_reference_')]
#[Groups(['full', 'part:read'])]
protected InfoProviderReference $providerReference;
/**

View file

@ -35,14 +35,14 @@ trait BasicPropertyTrait
/**
* @var string A text describing what this part does
*/
#[Groups(['simple', 'extended', 'full', 'import'])]
#[Groups(['simple', 'extended', 'full', 'import', 'part:read', 'part:write'])]
#[ORM\Column(type: Types::TEXT)]
protected string $description = '';
/**
* @var string A comment/note related to this part
*/
#[Groups(['extended', 'full', 'import'])]
#[Groups(['extended', 'full', 'import', 'part:read', 'part:write'])]
#[ORM\Column(type: Types::TEXT)]
protected string $comment = '';
@ -55,7 +55,7 @@ trait BasicPropertyTrait
/**
* @var bool true, if the part is marked as favorite
*/
#[Groups(['extended', 'full', 'import'])]
#[Groups(['extended', 'full', 'import', 'part:read', 'part:write'])]
#[ORM\Column(type: Types::BOOLEAN)]
protected bool $favorite = false;
@ -65,7 +65,7 @@ trait BasicPropertyTrait
*/
#[Assert\NotNull(message: 'validator.select_valid_category')]
#[Selectable()]
#[Groups(['simple', 'extended', 'full', 'import'])]
#[Groups(['simple', 'extended', 'full', 'import', "part:read", "part:write"])]
#[ORM\ManyToOne(targetEntity: Category::class)]
#[ORM\JoinColumn(name: 'id_category', nullable: false)]
protected ?Category $category = null;
@ -73,7 +73,7 @@ trait BasicPropertyTrait
/**
* @var Footprint|null The footprint of this part (e.g. DIP8)
*/
#[Groups(['simple', 'extended', 'full', 'import'])]
#[Groups(['simple', 'extended', 'full', 'import', 'part:read', 'part:write'])]
#[ORM\ManyToOne(targetEntity: Footprint::class)]
#[ORM\JoinColumn(name: 'id_footprint')]
#[Selectable()]

View file

@ -49,14 +49,14 @@ trait InstockTrait
* Given in the partUnit.
*/
#[Assert\PositiveOrZero]
#[Groups(['extended', 'full', 'import'])]
#[Groups(['extended', 'full', 'import', 'part:read', 'part:write'])]
#[ORM\Column(type: Types::FLOAT)]
protected float $minamount = 0;
/**
* @var ?MeasurementUnit the unit in which the part's amount is measured
*/
#[Groups(['extended', 'full', 'import'])]
#[Groups(['extended', 'full', 'import', 'part:read', 'part:write'])]
#[ORM\ManyToOne(targetEntity: MeasurementUnit::class)]
#[ORM\JoinColumn(name: 'id_part_unit')]
protected ?MeasurementUnit $partUnit = null;

View file

@ -39,7 +39,7 @@ trait ManufacturerTrait
/**
* @var Manufacturer|null The manufacturer of this part
*/
#[Groups(['simple', 'extended', 'full', 'import'])]
#[Groups(['simple', 'extended', 'full', 'import', 'part:read', 'part:write'])]
#[ORM\ManyToOne(targetEntity: Manufacturer::class)]
#[ORM\JoinColumn(name: 'id_manufacturer')]
#[Selectable()]
@ -49,21 +49,21 @@ trait ManufacturerTrait
* @var string the url to the part on the manufacturer's homepage
*/
#[Assert\Url]
#[Groups(['full', 'import'])]
#[Groups(['full', 'import', 'part:read', 'part:write'])]
#[ORM\Column(type: Types::TEXT)]
protected string $manufacturer_product_url = '';
/**
* @var string The product number used by the manufacturer. If this is set to "", the name field is used.
*/
#[Groups(['extended', 'full', 'import'])]
#[Groups(['extended', 'full', 'import', 'part:read', 'part:write'])]
#[ORM\Column(type: Types::STRING)]
protected string $manufacturer_product_number = '';
/**
* @var ManufacturingStatus|null The production status of this part. Can be one of the specified ones.
*/
#[Groups(['extended', 'full', 'import'])]
#[Groups(['extended', 'full', 'import', 'part:read', 'part:write'])]
#[ORM\Column(type: Types::STRING, length: 255, nullable: true, enumType: ManufacturingStatus::class)]
protected ?ManufacturingStatus $manufacturing_status = ManufacturingStatus::NOT_SET;

View file

@ -9,12 +9,10 @@ use App\Entity\ProjectSystem\ProjectBOMEntry;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
trait ProjectTrait
{
/**
* @var Collection<ProjectBOMEntry> $project_bom_entries
*/
/**
* @var Collection<ProjectBOMEntry> $project_bom_entries
*/
@ -42,6 +40,7 @@ trait ProjectTrait
* Checks whether this part represents the builds of a project
* @return bool True if it represents the builds, false if not
*/
#[Groups(['part:read'])]
public function isProjectBuildPart(): bool
{
return $this->built_project !== null;