Renamed Storelocation entity to StorageLocation

This commit is contained in:
Jan Böhmer 2023-09-04 22:57:40 +02:00
parent 09acca950d
commit 0af5a58dbe
59 changed files with 218 additions and 176 deletions

View file

@ -22,6 +22,7 @@ declare(strict_types=1);
namespace App\Entity\Attachments;
use App\Entity\Parts\PartTraits\ProjectTrait;
use App\Repository\AttachmentRepository;
use App\EntityListeners\AttachmentDeleteListener;
use Doctrine\DBAL\Types\Types;
@ -42,7 +43,12 @@ use LogicException;
#[ORM\Entity(repositoryClass: AttachmentRepository::class)]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn(name: 'class_name', type: 'string')]
#[ORM\DiscriminatorMap(['PartDB\Part' => 'PartAttachment', 'Part' => 'PartAttachment', 'PartDB\Device' => 'ProjectAttachment', 'Device' => 'ProjectAttachment', 'AttachmentType' => 'AttachmentTypeAttachment', 'Category' => 'CategoryAttachment', 'Footprint' => 'FootprintAttachment', 'Manufacturer' => 'ManufacturerAttachment', 'Currency' => 'CurrencyAttachment', 'Group' => 'GroupAttachment', 'MeasurementUnit' => 'MeasurementUnitAttachment', 'Storelocation' => 'StorelocationAttachment', 'Supplier' => 'SupplierAttachment', 'User' => 'UserAttachment', 'LabelProfile' => 'LabelAttachment'])]
#[ORM\DiscriminatorMap(['PartDB\Part' => PartAttachment::class, 'Part' => PartAttachment::class,
'PartDB\Device' => ProjectAttachment::class, 'Device' => ProjectAttachment::class, 'AttachmentType' => AttachmentTypeAttachment::class,
'Category' => CategoryAttachment::class, 'Footprint' => FootprintAttachment::class, 'Manufacturer' => ManufacturerAttachment::class,
'Currency' => CurrencyAttachment::class, 'Group' => GroupAttachment::class, 'MeasurementUnit' => MeasurementUnitAttachment::class,
'Storelocation' => StorageLocationAttachment::class, 'Supplier' => SupplierAttachment::class,
'User' => UserAttachment::class, 'LabelProfile' => LabelAttachment::class])]
#[ORM\EntityListeners([AttachmentDeleteListener::class])]
#[ORM\Table(name: '`attachments`')]
#[ORM\Index(name: 'attachments_idx_id_element_id_class_name', columns: ['id', 'element_id', 'class_name'])]

View file

@ -22,24 +22,24 @@ declare(strict_types=1);
namespace App\Entity\Attachments;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\StorageLocation;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* An attachment attached to a measurement unit element.
* @extends Attachment<Storelocation>
* @extends Attachment<StorageLocation>
*/
#[UniqueEntity(['name', 'attachment_type', 'element'])]
#[ORM\Entity]
class StorelocationAttachment extends Attachment
class StorageLocationAttachment extends Attachment
{
final public const ALLOWED_ELEMENT_CLASS = Storelocation::class;
final public const ALLOWED_ELEMENT_CLASS = StorageLocation::class;
/**
* @var Storelocation|null the element this attachment is associated with
* @var StorageLocation|null the element this attachment is associated with
*/
#[ORM\ManyToOne(targetEntity: Storelocation::class, inversedBy: 'attachments')]
#[ORM\ManyToOne(targetEntity: StorageLocation::class, inversedBy: 'attachments')]
#[ORM\JoinColumn(name: 'element_id', nullable: false, onDelete: 'CASCADE')]
protected ?AttachmentContainingDBElement $element = null;
}

View file

@ -34,7 +34,7 @@ use App\Entity\Attachments\ManufacturerAttachment;
use App\Entity\Attachments\MeasurementUnitAttachment;
use App\Entity\Attachments\PartAttachment;
use App\Entity\Attachments\ProjectAttachment;
use App\Entity\Attachments\StorelocationAttachment;
use App\Entity\Attachments\StorageLocationAttachment;
use App\Entity\Attachments\SupplierAttachment;
use App\Entity\Attachments\UserAttachment;
use App\Entity\Parameters\AbstractParameter;
@ -46,7 +46,7 @@ use App\Entity\UserSystem\Group;
use App\Entity\Parts\Manufacturer;
use App\Entity\PriceInformations\Orderdetail;
use App\Entity\Parts\Part;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\StorageLocation;
use App\Entity\Parts\PartLot;
use App\Entity\PriceInformations\Currency;
use App\Entity\Parts\MeasurementUnit;
@ -67,7 +67,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
* Every database table which are managed with this class (or a subclass of it)
* must have the table row "id"!! The ID is the unique key to identify the elements.
*/
#[DiscriminatorMap(typeProperty: 'type', mapping: ['attachment_type' => AttachmentType::class, 'attachment' => Attachment::class, 'attachment_type_attachment' => AttachmentTypeAttachment::class, 'category_attachment' => CategoryAttachment::class, 'currency_attachment' => CurrencyAttachment::class, 'footprint_attachment' => FootprintAttachment::class, 'group_attachment' => GroupAttachment::class, 'label_attachment' => LabelAttachment::class, 'manufacturer_attachment' => ManufacturerAttachment::class, 'measurement_unit_attachment' => MeasurementUnitAttachment::class, 'part_attachment' => PartAttachment::class, 'project_attachment' => ProjectAttachment::class, 'storelocation_attachment' => StorelocationAttachment::class, 'supplier_attachment' => SupplierAttachment::class, 'user_attachment' => UserAttachment::class, 'category' => Category::class, 'project' => Project::class, 'project_bom_entry' => ProjectBOMEntry::class, 'footprint' => Footprint::class, 'group' => Group::class, 'manufacturer' => Manufacturer::class, 'orderdetail' => Orderdetail::class, 'part' => Part::class, 'pricedetail' => 'App\Entity\PriceInformation\Pricedetail', 'storelocation' => Storelocation::class, 'part_lot' => PartLot::class, 'currency' => Currency::class, 'measurement_unit' => MeasurementUnit::class, 'parameter' => AbstractParameter::class, 'supplier' => Supplier::class, 'user' => User::class])]
#[DiscriminatorMap(typeProperty: 'type', mapping: ['attachment_type' => AttachmentType::class, 'attachment' => Attachment::class, 'attachment_type_attachment' => AttachmentTypeAttachment::class, 'category_attachment' => CategoryAttachment::class, 'currency_attachment' => CurrencyAttachment::class, 'footprint_attachment' => FootprintAttachment::class, 'group_attachment' => GroupAttachment::class, 'label_attachment' => LabelAttachment::class, 'manufacturer_attachment' => ManufacturerAttachment::class, 'measurement_unit_attachment' => MeasurementUnitAttachment::class, 'part_attachment' => PartAttachment::class, 'project_attachment' => ProjectAttachment::class, 'storelocation_attachment' => StorageLocationAttachment::class, 'supplier_attachment' => SupplierAttachment::class, 'user_attachment' => UserAttachment::class, 'category' => Category::class, 'project' => Project::class, 'project_bom_entry' => ProjectBOMEntry::class, 'footprint' => Footprint::class, 'group' => Group::class, 'manufacturer' => Manufacturer::class, 'orderdetail' => Orderdetail::class, 'part' => Part::class, 'pricedetail' => 'App\Entity\PriceInformation\Pricedetail', 'storelocation' => StorageLocation::class, 'part_lot' => PartLot::class, 'currency' => Currency::class, 'measurement_unit' => MeasurementUnit::class, 'parameter' => AbstractParameter::class, 'supplier' => Supplier::class, 'user' => User::class])]
#[ORM\MappedSuperclass(repositoryClass: DBElementRepository::class)]
abstract class AbstractDBElement implements JsonSerializable
{

View file

@ -22,7 +22,7 @@ namespace App\Entity\LabelSystem;
use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\StorageLocation;
enum LabelSupportedElement: string
{
@ -39,7 +39,7 @@ enum LabelSupportedElement: string
return match ($this) {
self::PART => Part::class,
self::PART_LOT => PartLot::class,
self::STORELOCATION => Storelocation::class,
self::STORELOCATION => StorageLocation::class,
};
}
}

View file

@ -36,7 +36,7 @@ use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\StorageLocation;
use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use App\Entity\PriceInformations\Orderdetail;

View file

@ -52,7 +52,7 @@ use App\Entity\Attachments\GroupAttachment;
use App\Entity\Attachments\ManufacturerAttachment;
use App\Entity\Attachments\MeasurementUnitAttachment;
use App\Entity\Attachments\PartAttachment;
use App\Entity\Attachments\StorelocationAttachment;
use App\Entity\Attachments\StorageLocationAttachment;
use App\Entity\Attachments\SupplierAttachment;
use App\Entity\Attachments\UserAttachment;
use App\Entity\Base\AbstractDBElement;
@ -69,14 +69,14 @@ use App\Entity\Parameters\GroupParameter;
use App\Entity\Parameters\ManufacturerParameter;
use App\Entity\Parameters\MeasurementUnitParameter;
use App\Entity\Parameters\PartParameter;
use App\Entity\Parameters\StorelocationParameter;
use App\Entity\Parameters\StorageLocationParameter;
use App\Entity\Parameters\SupplierParameter;
use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\StorageLocation;
use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use App\Entity\UserSystem\Group;
@ -166,8 +166,8 @@ class CollectionElementDeleted extends AbstractLogEntry implements LogWithEventU
return MeasurementUnitParameter::class;
case Part::class:
return PartParameter::class;
case Storelocation::class:
return StorelocationParameter::class;
case StorageLocation::class:
return StorageLocationParameter::class;
case Supplier::class:
return SupplierParameter::class;
@ -196,8 +196,8 @@ class CollectionElementDeleted extends AbstractLogEntry implements LogWithEventU
return MeasurementUnitAttachment::class;
case Part::class:
return PartAttachment::class;
case Storelocation::class:
return StorelocationAttachment::class;
case StorageLocation::class:
return StorageLocationAttachment::class;
case Supplier::class:
return SupplierAttachment::class;
case User::class:

View file

@ -30,7 +30,7 @@ use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\StorageLocation;
use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use App\Entity\PriceInformations\Orderdetail;
@ -81,7 +81,7 @@ enum LogTargetType: int
self::GROUP => Group::class,
self::MANUFACTURER => Manufacturer::class,
self::PART => Part::class,
self::STORELOCATION => Storelocation::class,
self::STORELOCATION => StorageLocation::class,
self::SUPPLIER => Supplier::class,
self::PART_LOT => PartLot::class,
self::CURRENCY => Currency::class,

View file

@ -41,6 +41,7 @@ declare(strict_types=1);
namespace App\Entity\Parameters;
use App\Entity\Attachments\AttachmentTypeAttachment;
use App\Repository\ParameterRepository;
use Doctrine\DBAL\Types\Types;
use App\Entity\Base\AbstractDBElement;
@ -56,7 +57,10 @@ use function sprintf;
#[ORM\Entity(repositoryClass: ParameterRepository::class)]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn(name: 'type', type: 'smallint')]
#[ORM\DiscriminatorMap([0 => 'CategoryParameter', 1 => 'CurrencyParameter', 2 => 'ProjectParameter', 3 => 'FootprintParameter', 4 => 'GroupParameter', 5 => 'ManufacturerParameter', 6 => 'MeasurementUnitParameter', 7 => 'PartParameter', 8 => 'StorelocationParameter', 9 => 'SupplierParameter', 10 => 'AttachmentTypeParameter'])]
#[ORM\DiscriminatorMap([0 => CategoryParameter::class, 1 => CurrencyParameter::class, 2 => ProjectParameter::class,
3 => FootprintParameter::class, 4 => GroupParameter::class, 5 => ManufacturerParameter::class,
6 => MeasurementUnitParameter::class, 7 => PartParameter::class, 8 => StorageLocationParameter::class,
9 => SupplierParameter::class, 10 => AttachmentTypeAttachment::class])]
#[ORM\Table('parameters')]
#[ORM\Index(name: 'parameter_name_idx', columns: ['name'])]
#[ORM\Index(name: 'parameter_group_idx', columns: ['param_group'])]

View file

@ -43,20 +43,20 @@ namespace App\Entity\Parameters;
use App\Repository\ParameterRepository;
use App\Entity\Base\AbstractDBElement;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\StorageLocation;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
#[UniqueEntity(fields: ['name', 'group', 'element'])]
#[ORM\Entity(repositoryClass: ParameterRepository::class)]
class StorelocationParameter extends AbstractParameter
class StorageLocationParameter extends AbstractParameter
{
final public const ALLOWED_ELEMENT_CLASS = Storelocation::class;
final public const ALLOWED_ELEMENT_CLASS = StorageLocation::class;
/**
* @var Storelocation the element this para is associated with
* @var StorageLocation the element this para is associated with
*/
#[ORM\ManyToOne(targetEntity: Storelocation::class, inversedBy: 'parameters')]
#[ORM\ManyToOne(targetEntity: StorageLocation::class, inversedBy: 'parameters')]
#[ORM\JoinColumn(name: 'element_id', nullable: false, onDelete: 'CASCADE')]
protected ?AbstractDBElement $element = null;
}

View file

@ -97,13 +97,13 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
protected ?\DateTimeInterface $expiration_date = null;
/**
* @var Storelocation|null The storelocation of this lot
* @var StorageLocation|null The storelocation of this lot
*/
#[Groups(['simple', 'extended', 'full', 'import', 'part_lot:read', 'part_lot:write'])]
#[ORM\ManyToOne(targetEntity: Storelocation::class, fetch: 'EAGER')]
#[ORM\ManyToOne(targetEntity: StorageLocation::class, fetch: 'EAGER')]
#[ORM\JoinColumn(name: 'id_store_location')]
#[Selectable()]
protected ?Storelocation $storage_location = null;
protected ?StorageLocation $storage_location = null;
/**
* @var bool If this is set to true, the instock amount is marked as not known
@ -229,9 +229,9 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
/**
* Gets the storage location, where this part lot is stored.
*
* @return Storelocation|null The store location where this part is stored
* @return StorageLocation|null The store location where this part is stored
*/
public function getStorageLocation(): ?Storelocation
public function getStorageLocation(): ?StorageLocation
{
return $this->storage_location;
}
@ -239,7 +239,7 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
/**
* Sets the storage location, where this part lot is stored.
*/
public function setStorageLocation(?Storelocation $storage_location): self
public function setStorageLocation(?StorageLocation $storage_location): self
{
$this->storage_location = $storage_location;

View file

@ -22,14 +22,23 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Link;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Serializer\Filter\PropertyFilter;
use App\Entity\Attachments\Attachment;
use App\Repository\Parts\StorelocationRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Attachments\StorelocationAttachment;
use App\Entity\Attachments\StorageLocationAttachment;
use App\Entity\Base\AbstractPartsContainingDBElement;
use App\Entity\Base\AbstractStructuralDBElement;
use App\Entity\Parameters\StorelocationParameter;
use App\Entity\Parameters\StorageLocationParameter;
use App\Entity\UserSystem\User;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
@ -38,13 +47,36 @@ use Symfony\Component\Validator\Constraints as Assert;
/**
* This entity represents a storage location, where parts can be stored.
* @extends AbstractPartsContainingDBElement<StorelocationAttachment, StorelocationParameter>
* @extends AbstractPartsContainingDBElement<StorageLocationAttachment, StorageLocationParameter>
*/
#[ORM\Entity(repositoryClass: StorelocationRepository::class)]
#[ORM\Table('`storelocations`')]
#[ORM\Index(name: 'location_idx_name', columns: ['name'])]
#[ORM\Index(name: 'location_idx_parent_name', columns: ['parent_id', 'name'])]
class Storelocation extends AbstractPartsContainingDBElement
#[ApiResource(
operations: [
new Get(security: 'is_granted("read", object)'),
new GetCollection(security: 'is_granted("@storelocations.read")'),
new Post(securityPostDenormalize: 'is_granted("create", object)'),
new Patch(security: 'is_granted("edit", object)'),
new Delete(security: 'is_granted("delete", object)'),
],
normalizationContext: ['groups' => ['location:read', 'api:basic:read'], 'openapi_definition_name' => 'Read'],
denormalizationContext: ['groups' => ['location:write', 'api:basic:write'], 'openapi_definition_name' => 'Write'],
)]
#[ApiResource(
uriTemplate: '/storage_locations/{id}/children.{_format}',
operations: [
new GetCollection(openapiContext: ['summary' => 'Retrieves the children elements of a storage location.'],
security: 'is_granted("@storelocations.read")')
],
uriVariables: [
'id' => new Link(fromProperty: 'children', fromClass: Manufacturer::class)
],
normalizationContext: ['groups' => ['location:read', 'api:basic:read'], 'openapi_definition_name' => 'Read']
)]
#[ApiFilter(PropertyFilter::class)]
class StorageLocation extends AbstractPartsContainingDBElement
{
#[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')]
#[ORM\OrderBy(['name' => 'ASC'])]
@ -61,10 +93,10 @@ class Storelocation extends AbstractPartsContainingDBElement
#[ORM\JoinColumn(name: 'storage_type_id')]
protected ?MeasurementUnit $storage_type = null;
/** @var Collection<int, StorelocationParameter>
/** @var Collection<int, StorageLocationParameter>
*/
#[Assert\Valid]
#[ORM\OneToMany(targetEntity: StorelocationParameter::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
#[ORM\OneToMany(targetEntity: StorageLocationParameter::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
#[ORM\OrderBy(['group' => 'ASC', 'name' => 'ASC'])]
protected Collection $parameters;
@ -104,13 +136,13 @@ class Storelocation extends AbstractPartsContainingDBElement
protected bool $part_owner_must_match = false;
/**
* @var Collection<int, StorelocationAttachment>
* @var Collection<int, StorageLocationAttachment>
*/
#[Assert\Valid]
#[ORM\OneToMany(targetEntity: StorelocationAttachment::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
#[ORM\OneToMany(targetEntity: StorageLocationAttachment::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
protected Collection $attachments;
#[ORM\ManyToOne(targetEntity: StorelocationAttachment::class)]
#[ORM\ManyToOne(targetEntity: StorageLocationAttachment::class)]
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
protected ?Attachment $master_picture_attachment = null;
@ -186,7 +218,7 @@ class Storelocation extends AbstractPartsContainingDBElement
/**
* Sets the owner of this storage location
*/
public function setOwner(?User $owner): Storelocation
public function setOwner(?User $owner): StorageLocation
{
$this->owner = $owner;
return $this;
@ -203,7 +235,7 @@ class Storelocation extends AbstractPartsContainingDBElement
/**
* If this is set to true, only parts lots, which are owned by the same user as the store location are allowed to be stored here.
*/
public function setPartOwnerMustMatch(bool $part_owner_must_match): Storelocation
public function setPartOwnerMustMatch(bool $part_owner_must_match): StorageLocation
{
$this->part_owner_must_match = $part_owner_must_match;
return $this;