mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Show attachments and preview image in API response
This commit is contained in:
parent
1823bc6528
commit
87e881f8e0
7 changed files with 18 additions and 14 deletions
|
@ -5,6 +5,9 @@ api_platform:
|
||||||
|
|
||||||
version: '0.1.0'
|
version: '0.1.0'
|
||||||
|
|
||||||
|
# eager_loading:
|
||||||
|
# max_joins: 100
|
||||||
|
|
||||||
swagger:
|
swagger:
|
||||||
api_keys:
|
api_keys:
|
||||||
# overridden in OpenApiFactoryDecorator
|
# overridden in OpenApiFactoryDecorator
|
||||||
|
|
|
@ -62,7 +62,6 @@ use LogicException;
|
||||||
#[ORM\Index(name: 'attachments_idx_class_name_id', columns: ['class_name', 'id'])]
|
#[ORM\Index(name: 'attachments_idx_class_name_id', columns: ['class_name', 'id'])]
|
||||||
#[ORM\Index(name: 'attachment_name_idx', columns: ['name'])]
|
#[ORM\Index(name: 'attachment_name_idx', columns: ['name'])]
|
||||||
#[ORM\Index(name: 'attachment_element_idx', columns: ['class_name', 'element_id'])]
|
#[ORM\Index(name: 'attachment_element_idx', columns: ['class_name', 'element_id'])]
|
||||||
|
|
||||||
#[ApiResource(
|
#[ApiResource(
|
||||||
operations: [
|
operations: [
|
||||||
new Get(security: 'is_granted("read", object)'),
|
new Get(security: 'is_granted("read", object)'),
|
||||||
|
@ -128,7 +127,7 @@ abstract class Attachment extends AbstractNamedDBElement
|
||||||
* ORM mapping is done in subclasses (like PartAttachment).
|
* ORM mapping is done in subclasses (like PartAttachment).
|
||||||
* @phpstan-param T|null $element
|
* @phpstan-param T|null $element
|
||||||
*/
|
*/
|
||||||
#[Groups(['attachment:read:standalone', 'attachment:read'])]
|
#[Groups(['attachment:read:standalone', 'attachment:write'])]
|
||||||
protected ?AttachmentContainingDBElement $element = null;
|
protected ?AttachmentContainingDBElement $element = null;
|
||||||
|
|
||||||
#[ORM\Column(type: Types::BOOLEAN)]
|
#[ORM\Column(type: Types::BOOLEAN)]
|
||||||
|
|
|
@ -152,14 +152,14 @@ class Category extends AbstractPartsContainingDBElement
|
||||||
* @var Collection<int, CategoryAttachment>
|
* @var Collection<int, CategoryAttachment>
|
||||||
*/
|
*/
|
||||||
#[Assert\Valid]
|
#[Assert\Valid]
|
||||||
#[Groups(['full', 'category:read'])]
|
#[Groups(['full', 'category:read', 'category:write'])]
|
||||||
#[ORM\OneToMany(targetEntity: CategoryAttachment::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
#[ORM\OneToMany(targetEntity: CategoryAttachment::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||||
protected Collection $attachments;
|
protected Collection $attachments;
|
||||||
|
|
||||||
#[ORM\ManyToOne(targetEntity: CategoryAttachment::class)]
|
#[ORM\ManyToOne(targetEntity: CategoryAttachment::class)]
|
||||||
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
|
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
|
||||||
#[Groups(['category:read'])]
|
#[Groups(['category:read', 'category:write'])]
|
||||||
protected ?Attachment $master_picture_attachment = null;
|
protected ?Attachment $master_picture_attachment = null;
|
||||||
|
|
||||||
/** @var Collection<int, CategoryParameter>
|
/** @var Collection<int, CategoryParameter>
|
||||||
|
|
|
@ -98,12 +98,12 @@ class Footprint extends AbstractPartsContainingDBElement
|
||||||
#[Assert\Valid]
|
#[Assert\Valid]
|
||||||
#[ORM\OneToMany(targetEntity: FootprintAttachment::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
#[ORM\OneToMany(targetEntity: FootprintAttachment::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||||
#[Groups(['footprint:read'])]
|
#[Groups(['footprint:read', 'footprint:write'])]
|
||||||
protected Collection $attachments;
|
protected Collection $attachments;
|
||||||
|
|
||||||
#[ORM\ManyToOne(targetEntity: FootprintAttachment::class)]
|
#[ORM\ManyToOne(targetEntity: FootprintAttachment::class)]
|
||||||
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
|
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
|
||||||
#[Groups(['footprint:read'])]
|
#[Groups(['footprint:read', 'footprint:write'])]
|
||||||
protected ?Attachment $master_picture_attachment = null;
|
protected ?Attachment $master_picture_attachment = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -111,7 +111,7 @@ class Footprint extends AbstractPartsContainingDBElement
|
||||||
*/
|
*/
|
||||||
#[ORM\ManyToOne(targetEntity: FootprintAttachment::class)]
|
#[ORM\ManyToOne(targetEntity: FootprintAttachment::class)]
|
||||||
#[ORM\JoinColumn(name: 'id_footprint_3d')]
|
#[ORM\JoinColumn(name: 'id_footprint_3d')]
|
||||||
#[Groups(['footprint:read'])]
|
#[Groups(['footprint:read', 'footprint:write'])]
|
||||||
protected ?FootprintAttachment $footprint_3d = null;
|
protected ?FootprintAttachment $footprint_3d = null;
|
||||||
|
|
||||||
/** @var Collection<int, FootprintParameter>
|
/** @var Collection<int, FootprintParameter>
|
||||||
|
|
|
@ -128,12 +128,12 @@ class MeasurementUnit extends AbstractPartsContainingDBElement
|
||||||
#[Assert\Valid]
|
#[Assert\Valid]
|
||||||
#[ORM\OneToMany(targetEntity: MeasurementUnitAttachment::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
#[ORM\OneToMany(targetEntity: MeasurementUnitAttachment::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||||
#[Groups(['measurement_unit:read'])]
|
#[Groups(['measurement_unit:read', 'measurement_unit:write'])]
|
||||||
protected Collection $attachments;
|
protected Collection $attachments;
|
||||||
|
|
||||||
#[ORM\ManyToOne(targetEntity: MeasurementUnitAttachment::class)]
|
#[ORM\ManyToOne(targetEntity: MeasurementUnitAttachment::class)]
|
||||||
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
|
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
|
||||||
#[Groups(['measurement_unit:read'])]
|
#[Groups(['measurement_unit:read', 'measurement_unit:write'])]
|
||||||
protected ?Attachment $master_picture_attachment = null;
|
protected ?Attachment $master_picture_attachment = null;
|
||||||
|
|
||||||
/** @var Collection<int, MeasurementUnitParameter>
|
/** @var Collection<int, MeasurementUnitParameter>
|
||||||
|
|
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||||
namespace App\Entity\Parts;
|
namespace App\Entity\Parts;
|
||||||
|
|
||||||
use ApiPlatform\Metadata\ApiFilter;
|
use ApiPlatform\Metadata\ApiFilter;
|
||||||
|
use ApiPlatform\Metadata\ApiProperty;
|
||||||
use ApiPlatform\Metadata\ApiResource;
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
use ApiPlatform\Metadata\Delete;
|
use ApiPlatform\Metadata\Delete;
|
||||||
use ApiPlatform\Metadata\Get;
|
use ApiPlatform\Metadata\Get;
|
||||||
|
@ -71,7 +72,8 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||||
#[ORM\Index(name: 'parts_idx_ipn', columns: ['ipn'])]
|
#[ORM\Index(name: 'parts_idx_ipn', columns: ['ipn'])]
|
||||||
#[ApiResource(
|
#[ApiResource(
|
||||||
operations: [
|
operations: [
|
||||||
new Get(normalizationContext: ['groups' => ['part:read', 'provider_reference:read', 'api:basic:read', 'part_lot:read', 'orderdetail:read', 'pricedetail:read']], security: 'is_granted("read", object)'),
|
new Get(normalizationContext: ['groups' => ['part:read', 'provider_reference:read', 'api:basic:read', 'part_lot:read',
|
||||||
|
'orderdetail:read', 'pricedetail:read', 'attachment:read']], security: 'is_granted("read", object)'),
|
||||||
new GetCollection(security: 'is_granted("@parts.read")'),
|
new GetCollection(security: 'is_granted("@parts.read")'),
|
||||||
new Post(securityPostDenormalize: 'is_granted("create", object)'),
|
new Post(securityPostDenormalize: 'is_granted("create", object)'),
|
||||||
new Patch(security: 'is_granted("edit", object)'),
|
new Patch(security: 'is_granted("edit", object)'),
|
||||||
|
@ -115,7 +117,7 @@ class Part extends AttachmentContainingDBElement
|
||||||
* @var Collection<int, PartAttachment>
|
* @var Collection<int, PartAttachment>
|
||||||
*/
|
*/
|
||||||
#[Assert\Valid]
|
#[Assert\Valid]
|
||||||
#[Groups(['full'])]
|
#[Groups(['full', 'part:read', 'part:write'])]
|
||||||
#[ORM\OneToMany(targetEntity: PartAttachment::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
#[ORM\OneToMany(targetEntity: PartAttachment::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||||
protected Collection $attachments;
|
protected Collection $attachments;
|
||||||
|
@ -126,6 +128,7 @@ class Part extends AttachmentContainingDBElement
|
||||||
#[Assert\Expression('value == null or value.isPicture()', message: 'part.master_attachment.must_be_picture')]
|
#[Assert\Expression('value == null or value.isPicture()', message: 'part.master_attachment.must_be_picture')]
|
||||||
#[ORM\ManyToOne(targetEntity: PartAttachment::class)]
|
#[ORM\ManyToOne(targetEntity: PartAttachment::class)]
|
||||||
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
|
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
|
||||||
|
#[Groups(['part:read', 'part:write'])]
|
||||||
protected ?Attachment $master_picture_attachment = null;
|
protected ?Attachment $master_picture_attachment = null;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
|
|
|
@ -253,13 +253,12 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
||||||
*/
|
*/
|
||||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: UserAttachment::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
#[ORM\OneToMany(mappedBy: 'element', targetEntity: UserAttachment::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||||
#[Groups(['user:read'])]
|
#[Groups(['user:read', 'user:write'])]
|
||||||
#[ApiProperty(readableLink: false, writableLink: false)]
|
|
||||||
protected Collection $attachments;
|
protected Collection $attachments;
|
||||||
|
|
||||||
#[ORM\ManyToOne(targetEntity: UserAttachment::class)]
|
#[ORM\ManyToOne(targetEntity: UserAttachment::class)]
|
||||||
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
|
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
|
||||||
#[Groups(['user:read'])]
|
#[Groups(['user:read', 'usser:write'])]
|
||||||
protected ?Attachment $master_picture_attachment = null;
|
protected ?Attachment $master_picture_attachment = null;
|
||||||
|
|
||||||
/** @var \DateTimeInterface|null The time when the backup codes were generated
|
/** @var \DateTimeInterface|null The time when the backup codes were generated
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue