Skip to content

Commit

Permalink
Merge pull request #105 from heseya/feature/SK-923
Browse files Browse the repository at this point in the history
Fix phone in address
  • Loading branch information
daVitekPL authored Dec 12, 2024
2 parents ea533a9 + 5090e88 commit 4759ce0
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 8 deletions.
42 changes: 42 additions & 0 deletions src/Domain/Manufacturer/Dtos/ManufacturerAddressStoreDto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Domain\Manufacturer\Dtos;

use Spatie\LaravelData\Attributes\Validation\Max;
use Spatie\LaravelData\Attributes\Validation\Nullable;
use Spatie\LaravelData\Attributes\Validation\Required;
use Spatie\LaravelData\Attributes\Validation\StringType;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Optional;
use Spatie\LaravelData\Support\Validation\ValidationContext;

final class ManufacturerAddressStoreDto extends Data
{
public function __construct(
public string $name,
#[Required, StringType, Max(255)]
public string $address,
#[Nullable, StringType, Max(20)]
public Optional|string $phone,
#[Required, StringType, Max(16)]
public string $zip,
#[Required, StringType, Max(255)]
public string $city,
#[Required, StringType, Max(2)]
public string $country,
#[Nullable, StringType, Max(15)]
public Optional|string|null $vat,
) {}

/**
* @return array<string,array<int,mixed>>
*/
public static function rules(ValidationContext $context): array
{
return [
'name' => ['required', 'string', 'max:255'],
];
}
}
41 changes: 41 additions & 0 deletions src/Domain/Manufacturer/Dtos/ManufacturerAddressUpdateDto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Domain\Manufacturer\Dtos;

use Spatie\LaravelData\Attributes\Validation\Max;
use Spatie\LaravelData\Attributes\Validation\Nullable;
use Spatie\LaravelData\Attributes\Validation\StringType;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Optional;
use Spatie\LaravelData\Support\Validation\ValidationContext;

final class ManufacturerAddressUpdateDto extends Data
{
public function __construct(
public string $name,
#[StringType, Max(255)]
public string $address,
#[StringType, Max(20)]
public Optional|string $phone,
#[StringType, Max(16)]
public string $zip,
#[StringType, Max(255)]
public string $city,
#[StringType, Max(2)]
public string $country,
#[Nullable, StringType, Max(15)]
public Optional|string|null $vat,
) {}

/**
* @return array<string,array<int,mixed>>
*/
public static function rules(ValidationContext $context): array
{
return [
'name' => ['string', 'max:255'],
];
}
}
3 changes: 1 addition & 2 deletions src/Domain/Manufacturer/Dtos/ManufacturerCreateDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Domain\Manufacturer\Dtos;

use Domain\User\Dtos\AddressStoreDto;
use Spatie\LaravelData\Attributes\Validation\Email;
use Spatie\LaravelData\Attributes\Validation\Max;
use Spatie\LaravelData\Data;
Expand All @@ -22,7 +21,7 @@ public function __construct(
public readonly Optional|string|null $last_name,
#[Email, Max(255)]
public readonly string $email,
public readonly AddressStoreDto $address,
public readonly ManufacturerAddressStoreDto $address,
public readonly array|Optional $product_ids,
) {}

Expand Down
3 changes: 1 addition & 2 deletions src/Domain/Manufacturer/Dtos/ManufacturerUpdateDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Domain\Manufacturer\Dtos;

use Domain\User\Dtos\AddressUpdateDto;
use Spatie\LaravelData\Attributes\Validation\Email;
use Spatie\LaravelData\Attributes\Validation\Max;
use Spatie\LaravelData\Attributes\Validation\RequiredWithout;
Expand All @@ -25,7 +24,7 @@ public function __construct(
public readonly Optional|string|null $last_name,
#[Email, Max(255)]
public readonly Optional|string $email,
public readonly AddressUpdateDto|Optional $address,
public readonly ManufacturerAddressUpdateDto|Optional $address,
public readonly array|Optional $product_ids,
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace Domain\Manufacturer\Repositories;

use App\Models\Address;
use Domain\Manufacturer\Dtos\ManufacturerAddressUpdateDto;
use Domain\Manufacturer\Dtos\ManufacturerCreateDto;
use Domain\Manufacturer\Dtos\ManufacturerIndexDto;
use Domain\Manufacturer\Dtos\ManufacturerUpdateDto;
use Domain\Manufacturer\Models\Manufacturer;
use Domain\User\Dtos\AddressUpdateDto;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\Config;

Expand All @@ -32,7 +32,7 @@ public function create(ManufacturerCreateDto $dto): Manufacturer

public function update(Manufacturer $manufacturer, ManufacturerUpdateDto $dto): Manufacturer
{
if ($dto->address instanceof AddressUpdateDto) {
if ($dto->address instanceof ManufacturerAddressUpdateDto) {
$manufacturer->address()->update($dto->address->toArray());
}

Expand Down
2 changes: 0 additions & 2 deletions tests/Feature/Manufacturers/ManufacturerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public function testCreate(string $user): void
'address' => [
'name' => 'Jan Kowalski',
'address' => 'Test 12',
'phone' => '123456789',
'zip' => '12-123',
'city' => 'City',
'country' => 'PL',
Expand Down Expand Up @@ -182,7 +181,6 @@ public function testUpdate(string $user): void
'address' => [
'name' => 'Jan Kowalski',
'address' => 'Test 12',
'phone' => '123456789',
'zip' => '12-123',
'city' => 'City',
'country' => 'PL',
Expand Down

0 comments on commit 4759ce0

Please sign in to comment.