mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-29 21:14:29 +02:00
Added API endpoints for orderdetails and pricedetails
This commit is contained in:
parent
64db3ed965
commit
219fbe5fca
2 changed files with 63 additions and 9 deletions
|
@ -23,6 +23,15 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\PriceInformations;
|
||||
|
||||
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 Doctrine\DBAL\Types\Types;
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Base\TimestampTrait;
|
||||
|
@ -46,12 +55,35 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
#[ORM\HasLifecycleCallbacks]
|
||||
#[ORM\Table('`orderdetails`')]
|
||||
#[ORM\Index(name: 'orderdetails_supplier_part_nr', columns: ['supplierpartnr'])]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(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)'),
|
||||
new Delete(security: 'is_granted("delete", object)'),
|
||||
],
|
||||
normalizationContext: ['groups' => ['orderdetail:read', 'api:basic:read', 'pricedetail:read'], 'openapi_definition_name' => 'Read'],
|
||||
denormalizationContext: ['groups' => ['orderdetail:write', 'api:basic:write'], 'openapi_definition_name' => 'Write'],
|
||||
)]
|
||||
#[ApiResource(
|
||||
uriTemplate: '/parts/{id}/orderdetails.{_format}',
|
||||
operations: [
|
||||
new GetCollection(openapiContext: ['summary' => 'Retrieves the orderdetails of a part.'],
|
||||
security: 'is_granted("@parts.read")')
|
||||
],
|
||||
uriVariables: [
|
||||
'id' => new Link(toProperty: 'part', fromClass: Part::class)
|
||||
],
|
||||
normalizationContext: ['groups' => ['orderdetail:read', 'pricedetail:read', 'api:basic:read'], 'openapi_definition_name' => 'Read']
|
||||
)]
|
||||
#[ApiFilter(PropertyFilter::class)]
|
||||
class Orderdetail extends AbstractDBElement implements TimeStampableInterface, NamedElementInterface
|
||||
{
|
||||
use TimestampTrait;
|
||||
|
||||
#[Assert\Valid]
|
||||
#[Groups(['extended', 'full', 'import'])]
|
||||
#[Groups(['extended', 'full', 'import', 'orderdetail:read', 'orderdetail:write'])]
|
||||
#[ORM\OneToMany(targetEntity: Pricedetail::class, mappedBy: 'orderdetail', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['min_discount_quantity' => 'ASC'])]
|
||||
protected Collection $pricedetails;
|
||||
|
@ -59,14 +91,14 @@ class Orderdetail extends AbstractDBElement implements TimeStampableInterface, N
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
#[Groups(['extended', 'full', 'import'])]
|
||||
#[Groups(['extended', 'full', 'import', 'orderdetail:read', 'orderdetail:write'])]
|
||||
#[ORM\Column(type: Types::STRING)]
|
||||
protected string $supplierpartnr = '';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
#[Groups(['extended', 'full', 'import'])]
|
||||
#[Groups(['extended', 'full', 'import', 'orderdetail:read', 'orderdetail:write'])]
|
||||
#[ORM\Column(type: Types::BOOLEAN)]
|
||||
protected bool $obsolete = false;
|
||||
|
||||
|
@ -74,7 +106,7 @@ class Orderdetail extends AbstractDBElement implements TimeStampableInterface, N
|
|||
* @var string
|
||||
*/
|
||||
#[Assert\Url]
|
||||
#[Groups(['full', 'import'])]
|
||||
#[Groups(['full', 'import', 'orderdetail:read', 'orderdetail:write'])]
|
||||
#[ORM\Column(type: Types::TEXT)]
|
||||
protected string $supplier_product_url = '';
|
||||
|
||||
|
@ -83,6 +115,7 @@ class Orderdetail extends AbstractDBElement implements TimeStampableInterface, N
|
|||
*/
|
||||
#[Assert\NotNull]
|
||||
#[ORM\ManyToOne(targetEntity: Part::class, inversedBy: 'orderdetails')]
|
||||
#[Groups(['orderdetail:read', 'orderdetail:write'])]
|
||||
#[ORM\JoinColumn(name: 'part_id', nullable: false, onDelete: 'CASCADE')]
|
||||
protected ?Part $part = null;
|
||||
|
||||
|
@ -90,7 +123,7 @@ class Orderdetail extends AbstractDBElement implements TimeStampableInterface, N
|
|||
* @var Supplier|null
|
||||
*/
|
||||
#[Assert\NotNull(message: 'validator.orderdetail.supplier_must_not_be_null')]
|
||||
#[Groups(['extended', 'full', 'import'])]
|
||||
#[Groups(['extended', 'full', 'import', 'orderdetail:read', 'orderdetail:write'])]
|
||||
#[ORM\ManyToOne(targetEntity: Supplier::class, inversedBy: 'orderdetails')]
|
||||
#[ORM\JoinColumn(name: 'id_supplier')]
|
||||
protected ?Supplier $supplier = null;
|
||||
|
|
|
@ -22,6 +22,14 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\PriceInformations;
|
||||
|
||||
use ApiPlatform\Metadata\ApiFilter;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Delete;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use ApiPlatform\Metadata\Patch;
|
||||
use ApiPlatform\Metadata\Post;
|
||||
use ApiPlatform\Serializer\Filter\PropertyFilter;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Base\TimestampTrait;
|
||||
|
@ -45,6 +53,18 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
#[ORM\Table('`pricedetails`')]
|
||||
#[ORM\Index(name: 'pricedetails_idx_min_discount', columns: ['min_discount_quantity'])]
|
||||
#[ORM\Index(name: 'pricedetails_idx_min_discount_price_qty', columns: ['min_discount_quantity', 'price_related_quantity'])]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(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)'),
|
||||
new Delete(security: 'is_granted("delete", object)'),
|
||||
],
|
||||
normalizationContext: ['groups' => ['pricedetail:read', 'api:basic:read'], 'openapi_definition_name' => 'Read'],
|
||||
denormalizationContext: ['groups' => ['pricedetail:write', 'api:basic:write'], 'openapi_definition_name' => 'Write'],
|
||||
)]
|
||||
#[ApiFilter(PropertyFilter::class)]
|
||||
class Pricedetail extends AbstractDBElement implements TimeStampableInterface
|
||||
{
|
||||
use TimestampTrait;
|
||||
|
@ -54,7 +74,7 @@ class Pricedetail extends AbstractDBElement implements TimeStampableInterface
|
|||
/**
|
||||
* @var BigDecimal The price related to the detail. (Given in the selected currency)
|
||||
*/
|
||||
#[Groups(['extended', 'full'])]
|
||||
#[Groups(['extended', 'full', 'pricedetail:read', 'pricedetail:write'])]
|
||||
#[ORM\Column(type: 'big_decimal', precision: 11, scale: 5)]
|
||||
#[BigDecimalPositive()]
|
||||
protected BigDecimal $price;
|
||||
|
@ -63,7 +83,7 @@ class Pricedetail extends AbstractDBElement implements TimeStampableInterface
|
|||
* @var ?Currency The currency used for the current price information.
|
||||
* If this is null, the global base unit is assumed
|
||||
*/
|
||||
#[Groups(['extended', 'full', 'import'])]
|
||||
#[Groups(['extended', 'full', 'import', 'pricedetail:read', 'pricedetail:write'])]
|
||||
#[ORM\ManyToOne(targetEntity: Currency::class, inversedBy: 'pricedetails')]
|
||||
#[ORM\JoinColumn(name: 'id_currency')]
|
||||
#[Selectable()]
|
||||
|
@ -73,7 +93,7 @@ class Pricedetail extends AbstractDBElement implements TimeStampableInterface
|
|||
* @var float
|
||||
*/
|
||||
#[Assert\Positive]
|
||||
#[Groups(['extended', 'full', 'import'])]
|
||||
#[Groups(['extended', 'full', 'import', 'pricedetail:read', 'pricedetail:write'])]
|
||||
#[ORM\Column(type: Types::FLOAT)]
|
||||
protected float $price_related_quantity = 1.0;
|
||||
|
||||
|
@ -81,7 +101,7 @@ class Pricedetail extends AbstractDBElement implements TimeStampableInterface
|
|||
* @var float
|
||||
*/
|
||||
#[Assert\Positive]
|
||||
#[Groups(['extended', 'full', 'import'])]
|
||||
#[Groups(['extended', 'full', 'import', 'pricedetail:read', 'pricedetail:write'])]
|
||||
#[ORM\Column(type: Types::FLOAT)]
|
||||
protected float $min_discount_quantity = 1.0;
|
||||
|
||||
|
@ -97,6 +117,7 @@ class Pricedetail extends AbstractDBElement implements TimeStampableInterface
|
|||
#[Assert\NotNull]
|
||||
#[ORM\ManyToOne(targetEntity: Orderdetail::class, inversedBy: 'pricedetails')]
|
||||
#[ORM\JoinColumn(name: 'orderdetails_id', nullable: false, onDelete: 'CASCADE')]
|
||||
#[Groups(['pricedetail:read', 'pricedetail:write'])]
|
||||
protected ?Orderdetail $orderdetail = null;
|
||||
|
||||
public function __construct()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue