From 94383672ab7d62f808773e79a44414847f01aaae Mon Sep 17 00:00:00 2001 From: vetalm1 Date: Wed, 15 Jul 2020 23:20:43 +1000 Subject: [PATCH 1/2] HW16 DDD (rework) --- app/Advert/Domain/Model/Advert.php | 8 ---- app/Advert/Domain/Model/Entities/Owner.php | 4 +- app/Advert/Domain/Model/VO/Division.php | 2 +- app/Advert/Domain/Model/VO/Img.php | 2 +- app/Advert/Domain/Model/VO/Town.php | 8 ++-- .../Repository/AdvertOperation.php} | 2 +- .../AdvertOperationEloquentRepository.php | 9 +--- app/Http/Controllers/HomeController.php | 6 +-- app/Services/Adverts/AdvertsService.php | 8 ++-- app/Services/Adverts/ItemDTO.php | 45 +++++++++++++++++++ app/Services/Adverts/ItemDto.php | 45 ------------------- .../Adverts/{ItemsDto.php => ItemsDTO.php} | 2 +- .../{PaginateDto.php => PaginateDTO.php} | 2 +- .../views/cms/adverts/blocks/item.blade.php | 2 +- resources/views/cms/blocks/header.blade.php | 3 ++ resources/views/home/blocks/header.blade.php | 3 ++ routes/web.php | 2 +- 17 files changed, 73 insertions(+), 80 deletions(-) rename app/Advert/{Domain/Service/AdvertOperationService.php => Infrastructure/Repository/AdvertOperation.php} (91%) create mode 100644 app/Services/Adverts/ItemDTO.php delete mode 100644 app/Services/Adverts/ItemDto.php rename app/Services/Adverts/{ItemsDto.php => ItemsDTO.php} (96%) rename app/Services/Adverts/{PaginateDto.php => PaginateDTO.php} (96%) diff --git a/app/Advert/Domain/Model/Advert.php b/app/Advert/Domain/Model/Advert.php index 66265a6b..e4bf965f 100644 --- a/app/Advert/Domain/Model/Advert.php +++ b/app/Advert/Domain/Model/Advert.php @@ -67,12 +67,4 @@ public function __construct $this->date = $date; } - public function publishAdvert() {} - public function viewAdvert() {} - public function editAdvert() {} - public function deleteAdvert() {} - public function archiveAdvert() {} - public function addMessageToAdvert() {} - public function editMessageInAdvert() {} - public function deleteMessageFromAdvert() {} } diff --git a/app/Advert/Domain/Model/Entities/Owner.php b/app/Advert/Domain/Model/Entities/Owner.php index 6085fd00..245af51e 100644 --- a/app/Advert/Domain/Model/Entities/Owner.php +++ b/app/Advert/Domain/Model/Entities/Owner.php @@ -33,8 +33,8 @@ public function __construct(string $name, string $phone, string $address, string $this->zipCode = $zipCode; } - public function getFullData(): string + public function getFullData(): array { - return 'Name: '.$this->name.PHP_EOL.'tel:'.$this->phone.PHP_EOL.'Adr:'.$this->address; + return ['Name: '=>$this->name,'tel:'=>$this->phone,'Adr:'=>$this->address]; } } diff --git a/app/Advert/Domain/Model/VO/Division.php b/app/Advert/Domain/Model/VO/Division.php index 59307aaa..23302f4b 100644 --- a/app/Advert/Domain/Model/VO/Division.php +++ b/app/Advert/Domain/Model/VO/Division.php @@ -1,7 +1,7 @@ name = $name; $this->state = $state; } - public function getName(): string + public function getName(): array { - return $this->name.'-'.$this->state; + return [$this->name, $this->state]; } } diff --git a/app/Advert/Domain/Service/AdvertOperationService.php b/app/Advert/Infrastructure/Repository/AdvertOperation.php similarity index 91% rename from app/Advert/Domain/Service/AdvertOperationService.php rename to app/Advert/Infrastructure/Repository/AdvertOperation.php index 244222fe..afe99578 100644 --- a/app/Advert/Domain/Service/AdvertOperationService.php +++ b/app/Advert/Infrastructure/Repository/AdvertOperation.php @@ -4,7 +4,7 @@ namespace App\Advert\Domain\Service; -interface AdvertOperationService +interface AdvertOperation { public function publishAdvert(); diff --git a/app/Advert/Infrastructure/Repository/AdvertOperationEloquentRepository.php b/app/Advert/Infrastructure/Repository/AdvertOperationEloquentRepository.php index fcf91458..7bf06e18 100644 --- a/app/Advert/Infrastructure/Repository/AdvertOperationEloquentRepository.php +++ b/app/Advert/Infrastructure/Repository/AdvertOperationEloquentRepository.php @@ -4,11 +4,9 @@ namespace App\Advert\Infrastructure\Repository; -use App\Advert\Domain\Service\AdvertOperationService; -use App\Models\Advert; -use App\Services\Adverts\Repositories\AdvertRepositoryInterface; +use App\Advert\Domain\Service\AdvertOperation; -class AdvertOperationEloquentRepository implements AdvertOperationService +class AdvertOperationEloquentRepository implements AdvertOperation { @@ -54,6 +52,3 @@ public function deleteMessageFromAdvert() } -//Все что связано с модулями (swiftmailer, eloquent, ) можно реализовать через срвисы/репозитории, -// тем самым можно отвязаться от конкретных модулей и базы данных -// diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 58bb26b3..64b37d4f 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -63,7 +63,7 @@ public function create() * Store a newly created resource in storage. * * @param StoreAdvertRequest $request - * @return Response + * @return void */ public function store(StoreAdvertRequest $request) { @@ -95,8 +95,8 @@ public function show(Advert $advert) /** * Show the form for editing the specified resource. * - * @param int $id - * @return Response + * @param int $id + * @return void */ public function edit($id) { diff --git a/app/Services/Adverts/AdvertsService.php b/app/Services/Adverts/AdvertsService.php index 3b843479..96d6838c 100644 --- a/app/Services/Adverts/AdvertsService.php +++ b/app/Services/Adverts/AdvertsService.php @@ -31,7 +31,7 @@ public function __construct( public function showItem($id) { $item = $this->advertRepository->find($id); - return ItemDto::make($item); + return $item; //ItemDTO::make($item); } public function showAdvertList() @@ -42,20 +42,20 @@ public function showAdvertList() public function showDivisionList() { $division =$this->advertRepository->divisionList(); - return ItemsDto::make($division); + return ItemsDTO::make($division); } public function showTownList() { $town = $this->advertRepository->townList(); - return ItemsDto::make($town); + return ItemsDTO::make($town); } public function page($qty) { // return $this->advertCacheRepository->cachingPage($qty); $pages = $this->advertRepository->paginateList($qty); - return PaginateDto::make($pages); + return PaginateDTO::make($pages); } diff --git a/app/Services/Adverts/ItemDTO.php b/app/Services/Adverts/ItemDTO.php new file mode 100644 index 00000000..ba8add9f --- /dev/null +++ b/app/Services/Adverts/ItemDTO.php @@ -0,0 +1,45 @@ +id = $object->id; + $this->title = $object->title; + $this->price = $object->price; + $this->content =$object->content; + $this->img = $object->img; + $this->created_at = $object->created_at; + $this->updated_at =$object->updated_at; + $this->userName = $object->user->name; + $this->user_id = $object->user_id; + $this->messages = $object->messages; + + + } + + +} diff --git a/app/Services/Adverts/ItemDto.php b/app/Services/Adverts/ItemDto.php deleted file mode 100644 index bfc19576..00000000 --- a/app/Services/Adverts/ItemDto.php +++ /dev/null @@ -1,45 +0,0 @@ -id = $data->id; - $this->title = $data->title; - $this->price = $data->price; - $this->content = $data->content; - $this->img = $data->img; - $this->created_at = $data->created_at; - $this->updated_at = $data->updated_at; - $this->userName = $data->user->name; - $this->userId = $data->user_id; - $this->messages = $data->messages; - - - } - - -} diff --git a/app/Services/Adverts/ItemsDto.php b/app/Services/Adverts/ItemsDTO.php similarity index 96% rename from app/Services/Adverts/ItemsDto.php rename to app/Services/Adverts/ItemsDTO.php index e5ce2660..b71e537c 100644 --- a/app/Services/Adverts/ItemsDto.php +++ b/app/Services/Adverts/ItemsDTO.php @@ -4,7 +4,7 @@ namespace App\Services\Adverts; -class ItemsDto +class ItemsDTO { public $items; diff --git a/app/Services/Adverts/PaginateDto.php b/app/Services/Adverts/PaginateDTO.php similarity index 96% rename from app/Services/Adverts/PaginateDto.php rename to app/Services/Adverts/PaginateDTO.php index 6635b661..e2329c4e 100644 --- a/app/Services/Adverts/PaginateDto.php +++ b/app/Services/Adverts/PaginateDTO.php @@ -4,7 +4,7 @@ namespace App\Services\Adverts; -class PaginateDto +class PaginateDTO { public $items; diff --git a/resources/views/cms/adverts/blocks/item.blade.php b/resources/views/cms/adverts/blocks/item.blade.php index a3027140..92c80ec7 100644 --- a/resources/views/cms/adverts/blocks/item.blade.php +++ b/resources/views/cms/adverts/blocks/item.blade.php @@ -4,7 +4,7 @@
... -
#{{$advert->id}} - {{$advert->userName}} (id: {{$advert->userId}})
+
#{{$advert->id}} - {{$advert->userName}} (id: {{$advert->user_id}})

{{$advert->title}}

Цена: {{$advert->price}} р.

{{$advert->content}}

diff --git a/resources/views/cms/blocks/header.blade.php b/resources/views/cms/blocks/header.blade.php index 7f44e935..d0f43596 100644 --- a/resources/views/cms/blocks/header.blade.php +++ b/resources/views/cms/blocks/header.blade.php @@ -19,6 +19,9 @@ + diff --git a/resources/views/home/blocks/header.blade.php b/resources/views/home/blocks/header.blade.php index 39890f5e..543da2ee 100644 --- a/resources/views/home/blocks/header.blade.php +++ b/resources/views/home/blocks/header.blade.php @@ -26,6 +26,9 @@ + diff --git a/routes/web.php b/routes/web.php index 0c4caf20..81670bc3 100644 --- a/routes/web.php +++ b/routes/web.php @@ -10,7 +10,7 @@ | */ -Route::get('/cms', 'Cms\CmsController@index')->middleware('auth'); +Route::get('/cms', 'Cms\CmsController@index')->middleware('auth')->name('cms'); Route::redirect('/', '/ru/home'); Auth::routes(); From c04249b2371d18e3ef7d69be816b2355aafa0613 Mon Sep 17 00:00:00 2001 From: vetalm1 Date: Fri, 17 Jul 2020 01:40:40 +1000 Subject: [PATCH 2/2] HW16 DDD (rework) --- Envoy.blade.php | 32 ++++++++++++++++++++++++++++++++ composer.json | 1 - 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 Envoy.blade.php diff --git a/Envoy.blade.php b/Envoy.blade.php new file mode 100644 index 00000000..3dd59190 --- /dev/null +++ b/Envoy.blade.php @@ -0,0 +1,32 @@ + + +@servers(['web' => ['user@80.78.254.239']]) + +@story('init') + git_init + composer +@endstory + +@story('deploy') + git_clone + composer +@endstory + +@task('git_init', ['on' => 'web']) + git clone --single-branch --branch VMeshavkin/hw16 https://github.com/otusteamedu/Laravel.git +@endtask + +@task('git_clone', ['on' => 'web']) + cd Laravel + git pull origin VMeshavkin/hw16 +@endtask + +@task('composer', ['on' => 'web']) + cd Laravel + composer install +@endtask + + +@task('test', ['on' => 'web']) + php vendor/bin/phpunit +@endtask diff --git a/composer.json b/composer.json index fb178591..a41e68d1 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,6 @@ "laravel/ui": "^2.0", "predis/predis": "^1.1", "ramsey/uuid": "^4.0", - "vagrant/calendar": "dev-VMeshavkin/hw13", "vetalm1/calendar": "dev-master", "watson/rememberable": "^4.0" },