From 5090e88fb9f4259e60b949221cb7c76bead9dae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Witold=20Wis=CC=81niewski?= Date: Thu, 12 Dec 2024 13:47:46 +0100 Subject: [PATCH] Fix phone in address --- .../Dtos/ManufacturerAddressStoreDto.php | 42 +++++++++++++++++++ .../Dtos/ManufacturerAddressUpdateDto.php | 41 ++++++++++++++++++ .../Dtos/ManufacturerCreateDto.php | 3 +- .../Dtos/ManufacturerUpdateDto.php | 3 +- .../Repositories/ManufacturerRepository.php | 4 +- .../Manufacturers/ManufacturerTest.php | 2 - 6 files changed, 87 insertions(+), 8 deletions(-) create mode 100644 src/Domain/Manufacturer/Dtos/ManufacturerAddressStoreDto.php create mode 100644 src/Domain/Manufacturer/Dtos/ManufacturerAddressUpdateDto.php diff --git a/src/Domain/Manufacturer/Dtos/ManufacturerAddressStoreDto.php b/src/Domain/Manufacturer/Dtos/ManufacturerAddressStoreDto.php new file mode 100644 index 00000000..33f9fd7e --- /dev/null +++ b/src/Domain/Manufacturer/Dtos/ManufacturerAddressStoreDto.php @@ -0,0 +1,42 @@ +> + */ + public static function rules(ValidationContext $context): array + { + return [ + 'name' => ['required', 'string', 'max:255'], + ]; + } +} diff --git a/src/Domain/Manufacturer/Dtos/ManufacturerAddressUpdateDto.php b/src/Domain/Manufacturer/Dtos/ManufacturerAddressUpdateDto.php new file mode 100644 index 00000000..dede5711 --- /dev/null +++ b/src/Domain/Manufacturer/Dtos/ManufacturerAddressUpdateDto.php @@ -0,0 +1,41 @@ +> + */ + public static function rules(ValidationContext $context): array + { + return [ + 'name' => ['string', 'max:255'], + ]; + } +} diff --git a/src/Domain/Manufacturer/Dtos/ManufacturerCreateDto.php b/src/Domain/Manufacturer/Dtos/ManufacturerCreateDto.php index 189501c8..30cc5799 100644 --- a/src/Domain/Manufacturer/Dtos/ManufacturerCreateDto.php +++ b/src/Domain/Manufacturer/Dtos/ManufacturerCreateDto.php @@ -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; @@ -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, ) {} diff --git a/src/Domain/Manufacturer/Dtos/ManufacturerUpdateDto.php b/src/Domain/Manufacturer/Dtos/ManufacturerUpdateDto.php index c2253fea..6f3d2c6f 100644 --- a/src/Domain/Manufacturer/Dtos/ManufacturerUpdateDto.php +++ b/src/Domain/Manufacturer/Dtos/ManufacturerUpdateDto.php @@ -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; @@ -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, ) {} } diff --git a/src/Domain/Manufacturer/Repositories/ManufacturerRepository.php b/src/Domain/Manufacturer/Repositories/ManufacturerRepository.php index 21ec3216..a1e96725 100644 --- a/src/Domain/Manufacturer/Repositories/ManufacturerRepository.php +++ b/src/Domain/Manufacturer/Repositories/ManufacturerRepository.php @@ -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; @@ -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()); } diff --git a/tests/Feature/Manufacturers/ManufacturerTest.php b/tests/Feature/Manufacturers/ManufacturerTest.php index 48475c3b..747f38f9 100644 --- a/tests/Feature/Manufacturers/ManufacturerTest.php +++ b/tests/Feature/Manufacturers/ManufacturerTest.php @@ -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', @@ -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',