mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-14 20:35:08 +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
|
@ -152,14 +152,14 @@ class Category extends AbstractPartsContainingDBElement
|
|||
* @var Collection<int, CategoryAttachment>
|
||||
*/
|
||||
#[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\OrderBy(['name' => 'ASC'])]
|
||||
protected Collection $attachments;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: CategoryAttachment::class)]
|
||||
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
|
||||
#[Groups(['category:read'])]
|
||||
#[Groups(['category:read', 'category:write'])]
|
||||
protected ?Attachment $master_picture_attachment = null;
|
||||
|
||||
/** @var Collection<int, CategoryParameter>
|
||||
|
|
|
@ -98,12 +98,12 @@ class Footprint extends AbstractPartsContainingDBElement
|
|||
#[Assert\Valid]
|
||||
#[ORM\OneToMany(targetEntity: FootprintAttachment::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[Groups(['footprint:read'])]
|
||||
#[Groups(['footprint:read', 'footprint:write'])]
|
||||
protected Collection $attachments;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: FootprintAttachment::class)]
|
||||
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
|
||||
#[Groups(['footprint:read'])]
|
||||
#[Groups(['footprint:read', 'footprint:write'])]
|
||||
protected ?Attachment $master_picture_attachment = null;
|
||||
|
||||
/**
|
||||
|
@ -111,7 +111,7 @@ class Footprint extends AbstractPartsContainingDBElement
|
|||
*/
|
||||
#[ORM\ManyToOne(targetEntity: FootprintAttachment::class)]
|
||||
#[ORM\JoinColumn(name: 'id_footprint_3d')]
|
||||
#[Groups(['footprint:read'])]
|
||||
#[Groups(['footprint:read', 'footprint:write'])]
|
||||
protected ?FootprintAttachment $footprint_3d = null;
|
||||
|
||||
/** @var Collection<int, FootprintParameter>
|
||||
|
|
|
@ -128,12 +128,12 @@ class MeasurementUnit extends AbstractPartsContainingDBElement
|
|||
#[Assert\Valid]
|
||||
#[ORM\OneToMany(targetEntity: MeasurementUnitAttachment::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[Groups(['measurement_unit:read'])]
|
||||
#[Groups(['measurement_unit:read', 'measurement_unit:write'])]
|
||||
protected Collection $attachments;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: MeasurementUnitAttachment::class)]
|
||||
#[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;
|
||||
|
||||
/** @var Collection<int, MeasurementUnitParameter>
|
||||
|
|
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||
namespace App\Entity\Parts;
|
||||
|
||||
use ApiPlatform\Metadata\ApiFilter;
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Delete;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
|
@ -71,7 +72,8 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
|||
#[ORM\Index(name: 'parts_idx_ipn', columns: ['ipn'])]
|
||||
#[ApiResource(
|
||||
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 Post(securityPostDenormalize: 'is_granted("create", object)'),
|
||||
new Patch(security: 'is_granted("edit", object)'),
|
||||
|
@ -115,7 +117,7 @@ class Part extends AttachmentContainingDBElement
|
|||
* @var Collection<int, PartAttachment>
|
||||
*/
|
||||
#[Assert\Valid]
|
||||
#[Groups(['full'])]
|
||||
#[Groups(['full', 'part:read', 'part:write'])]
|
||||
#[ORM\OneToMany(targetEntity: PartAttachment::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
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')]
|
||||
#[ORM\ManyToOne(targetEntity: PartAttachment::class)]
|
||||
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
|
||||
#[Groups(['part:read', 'part:write'])]
|
||||
protected ?Attachment $master_picture_attachment = null;
|
||||
|
||||
public function __construct()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue