Skip to content

Commit

Permalink
Merge branch 'master' into feature/product-variations
Browse files Browse the repository at this point in the history
  • Loading branch information
LodeAlaert committed Jul 10, 2024
2 parents 966b84f + 76132e5 commit dd6ca52
Show file tree
Hide file tree
Showing 38 changed files with 1,078 additions and 20 deletions.
11 changes: 6 additions & 5 deletions src/DataTransferObjects/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Esign\Plytix\DataTransferObjects;

use Esign\Plytix\DataTransferObjects\Casts\PlytixDateTimeCast;
use Illuminate\Support\Carbon;
use Spatie\LaravelData\Attributes\MapInputName;
use Spatie\LaravelData\Attributes\WithCast;
use Spatie\LaravelData\Casts\DateTimeInterfaceCast;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Mappers\SnakeCaseMapper;

Expand All @@ -28,9 +28,10 @@ public function __construct(
public readonly ?string $status,
public readonly ?string $thumbnail,
public readonly ?string $url,
#[WithCast(DateTimeInterfaceCast::class, format: 'Y-m-d\TH:i:s.uP')]
#[WithCast(PlytixDateTimeCast::class)]
public readonly ?Carbon $created,
#[WithCast(DateTimeInterfaceCast::class, format: 'Y-m-d\TH:i:s.uP')]
#[WithCast(PlytixDateTimeCast::class)]
public readonly ?Carbon $modified,
) {}
}
) {
}
}
26 changes: 26 additions & 0 deletions src/DataTransferObjects/Casts/PlytixDateTimeCast.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Esign\Plytix\DataTransferObjects\Casts;

use Spatie\LaravelData\Casts\DateTimeInterfaceCast;

class PlytixDateTimeCast extends DateTimeInterfaceCast
{
public const FORMATS = [
'Y-m-d\TH:i:s.uP',
'Y-m-d\TH:i:sP',
];

public function __construct(
?string $type = null,
?string $setTimeZone = null,
?string $timeZone = null
) {
parent::__construct(
format: static::FORMATS,
type: $type,
setTimeZone: $setTimeZone,
timeZone: $timeZone
);
}
}
6 changes: 3 additions & 3 deletions src/DataTransferObjects/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Esign\Plytix\DataTransferObjects;

use Esign\Plytix\DataTransferObjects\Casts\PlytixDateTimeCast;
use Illuminate\Support\Carbon;
use Spatie\LaravelData\Attributes\DataCollectionOf;
use Spatie\LaravelData\Attributes\MapInputName;
use Spatie\LaravelData\Attributes\WithCast;
use Spatie\LaravelData\Casts\DateTimeInterfaceCast;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Mappers\SnakeCaseMapper;

Expand All @@ -19,9 +19,9 @@ public function __construct(
public readonly ?string $label,
public readonly ?string $status,
public readonly ?int $numVariations,
#[WithCast(DateTimeInterfaceCast::class, format: 'Y-m-d\TH:i:s.uP')]
#[WithCast(PlytixDateTimeCast::class)]
public readonly ?Carbon $modified,
#[WithCast(DateTimeInterfaceCast::class, format: 'Y-m-d\TH:i:s.uP')]
#[WithCast(PlytixDateTimeCast::class)]
public readonly ?Carbon $created,
public readonly array $attributes,
#[DataCollectionOf(RelationshipInformation::class)]
Expand Down
20 changes: 20 additions & 0 deletions src/DataTransferObjects/ProductAttribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Esign\Plytix\DataTransferObjects;

use Spatie\LaravelData\Attributes\MapInputName;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Mappers\SnakeCaseMapper;

#[MapInputName(SnakeCaseMapper::class)]
class ProductAttribute extends Data
{
public function __construct(
public readonly string $id,
public readonly ?array $groups,
public readonly ?string $label,
public readonly ?string $name,
public readonly ?string $typeClass
) {
}
}
8 changes: 4 additions & 4 deletions src/DataTransferObjects/ProductCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

namespace Esign\Plytix\DataTransferObjects;

use DateTime;
use Esign\Plytix\DataTransferObjects\Casts\PlytixDateTimeCast;
use Illuminate\Support\Carbon;
use Spatie\LaravelData\Attributes\MapInputName;
use Spatie\LaravelData\Attributes\WithCast;
use Spatie\LaravelData\Casts\DateTimeInterfaceCast;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Mappers\SnakeCaseMapper;

Expand All @@ -15,13 +14,14 @@ class ProductCategory extends Data
{
public function __construct(
public readonly string $id,
#[WithCast(DateTimeInterfaceCast::class, format: 'Y-m-d\TH:i:s.uP')]
#[WithCast(PlytixDateTimeCast::class)]
public readonly ?Carbon $modified,
public readonly ?int $nChildren,
public readonly ?string $name,
public readonly ?string $order,
public readonly ?array $parentsIds,
public readonly ?array $path,
public readonly ?string $slug,
) {}
) {
}
}
6 changes: 3 additions & 3 deletions src/DataTransferObjects/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Esign\Plytix\DataTransferObjects;

use Esign\Plytix\DataTransferObjects\Casts\PlytixDateTimeCast;
use Illuminate\Support\Carbon;
use Spatie\LaravelData\Attributes\WithCast;
use Spatie\LaravelData\Casts\DateTimeInterfaceCast;
use Spatie\LaravelData\Data;

class Relationship extends Data
Expand All @@ -13,9 +13,9 @@ public function __construct(
public readonly string $id,
public readonly ?string $label,
public readonly ?string $name,
#[WithCast(DateTimeInterfaceCast::class, format: 'Y-m-d\TH:i:s.uP')]
#[WithCast(PlytixDateTimeCast::class)]
public readonly ?Carbon $created,
#[WithCast(DateTimeInterfaceCast::class, format: 'Y-m-d\TH:i:s.uP')]
#[WithCast(PlytixDateTimeCast::class)]
public readonly ?Carbon $modified,
) {
}
Expand Down
2 changes: 1 addition & 1 deletion src/Pagination/PagedPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Esign\Plytix\Pagination;

use LogicException;
use Saloon\Http\Response;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\PaginationPlugin\PagedPaginator as BasePagedPaginator;
use Saloon\Traits\Body\HasJsonBody;

Expand Down
3 changes: 1 addition & 2 deletions src/Plytix.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

namespace Esign\Plytix;

use Esign\Plytix\Pagination\PagedPaginator;
use Esign\Plytix\Enums\RateLimitingPlan;
use Esign\Plytix\Exceptions\InvalidConfigurationException;
use Esign\Plytix\Pagination\PagedPaginator;
use Esign\Plytix\Requests\TokenRequest;
use Illuminate\Support\Facades\Cache;
use Saloon\Contracts\Authenticator;
use Saloon\Http\Connector;
use Saloon\Http\Request;
use Saloon\PaginationPlugin\Contracts\HasPagination;
use Saloon\RateLimitPlugin\Contracts\RateLimitStore;
use Saloon\RateLimitPlugin\Limit;
use Saloon\RateLimitPlugin\Stores\LaravelCacheStore;
use Saloon\RateLimitPlugin\Traits\HasRateLimits;
use Saloon\Traits\Plugins\AlwaysThrowOnErrors;
Expand Down
41 changes: 41 additions & 0 deletions src/Requests/AssignProductsToRelationshipRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Esign\Plytix\Requests;

use Esign\Plytix\DataTransferObjects\RelationshipInformation;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;

class AssignProductsToRelationshipRequest extends Request implements HasBody
{
use HasJsonBody;

protected Method $method = Method::POST;

public function __construct(
protected string $productId,
protected string $relationshipId,
protected array $payload
) {
}

public function resolveEndpoint(): string
{
return '/api/v1/products/' . $this->productId . "/relationships/" . $this->relationshipId;
}

public function defaultBody(): array
{
return $this->payload;
}

public function createDtoFromResponse(Response $response): mixed
{
return array_map(function (array $relationshipInfo) {
return RelationshipInformation::from($relationshipInfo);
}, $response->json('data'));
}
}
38 changes: 38 additions & 0 deletions src/Requests/CreateAssetRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Esign\Plytix\Requests;

use Esign\Plytix\DataTransferObjects\Asset;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;

class CreateAssetRequest extends Request implements HasBody
{
use HasJsonBody;

protected Method $method = Method::POST;

public function __construct(protected array $payload)
{
}

public function resolveEndpoint(): string
{
return '/api/v1/assets';
}

public function defaultBody(): array
{
return $this->payload;
}

public function createDtoFromResponse(Response $response): mixed
{
return array_map(function (array $product) {
return Asset::from($product);
}, $response->json('data'));
}
}
38 changes: 38 additions & 0 deletions src/Requests/CreateProductAttributeRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Esign\Plytix\Requests;

use Esign\Plytix\DataTransferObjects\ProductAttribute;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;

class CreateProductAttributeRequest extends Request implements HasBody
{
use HasJsonBody;

protected Method $method = Method::POST;

public function __construct(protected array $payload)
{
}

public function resolveEndpoint(): string
{
return '/api/v1/attributes/product';
}

public function defaultBody(): array
{
return $this->payload;
}

public function createDtoFromResponse(Response $response): mixed
{
return array_map(function (array $attribute) {
return ProductAttribute::from($attribute);
}, $response->json('data'));
}
}
38 changes: 38 additions & 0 deletions src/Requests/CreateProductCategoryRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Esign\Plytix\Requests;

use Esign\Plytix\DataTransferObjects\ProductCategory;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;

class CreateProductCategoryRequest extends Request implements HasBody
{
use HasJsonBody;

protected Method $method = Method::POST;

public function __construct(protected array $payload)
{
}

public function resolveEndpoint(): string
{
return '/api/v1/categories/product';
}

public function defaultBody(): array
{
return $this->payload;
}

public function createDtoFromResponse(Response $response): mixed
{
return array_map(function (array $productCategory) {
return ProductCategory::from($productCategory);
}, $response->json('data'));
}
}
9 changes: 9 additions & 0 deletions src/Requests/CreateProductRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Esign\Plytix\Requests;

use Esign\Plytix\DataTransferObjects\Product;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;

class CreateProductRequest extends Request implements HasBody
Expand All @@ -26,4 +28,11 @@ public function defaultBody(): array
{
return $this->payload;
}

public function createDtoFromResponse(Response $response): mixed
{
return array_map(function (array $product) {
return Product::from($product);
}, $response->json('data'));
}
}
Loading

0 comments on commit dd6ca52

Please sign in to comment.