From 966f7a3e79be5451f641091b1331244cab8ae3e5 Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Mon, 4 Dec 2023 16:50:31 +0300 Subject: [PATCH 01/21] Added plan create page --- app/Livewire/Plan/Create.php | 3 +- .../views/livewire/plan/create.blade.php | 776 +++++++++++------- 2 files changed, 503 insertions(+), 276 deletions(-) diff --git a/app/Livewire/Plan/Create.php b/app/Livewire/Plan/Create.php index fd2ae10..2371a99 100644 --- a/app/Livewire/Plan/Create.php +++ b/app/Livewire/Plan/Create.php @@ -70,12 +70,13 @@ class Create extends Component $this->$options_type['price'] = $this->$options_type_input['price']; $this->$options_type['description'] = $this->$options_type_input['description']; $this->$options_type['items'][] = $this->input_items; + // dd($this->options_type_input); $this->reset('input_items'); } public function publish() { - /* dd($this->type); */ + // dd($this->details); $this->validate(); $plan = new Plan(); diff --git a/resources/views/livewire/plan/create.blade.php b/resources/views/livewire/plan/create.blade.php index d174a7b..3e52006 100644 --- a/resources/views/livewire/plan/create.blade.php +++ b/resources/views/livewire/plan/create.blade.php @@ -1,92 +1,192 @@ -
-
- Мои планы -
-
Добавление плана
-
-
-
+
+
+
+ +

+ Мои планы +

+
-
+
+
+
+ Название +
+ +
-
-
- - -
+
+
+
+
+ Изображение +
+
From a975c75bfdf48f3f50a8b17b576a032ce916c28d Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Wed, 6 Dec 2023 12:21:14 +0300 Subject: [PATCH 02/21] added plan factory and seeder --- database/factories/PlanFactory.php | 51 +++++++++++++++++++++++++++ database/seeders/PlanTablesSeeder.php | 19 ++++++++++ 2 files changed, 70 insertions(+) create mode 100755 database/factories/PlanFactory.php create mode 100755 database/seeders/PlanTablesSeeder.php diff --git a/database/factories/PlanFactory.php b/database/factories/PlanFactory.php new file mode 100755 index 0000000..697e274 --- /dev/null +++ b/database/factories/PlanFactory.php @@ -0,0 +1,51 @@ + + */ +class PlanFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + $faker = \Faker\Factory::create(); + $this->faker->addProvider(new Restaurant($faker)); + + $typeBody = [ + 'fit' => $this->faker->boolean(), + 'slim' => $this->faker->boolean(), + 'behavior' => $this->faker->boolean(), + 'wellness' => $this->faker->boolean(), + ]; + + $packetsOptions = [ + 'items' => [$this->faker->fruitName(), $this->faker->meatName(), $this->faker->sauceName()], + 'price' => $this->faker->randomNumber(), + 'short' => $this->faker->foodName(), + 'description' => $this->faker->text(), + ]; + + return [ + 'name' => $this->faker->foodName(), + // 'image' => $this->faker->image('application/storage/fake_images', 640, 480, null, false), + 'image' => storage_path('public/img/Photo_C.png'), + 'duration' => $this->faker->randomElement([7, 14,21]), + 'state' => $this->faker->randomElement(['active', 'draft', 'archived']), + 'type' => $typeBody, + 'details' => $this->faker->text(), + 'packets_count' => $this->faker->randomElement([1, 3]), + 'packet1_options' => $packetsOptions, + 'packet2_options' => $packetsOptions, + 'packet3_options' => $packetsOptions, + ]; + } +} diff --git a/database/seeders/PlanTablesSeeder.php b/database/seeders/PlanTablesSeeder.php new file mode 100755 index 0000000..184b2b0 --- /dev/null +++ b/database/seeders/PlanTablesSeeder.php @@ -0,0 +1,19 @@ +count(10)->create(); + } +} From 2a78186a98144c77b52adf3025181eed4d2d549b Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Wed, 6 Dec 2023 12:26:24 +0300 Subject: [PATCH 03/21] added feature test plan --- tests/Plan/CreateTest.php | 94 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 tests/Plan/CreateTest.php diff --git a/tests/Plan/CreateTest.php b/tests/Plan/CreateTest.php new file mode 100644 index 0000000..928accc --- /dev/null +++ b/tests/Plan/CreateTest.php @@ -0,0 +1,94 @@ +create(); + + $response = $this->actingAs($user) + ->get('/plan/create'); + + $response + ->assertOk(); + } + + public function test_publish_new_plan_success(): void + { + $plan = Plan::factory()->make(); + $user = User::factory()->create(); + + $this->actingAs($user); + + Livewire::test(Create::class) + ->set('name', $plan->name) + ->set('image', $plan->image) + ->set('duration', $plan->duration) + ->set('state', $plan->state) + ->set('type', $plan->type) + ->set('details', $plan->details) + ->set('packets_count', $plan->packets_count) + ->set('packet1_options', $plan->packet1_options) + ->set('packet2_options', $plan->packet2_options) + ->set('packet3_options', $plan->packet3_options) + ->call('publish') + ->assertRedirect('/plan/'. $plan->id); + } + + public function test_to_draft_new_plan_success(): void + { + $plan = Plan::factory()->make(); + $user = User::factory()->create(); + + $this->actingAs($user); + + Livewire::test(Create::class) + ->set('name', $plan->name) + ->set('image', $plan->image) + ->set('duration', $plan->duration) + ->set('state', $plan->state) + ->set('type', $plan->type) + ->set('details', $plan->details) + ->set('packets_count', $plan->packets_count) + ->set('packet1_options', $plan->packet1_options) + ->set('packet2_options', $plan->packet2_options) + ->set('packet3_options', $plan->packet3_options) + ->call('addToDrafts') + ->assertRedirect('/plan/'. $plan->id); + } + + public function test_to_preview_new_plan_success(): void + { + $plan = Plan::factory()->make(); + $user = User::factory()->create(); + + $this->actingAs($user); + + Livewire::test(Create::class) + ->set('name', $plan->name) + ->set('image', $plan->image) + ->set('duration', $plan->duration) + ->set('state', $plan->state) + ->set('type', $plan->type) + ->set('details', $plan->details) + ->set('packets_count', $plan->packets_count) + ->set('packet1_options', $plan->packet1_options) + ->set('packet2_options', $plan->packet2_options) + ->set('packet3_options', $plan->packet3_options) + ->call('addToDrafts') + ->assertRedirect('/plan/'. $plan->id); + } +} From be80f55dfa185afd81f5d0a5536d4ea18db9a39a Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Wed, 6 Dec 2023 12:30:49 +0300 Subject: [PATCH 04/21] fix create plan content --- app/Livewire/Plan/Create.php | 42 +++++++++++-------- .../views/livewire/plan/create.blade.php | 12 +++--- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/app/Livewire/Plan/Create.php b/app/Livewire/Plan/Create.php index 2371a99..abbff86 100644 --- a/app/Livewire/Plan/Create.php +++ b/app/Livewire/Plan/Create.php @@ -27,7 +27,9 @@ class Create extends Component public $packet2_options_input = []; public $packet3_options_input = []; - public $input_items = ""; + public $input_items_1 = ""; + public $input_items_2 = ""; + public $input_items_3 = ""; protected function rules() { @@ -69,42 +71,46 @@ class Create extends Component $this->$options_type['short'] = $this->$options_type_input['short']; $this->$options_type['price'] = $this->$options_type_input['price']; $this->$options_type['description'] = $this->$options_type_input['description']; - $this->$options_type['items'][] = $this->input_items; - // dd($this->options_type_input); - $this->reset('input_items'); + $this->$options_type['items'][] = $this->input_items_1; + $this->$options_type['items'][] = $this->input_items_2; + $this->$options_type['items'][] = $this->input_items_3; + $this->reset('input_items_1'); + $this->reset('input_items_2'); + $this->reset('input_items_3'); } public function publish() { - // dd($this->details); $this->validate(); $plan = new Plan(); - $plan->name = $this->name; - $plan->image = $this->image->store('plans', 'public'); - $plan->duration = $this->duration; - $plan->state = $this->state; - $plan->type = json_encode($this->type); - $plan->details = $this->details; - $plan->packets_count = $this->packets_count; - $plan->packet1_options = json_encode($this->packet1_options); - $plan->packet2_options = json_encode($this->packet2_options); - $plan->packet3_options = json_encode($this->packet3_options); - $plan->save(); + + $this->name = $plan->name; + $this->image = $plan->image->store('plans', 'public'); + $this->duration = $plan->duration; + $this->state = $plan->state; + $this->details = $plan->details; + $this->packets_count = $plan->packets_count; + $this->type = json_encode($plan->type); + $this->packet1_options = json_encode($plan->packet1_options); + $this->packet2_options = json_encode($plan->packet2_options); + $this->packet3_options = json_encode($plan->packet3_options); + $this->plan->saveOrFail(); $user = Auth::user(); $user->author_of_plans()->attach($plan->id); + return redirect()->route('plan.show', $plan->id); } public function addToDrafts() { - $this->type = "draft"; + $this->state = "draft"; $this->publish(); } public function showPreview() { - $this->type = "inactive"; + $this->state = "inactive"; $this->publish(); } } diff --git a/resources/views/livewire/plan/create.blade.php b/resources/views/livewire/plan/create.blade.php index 3e52006..a3f8d55 100644 --- a/resources/views/livewire/plan/create.blade.php +++ b/resources/views/livewire/plan/create.blade.php @@ -78,8 +78,6 @@ - -
@@ -278,7 +276,7 @@ @endisset
-
@@ -351,7 +349,7 @@ @endisset
-
@@ -420,7 +418,7 @@ @endisset
-
@@ -480,7 +478,7 @@
Содержание услуги
- @isset($packet2_options['items']) + @isset($packet3_options['items'])
    @foreach ($packet3_options['items'] as $item)
  • @@ -491,7 +489,7 @@ @endisset
    -
    From 950f3bd6a95ec6a7620133a1d38a65804c293740 Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Wed, 6 Dec 2023 12:39:04 +0300 Subject: [PATCH 05/21] correct plan field --- app/Livewire/Plan/Create.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/Livewire/Plan/Create.php b/app/Livewire/Plan/Create.php index abbff86..d9d0e85 100644 --- a/app/Livewire/Plan/Create.php +++ b/app/Livewire/Plan/Create.php @@ -85,21 +85,21 @@ class Create extends Component $plan = new Plan(); - $this->name = $plan->name; - $this->image = $plan->image->store('plans', 'public'); - $this->duration = $plan->duration; - $this->state = $plan->state; - $this->details = $plan->details; - $this->packets_count = $plan->packets_count; - $this->type = json_encode($plan->type); - $this->packet1_options = json_encode($plan->packet1_options); - $this->packet2_options = json_encode($plan->packet2_options); - $this->packet3_options = json_encode($plan->packet3_options); - $this->plan->saveOrFail(); + $plan->name = $this->name; + $plan->image = $this->image->store('plans', 'public'); + $plan->duration = $this->duration; + $plan->state = $this->state; + $plan->details = $this->details; + $plan->packets_count = $this->packets_count; + $plan->type = json_encode($this->type); + $plan->packet1_options = json_encode($this->packet1_options); + $plan->packet2_options = json_encode($this->packet2_options); + $plan->packet3_options = json_encode($this->packet3_options); + $plan->plan->saveOrFail(); $user = Auth::user(); - $user->author_of_plans()->attach($plan->id); + $user->author_of_plans()->attach($this->id); - return redirect()->route('plan.show', $plan->id); + return redirect()->route('plan.show', $this->id); } public function addToDrafts() From c2f86d8f65a4fd050e23d3114d38b474a2f64a7b Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Wed, 6 Dec 2023 12:53:04 +0300 Subject: [PATCH 06/21] add options for seeders Plan --- composer.json | 5 ++++- database/seeders/DatabaseSeeder.php | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c399c19..c8acd01 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,7 @@ "doctrine/dbal": "^3.0", "guzzlehttp/guzzle": "^7.2", "iben12/laravel-statable": "^1.5", + "jzonta/faker-restaurant": "^2.0", "laravel/framework": "^10.0", "laravel/jetstream": "^4.0", "laravel/sanctum": "^3.2", @@ -59,7 +60,9 @@ ], "post-create-project-cmd": [ "@php artisan key:generate --ansi" - ] + ], + "php-cs-fixer": "php-cs-fixer --config=.php-cs-fixer.php --allow-risky=yes", + "test": "phpunit --colors=always" }, "extra": { "laravel": { diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 71f673f..83f84bd 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -14,6 +14,7 @@ class DatabaseSeeder extends Seeder */ public function run() { + $this->call(PlanTablesSeeder::class); // \App\Models\User::factory(10)->create(); } } From 198b82970785176173a866456df5954c03c05bd4 Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Wed, 6 Dec 2023 12:56:19 +0300 Subject: [PATCH 07/21] added composer lock --- composer.lock | 184 +++++++++++++++++++++++++++++++------------------- 1 file changed, 115 insertions(+), 69 deletions(-) diff --git a/composer.lock b/composer.lock index f86d69d..910ad95 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "34d1a8c89daa6bffe88d41428ab1f92e", + "content-hash": "d583b5e56204b55c62acc30999b7d1f5", "packages": [ { "name": "asantibanez/livewire-charts", @@ -1170,6 +1170,74 @@ ], "time": "2023-01-14T14:17:03+00:00" }, + { + "name": "fakerphp/faker", + "version": "v1.23.0", + "source": { + "type": "git", + "url": "https://github.com/FakerPHP/Faker.git", + "reference": "e3daa170d00fde61ea7719ef47bb09bb8f1d9b01" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/FakerPHP/Faker/zipball/e3daa170d00fde61ea7719ef47bb09bb8f1d9b01", + "reference": "e3daa170d00fde61ea7719ef47bb09bb8f1d9b01", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0", + "psr/container": "^1.0 || ^2.0", + "symfony/deprecation-contracts": "^2.2 || ^3.0" + }, + "conflict": { + "fzaninotto/faker": "*" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.4.1", + "doctrine/persistence": "^1.3 || ^2.0", + "ext-intl": "*", + "phpunit/phpunit": "^9.5.26", + "symfony/phpunit-bridge": "^5.4.16" + }, + "suggest": { + "doctrine/orm": "Required to use Faker\\ORM\\Doctrine", + "ext-curl": "Required by Faker\\Provider\\Image to download images.", + "ext-dom": "Required by Faker\\Provider\\HtmlLorem for generating random HTML.", + "ext-iconv": "Required by Faker\\Provider\\ru_RU\\Text::realText() for generating real Russian text.", + "ext-mbstring": "Required for multibyte Unicode string functionality." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "v1.21-dev" + } + }, + "autoload": { + "psr-4": { + "Faker\\": "src/Faker/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "François Zaninotto" + } + ], + "description": "Faker is a PHP library that generates fake data for you.", + "keywords": [ + "data", + "faker", + "fixtures" + ], + "support": { + "issues": "https://github.com/FakerPHP/Faker/issues", + "source": "https://github.com/FakerPHP/Faker/tree/v1.23.0" + }, + "time": "2023-06-12T08:44:38+00:00" + }, { "name": "fruitcake/php-cors", "version": "v1.2.0", @@ -2022,6 +2090,52 @@ ], "time": "2020-06-13T08:05:20+00:00" }, + { + "name": "jzonta/faker-restaurant", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/jzonta/FakerRestaurant.git", + "reference": "4e10ff08dc8ca08603a3daf7abe48d412b013cf4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jzonta/FakerRestaurant/zipball/4e10ff08dc8ca08603a3daf7abe48d412b013cf4", + "reference": "4e10ff08dc8ca08603a3daf7abe48d412b013cf4", + "shasum": "" + }, + "require": { + "fakerphp/faker": "^1.9.1", + "php": ">=7.1" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.17", + "phpstan/phpstan": "^0.12.66", + "phpunit/phpunit": "^9" + }, + "type": "library", + "autoload": { + "psr-4": { + "FakerRestaurant\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "João Zonta" + } + ], + "description": "Food and Beverage names generate using fakerphp/faker", + "homepage": "https://github.com/jzonta/FakerRestaurant", + "support": { + "issues": "https://github.com/jzonta/FakerRestaurant/issues", + "source": "https://github.com/jzonta/FakerRestaurant/tree/v2.0.1" + }, + "time": "2021-11-15T11:21:22+00:00" + }, { "name": "laravel/fortify", "version": "v1.17.5", @@ -9324,74 +9438,6 @@ } ], "packages-dev": [ - { - "name": "fakerphp/faker", - "version": "v1.23.0", - "source": { - "type": "git", - "url": "https://github.com/FakerPHP/Faker.git", - "reference": "e3daa170d00fde61ea7719ef47bb09bb8f1d9b01" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/FakerPHP/Faker/zipball/e3daa170d00fde61ea7719ef47bb09bb8f1d9b01", - "reference": "e3daa170d00fde61ea7719ef47bb09bb8f1d9b01", - "shasum": "" - }, - "require": { - "php": "^7.4 || ^8.0", - "psr/container": "^1.0 || ^2.0", - "symfony/deprecation-contracts": "^2.2 || ^3.0" - }, - "conflict": { - "fzaninotto/faker": "*" - }, - "require-dev": { - "bamarni/composer-bin-plugin": "^1.4.1", - "doctrine/persistence": "^1.3 || ^2.0", - "ext-intl": "*", - "phpunit/phpunit": "^9.5.26", - "symfony/phpunit-bridge": "^5.4.16" - }, - "suggest": { - "doctrine/orm": "Required to use Faker\\ORM\\Doctrine", - "ext-curl": "Required by Faker\\Provider\\Image to download images.", - "ext-dom": "Required by Faker\\Provider\\HtmlLorem for generating random HTML.", - "ext-iconv": "Required by Faker\\Provider\\ru_RU\\Text::realText() for generating real Russian text.", - "ext-mbstring": "Required for multibyte Unicode string functionality." - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "v1.21-dev" - } - }, - "autoload": { - "psr-4": { - "Faker\\": "src/Faker/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "François Zaninotto" - } - ], - "description": "Faker is a PHP library that generates fake data for you.", - "keywords": [ - "data", - "faker", - "fixtures" - ], - "support": { - "issues": "https://github.com/FakerPHP/Faker/issues", - "source": "https://github.com/FakerPHP/Faker/tree/v1.23.0" - }, - "time": "2023-06-12T08:44:38+00:00" - }, { "name": "filp/whoops", "version": "2.15.3", From d285a6ac8d41413d0b095c244c350e2571b922a2 Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Wed, 6 Dec 2023 13:03:17 +0300 Subject: [PATCH 08/21] renamed plan seeder --- database/seeders/DatabaseSeeder.php | 2 +- database/seeders/PlanSeeder.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100755 database/seeders/PlanSeeder.php diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 83f84bd..e59e5b4 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -14,7 +14,7 @@ class DatabaseSeeder extends Seeder */ public function run() { - $this->call(PlanTablesSeeder::class); + $this->call(PlanSeeder::class); // \App\Models\User::factory(10)->create(); } } diff --git a/database/seeders/PlanSeeder.php b/database/seeders/PlanSeeder.php new file mode 100755 index 0000000..184b2b0 --- /dev/null +++ b/database/seeders/PlanSeeder.php @@ -0,0 +1,19 @@ +count(10)->create(); + } +} From 1f958bb971863dd63d270603313157d980f2b37e Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Wed, 6 Dec 2023 13:07:19 +0300 Subject: [PATCH 09/21] correct name seeder --- database/seeders/PlanSeeder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/seeders/PlanSeeder.php b/database/seeders/PlanSeeder.php index 184b2b0..81cf277 100755 --- a/database/seeders/PlanSeeder.php +++ b/database/seeders/PlanSeeder.php @@ -7,7 +7,7 @@ use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; use App\Models\Plan; -class PlanTablesSeeder extends Seeder +class PlanSeeder extends Seeder { /** * Run the database seeds. From 0a10264850a12bfc11e2a1a1da2047e15c04200e Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Wed, 6 Dec 2023 13:43:55 +0300 Subject: [PATCH 10/21] added casts to plan model --- app/Models/Plan.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/Models/Plan.php b/app/Models/Plan.php index 6f81b28..708d131 100644 --- a/app/Models/Plan.php +++ b/app/Models/Plan.php @@ -12,13 +12,22 @@ use CyrildeWit\EloquentViewable\Contracts\Viewable; class Plan extends Model implements Viewable { - use HasFactory, InteractsWithViews; + use HasFactory; + use InteractsWithViews; protected $withCount = [ 'likes', 'comments' ]; + protected $casts = [ + 'type' => 'array', + 'packet1_options' => 'array', + 'packet2_options' => 'array', + 'packet3_options' => 'array', + ]; + + public function author() { return $this->belongsToMany(User::class, 'plan_author', 'plan_id', 'user_id'); @@ -62,7 +71,7 @@ class Plan extends Model implements Viewable $data = $this->unserializeOptionsArr($this->type); return new Attribute( - get: fn() => array_keys($data), + get: fn () => array_keys($data), ); } @@ -79,7 +88,7 @@ class Plan extends Model implements Viewable } return new Attribute( - get: fn() => $result, + get: fn () => $result, ); } From 2c64099377fd08e4ea94b967188947062a85e8fd Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Thu, 7 Dec 2023 11:27:20 +0300 Subject: [PATCH 11/21] added seeder for users --- database/factories/UserDetailzFactory.php | 4 +- database/factories/UserFactory.php | 2 + ...3_31_093623_create_user_detailzs_table.php | 2 +- database/seeders/DatabaseSeeder.php | 1 + database/seeders/UserSeeder.php | 60 +++++++++++++++++++ 5 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 database/seeders/UserSeeder.php diff --git a/database/factories/UserDetailzFactory.php b/database/factories/UserDetailzFactory.php index a17eaa8..bf91c8f 100644 --- a/database/factories/UserDetailzFactory.php +++ b/database/factories/UserDetailzFactory.php @@ -21,7 +21,7 @@ class UserDetailzFactory extends Factory public function definition() { return [ - 'user_id' => User::factory(), + // 'user_id' => User::factory(), 'first_name' => $this->faker->name(), 'last_name' => $this->faker->name(), 'birthdate' => $this->faker->date('Y-m-d'), @@ -43,6 +43,8 @@ class UserDetailzFactory extends Factory 'favorite_foods' => $this->faker->text(), 'unfavorite_foods' => $this->faker->text(), 'additional_info' => $this->faker->text(), + 'is_mood_fillable' => $this->faker->boolean(), + 'is_bedtime_fillable' => $this->faker->boolean(), ]; } } diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 46cb47d..79728fe 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -20,6 +20,8 @@ class UserFactory extends Factory */ public function definition(): array { + + return [ 'name' => $this->faker->name(), 'email' => $this->faker->unique()->safeEmail(), diff --git a/database/migrations/2022_03_31_093623_create_user_detailzs_table.php b/database/migrations/2022_03_31_093623_create_user_detailzs_table.php index 51369ec..5034343 100644 --- a/database/migrations/2022_03_31_093623_create_user_detailzs_table.php +++ b/database/migrations/2022_03_31_093623_create_user_detailzs_table.php @@ -16,7 +16,7 @@ return new class extends Migration { Schema::create('user_detailzs', function (Blueprint $table) { $table->id(); - $table->bigInteger('user_id'); + $table->bigInteger('user_id')->nullable(); $table->string('first_name', 256)->default(''); $table->string('last_name', 256)->default(''); $table->date('birthdate')->default('1980-01-01')->nullable(false); diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index e59e5b4..a8222ee 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -15,6 +15,7 @@ class DatabaseSeeder extends Seeder public function run() { $this->call(PlanSeeder::class); + $this->call(UserSeeder::class); // \App\Models\User::factory(10)->create(); } } diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php new file mode 100644 index 0000000..0436dbf --- /dev/null +++ b/database/seeders/UserSeeder.php @@ -0,0 +1,60 @@ +create(); + + $userDetailz = UserDetailz::factory()->make(); + + $userDetailz->user()->associate($user); + + $userDetailz->saveOrFail(); + + }, $this->getListUsers()); + } + + private function getListUsers(): array + { + return [ + ['id' => 3, 'name' => 'Анчоус Альф', 'email' => 'reshetnick.mike+user1@gmail.com', 'password' => Hash::make('1234567890'), 'is_consultant' => true], + ['id' => 4, 'name' => 'Чена Сибаину', 'email' => 'reshetnik.n+user1@gmail.com', 'password' => Hash::make('1234567890'), 'is_consultant' => true], + ['id' => 5, 'name' => 'Бруно Бармалей', 'email' => 'reshetnick.mike+user2@gmail.com', 'password' => Hash::make('1234567890'), 'is_consultant' => true], + ['id' => 6, 'name' => 'Варенник Васаби', 'email' => 'reshetnick.mike+user3@gmail.com', 'password' => Hash::make('1234567890'), 'is_consultant' => true], + ['id' => 7, 'name' => 'Денди Дуглас', 'email' => 'reshetnick.mike+user4@gmail.com', 'password' => Hash::make('1234567890'), 'is_consultant' => true], + ['id' => 8, 'name' => 'Ник Радченков', 'email' => 'reshetnik.n+user2@gmail.com', 'password' => Hash::make('1234567890')], + ['id' => 9, 'name' => 'Миса Кошка', 'email' => 'reshetnik.n+user3@gmail.com', 'password' => Hash::make('1234567890')], + + ['id' => 10, 'name' => 'Ерошка Есаул', 'email' => 'reshetnick.mike+user5@gmail.com', 'password' => Hash::make('1234567890')], + ['id' => 11, 'name' => 'Жмурка Живчик', 'email' => 'reshetnick.mike+user6@gmail.com', 'password' => Hash::make('1234567890')], + ['id' => 12, 'name' => 'Гошка Картошка', 'email' => 'reshetnik.n+user4@gmail.com', 'password' => Hash::make('1234567890')], + ['id' => 13, 'name' => 'Зефир Забияка', 'email' => 'reshetnick.mike+user7@gmail.com', 'password' => Hash::make('1234567890')], + ['id' => 14, 'name' => 'Антоша Одуван', 'email' => 'reshetnik.n+user5@gmail.com', 'password' => Hash::make('1234567890')], + ['id' => 15, 'name' => 'Кусик Кукусик', 'email' => 'reshetnik.n+user6@gmail.com', 'password' => Hash::make('1234567890')], + ['id' => 16, 'name' => 'Косик Кокосик', 'email' => 'reshetnik.n+user7@gmail.com', 'password' => Hash::make('1234567890')], + + ['id' => 17, 'name' => 'Хинкалька Вкусная', 'email' => 'reshetnik.n+user8@gmail.com', 'password' => Hash::make('1234567890')], + ['id' => 18, 'name' => 'Импульс Йети', 'email' => 'reshetnick.mike+user8@gmail.com', 'password' => Hash::make('1234567890')], + ['id' => 19, 'name' => 'Квики Кекс', 'email' => 'reshetnick.mike+user9@gmail.com', 'password' => Hash::make('1234567890')], + ['id' => 20, 'name' => 'Чебурек Сочный', 'email' => 'reshetnik.n+user9@gmail.com', 'password' => Hash::make('1234567890')], + ['id' => 21, 'name' => 'Клубника Дикая', 'email' => 'reshetnik.n+user10@gmail.com', 'password' => Hash::make('1234567890')], + ['id' => 22, 'name' => 'Ляпис Лапша', 'email' => 'reshetnick.mike+user10@gmail.com', 'password' => Hash::make('1234567890')], + ['id' => 23, 'name' => 'Друг Парадоксов', 'email' => 'reshetnick.mike+user11@gmail.com', 'password' => Hash::make('1234567890')], + ]; + } +} From e57c1e63e787161451d7e9d54ec78f9ad0447892 Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Thu, 7 Dec 2023 14:21:46 +0300 Subject: [PATCH 12/21] removed bad name seeder --- database/seeders/PlanTablesSeeder.php | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100755 database/seeders/PlanTablesSeeder.php diff --git a/database/seeders/PlanTablesSeeder.php b/database/seeders/PlanTablesSeeder.php deleted file mode 100755 index 184b2b0..0000000 --- a/database/seeders/PlanTablesSeeder.php +++ /dev/null @@ -1,19 +0,0 @@ -count(10)->create(); - } -} From 8dec419f93edf252701ad9cd1a0590f29639bf4e Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Thu, 7 Dec 2023 14:23:44 +0300 Subject: [PATCH 13/21] fix error plan --- app/Livewire/Plan/Create.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/Livewire/Plan/Create.php b/app/Livewire/Plan/Create.php index d9d0e85..dc73888 100644 --- a/app/Livewire/Plan/Create.php +++ b/app/Livewire/Plan/Create.php @@ -85,21 +85,21 @@ class Create extends Component $plan = new Plan(); - $plan->name = $this->name; - $plan->image = $this->image->store('plans', 'public'); - $plan->duration = $this->duration; - $plan->state = $this->state; - $plan->details = $this->details; - $plan->packets_count = $this->packets_count; - $plan->type = json_encode($this->type); - $plan->packet1_options = json_encode($this->packet1_options); - $plan->packet2_options = json_encode($this->packet2_options); - $plan->packet3_options = json_encode($this->packet3_options); - $plan->plan->saveOrFail(); + $this->name = $plan->name; + $this->image = $plan->image->store('plans', 'public'); + $this->duration = $plan->duration; + $this->state = $plan->state; + $this->details = $plan->details; + $this->packets_count = $plan->packets_count; + $this->type = json_encode($plan->type); + $this->packet1_options = json_encode($plan->packet1_options); + $this->packet2_options = json_encode($plan->packet2_options); + $this->packet3_options = json_encode($plan->packet3_options); + $plan->saveOrFail(); $user = Auth::user(); - $user->author_of_plans()->attach($this->id); + $user->author_of_plans()->attach($plan->id); - return redirect()->route('plan.show', $this->id); + return redirect()->route('plan.show', $plan->id); } public function addToDrafts() From 795253cc25f8bd6e88270bec5bce2d91e4023c9c Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Thu, 7 Dec 2023 14:34:36 +0300 Subject: [PATCH 14/21] new variable for all password hash --- database/seeders/UserSeeder.php | 44 +++++++++++++++++---------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php index 0436dbf..e2fc86c 100644 --- a/database/seeders/UserSeeder.php +++ b/database/seeders/UserSeeder.php @@ -31,30 +31,32 @@ class UserSeeder extends Seeder private function getListUsers(): array { + $allUsersHash = Hash::make('1234567890'); + return [ - ['id' => 3, 'name' => 'Анчоус Альф', 'email' => 'reshetnick.mike+user1@gmail.com', 'password' => Hash::make('1234567890'), 'is_consultant' => true], - ['id' => 4, 'name' => 'Чена Сибаину', 'email' => 'reshetnik.n+user1@gmail.com', 'password' => Hash::make('1234567890'), 'is_consultant' => true], - ['id' => 5, 'name' => 'Бруно Бармалей', 'email' => 'reshetnick.mike+user2@gmail.com', 'password' => Hash::make('1234567890'), 'is_consultant' => true], - ['id' => 6, 'name' => 'Варенник Васаби', 'email' => 'reshetnick.mike+user3@gmail.com', 'password' => Hash::make('1234567890'), 'is_consultant' => true], - ['id' => 7, 'name' => 'Денди Дуглас', 'email' => 'reshetnick.mike+user4@gmail.com', 'password' => Hash::make('1234567890'), 'is_consultant' => true], - ['id' => 8, 'name' => 'Ник Радченков', 'email' => 'reshetnik.n+user2@gmail.com', 'password' => Hash::make('1234567890')], - ['id' => 9, 'name' => 'Миса Кошка', 'email' => 'reshetnik.n+user3@gmail.com', 'password' => Hash::make('1234567890')], + ['id' => 3, 'name' => 'Анчоус Альф', 'email' => 'reshetnick.mike+user1@gmail.com', 'password' => $allUsersHash, 'is_consultant' => true], + ['id' => 4, 'name' => 'Чена Сибаину', 'email' => 'reshetnik.n+user1@gmail.com', 'password' => $allUsersHash, 'is_consultant' => true], + ['id' => 5, 'name' => 'Бруно Бармалей', 'email' => 'reshetnick.mike+user2@gmail.com', 'password' => $allUsersHash, 'is_consultant' => true], + ['id' => 6, 'name' => 'Варенник Васаби', 'email' => 'reshetnick.mike+user3@gmail.com', 'password' => $allUsersHash, 'is_consultant' => true], + ['id' => 7, 'name' => 'Денди Дуглас', 'email' => 'reshetnick.mike+user4@gmail.com', 'password' => $allUsersHash, 'is_consultant' => true], + ['id' => 8, 'name' => 'Ник Радченков', 'email' => 'reshetnik.n+user2@gmail.com', 'password' => $allUsersHash], + ['id' => 9, 'name' => 'Миса Кошка', 'email' => 'reshetnik.n+user3@gmail.com', 'password' => $allUsersHash], - ['id' => 10, 'name' => 'Ерошка Есаул', 'email' => 'reshetnick.mike+user5@gmail.com', 'password' => Hash::make('1234567890')], - ['id' => 11, 'name' => 'Жмурка Живчик', 'email' => 'reshetnick.mike+user6@gmail.com', 'password' => Hash::make('1234567890')], - ['id' => 12, 'name' => 'Гошка Картошка', 'email' => 'reshetnik.n+user4@gmail.com', 'password' => Hash::make('1234567890')], - ['id' => 13, 'name' => 'Зефир Забияка', 'email' => 'reshetnick.mike+user7@gmail.com', 'password' => Hash::make('1234567890')], - ['id' => 14, 'name' => 'Антоша Одуван', 'email' => 'reshetnik.n+user5@gmail.com', 'password' => Hash::make('1234567890')], - ['id' => 15, 'name' => 'Кусик Кукусик', 'email' => 'reshetnik.n+user6@gmail.com', 'password' => Hash::make('1234567890')], - ['id' => 16, 'name' => 'Косик Кокосик', 'email' => 'reshetnik.n+user7@gmail.com', 'password' => Hash::make('1234567890')], + ['id' => 10, 'name' => 'Ерошка Есаул', 'email' => 'reshetnick.mike+user5@gmail.com', 'password' => $allUsersHash], + ['id' => 11, 'name' => 'Жмурка Живчик', 'email' => 'reshetnick.mike+user6@gmail.com', 'password' => $allUsersHash], + ['id' => 12, 'name' => 'Гошка Картошка', 'email' => 'reshetnik.n+user4@gmail.com', 'password' => $allUsersHash], + ['id' => 13, 'name' => 'Зефир Забияка', 'email' => 'reshetnick.mike+user7@gmail.com', 'password' => $allUsersHash], + ['id' => 14, 'name' => 'Антоша Одуван', 'email' => 'reshetnik.n+user5@gmail.com', 'password' => $allUsersHash], + ['id' => 15, 'name' => 'Кусик Кукусик', 'email' => 'reshetnik.n+user6@gmail.com', 'password' => $allUsersHash], + ['id' => 16, 'name' => 'Косик Кокосик', 'email' => 'reshetnik.n+user7@gmail.com', 'password' => $allUsersHash], - ['id' => 17, 'name' => 'Хинкалька Вкусная', 'email' => 'reshetnik.n+user8@gmail.com', 'password' => Hash::make('1234567890')], - ['id' => 18, 'name' => 'Импульс Йети', 'email' => 'reshetnick.mike+user8@gmail.com', 'password' => Hash::make('1234567890')], - ['id' => 19, 'name' => 'Квики Кекс', 'email' => 'reshetnick.mike+user9@gmail.com', 'password' => Hash::make('1234567890')], - ['id' => 20, 'name' => 'Чебурек Сочный', 'email' => 'reshetnik.n+user9@gmail.com', 'password' => Hash::make('1234567890')], - ['id' => 21, 'name' => 'Клубника Дикая', 'email' => 'reshetnik.n+user10@gmail.com', 'password' => Hash::make('1234567890')], - ['id' => 22, 'name' => 'Ляпис Лапша', 'email' => 'reshetnick.mike+user10@gmail.com', 'password' => Hash::make('1234567890')], - ['id' => 23, 'name' => 'Друг Парадоксов', 'email' => 'reshetnick.mike+user11@gmail.com', 'password' => Hash::make('1234567890')], + ['id' => 17, 'name' => 'Хинкалька Вкусная', 'email' => 'reshetnik.n+user8@gmail.com', 'password' => $allUsersHash], + ['id' => 18, 'name' => 'Импульс Йети', 'email' => 'reshetnick.mike+user8@gmail.com', 'password' => $allUsersHash], + ['id' => 19, 'name' => 'Квики Кекс', 'email' => 'reshetnick.mike+user9@gmail.com', 'password' => $allUsersHash], + ['id' => 20, 'name' => 'Чебурек Сочный', 'email' => 'reshetnik.n+user9@gmail.com', 'password' => $allUsersHash], + ['id' => 21, 'name' => 'Клубника Дикая', 'email' => 'reshetnik.n+user10@gmail.com', 'password' => $allUsersHash], + ['id' => 22, 'name' => 'Ляпис Лапша', 'email' => 'reshetnick.mike+user10@gmail.com', 'password' => $allUsersHash], + ['id' => 23, 'name' => 'Друг Парадоксов', 'email' => 'reshetnick.mike+user11@gmail.com', 'password' => $allUsersHash], ]; } } From bd26d95ced0a62eea73563dd3452d362dc8355f9 Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Thu, 7 Dec 2023 15:23:34 +0300 Subject: [PATCH 15/21] moved plan test to folder feature --- tests/{ => Feature}/Plan/CreateTest.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{ => Feature}/Plan/CreateTest.php (100%) diff --git a/tests/Plan/CreateTest.php b/tests/Feature/Plan/CreateTest.php similarity index 100% rename from tests/Plan/CreateTest.php rename to tests/Feature/Plan/CreateTest.php From 29c2adf109db0160f978a12f71fe9afe7b4e530d Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Thu, 7 Dec 2023 17:04:31 +0300 Subject: [PATCH 16/21] fixed fields plan --- app/Livewire/Plan/Create.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/Livewire/Plan/Create.php b/app/Livewire/Plan/Create.php index dc73888..ad02c5d 100644 --- a/app/Livewire/Plan/Create.php +++ b/app/Livewire/Plan/Create.php @@ -85,16 +85,16 @@ class Create extends Component $plan = new Plan(); - $this->name = $plan->name; - $this->image = $plan->image->store('plans', 'public'); - $this->duration = $plan->duration; - $this->state = $plan->state; - $this->details = $plan->details; - $this->packets_count = $plan->packets_count; - $this->type = json_encode($plan->type); - $this->packet1_options = json_encode($plan->packet1_options); - $this->packet2_options = json_encode($plan->packet2_options); - $this->packet3_options = json_encode($plan->packet3_options); + $plan->name = $this->name; + $plan->image = $this->image->store('plans', 'public'); + $plan->duration = $this->duration; + $plan->state = $this->state; + $plan->details = $this->details; + $plan->packets_count = $this->packets_count; + $plan->type = json_encode($this->type); + $plan->packet1_options = json_encode($this->packet1_options); + $plan->packet2_options = json_encode($this->packet2_options); + $plan->packet3_options = json_encode($this->packet3_options); $plan->saveOrFail(); $user = Auth::user(); $user->author_of_plans()->attach($plan->id); From 52b29346e3b2eefe2ff367f92d7f209d8d9d522a Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Fri, 8 Dec 2023 13:25:02 +0300 Subject: [PATCH 17/21] update plan create test --- database/factories/PlanFactory.php | 8 ++++-- tests/Feature/Plan/CreateTest.php | 41 ++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/database/factories/PlanFactory.php b/database/factories/PlanFactory.php index 697e274..9220ba6 100755 --- a/database/factories/PlanFactory.php +++ b/database/factories/PlanFactory.php @@ -1,6 +1,8 @@ $this->faker->text(), ]; + Storage::fake('plans'); + return [ 'name' => $this->faker->foodName(), - // 'image' => $this->faker->image('application/storage/fake_images', 640, 480, null, false), - 'image' => storage_path('public/img/Photo_C.png'), + // 'image' => UploadedFile::fake()->image('plans/Photo_C.png'), + 'image' => UploadedFile::fake()->image('plan.png'), 'duration' => $this->faker->randomElement([7, 14,21]), 'state' => $this->faker->randomElement(['active', 'draft', 'archived']), 'type' => $typeBody, diff --git a/tests/Feature/Plan/CreateTest.php b/tests/Feature/Plan/CreateTest.php index 928accc..b4609b4 100644 --- a/tests/Feature/Plan/CreateTest.php +++ b/tests/Feature/Plan/CreateTest.php @@ -1,7 +1,9 @@ get('/plan/create'); $response - ->assertOk(); + ->assertStatus(302) + ->assertRedirect('https://dev2.eatvio.com/ru'); } public function test_publish_new_plan_success(): void { $plan = Plan::factory()->make(); - $user = User::factory()->create(); + $user = User::factory()->create(['is_consultant' => true]); + + $count = $plan->count(); + $this->actingAs($user); Livewire::test(Create::class) ->set('name', $plan->name) + ->assertSet('name', $plan->name) ->set('image', $plan->image) ->set('duration', $plan->duration) ->set('state', $plan->state) @@ -45,18 +52,24 @@ class CreateTest extends TestCase ->set('packet2_options', $plan->packet2_options) ->set('packet3_options', $plan->packet3_options) ->call('publish') - ->assertRedirect('/plan/'. $plan->id); - } + // ->assertFileDownloaded('plan.png'); + ->assertStatus(200) + ->assertRedirect('plan/'.$plan->count()); + + $this->assertEquals($plan->count(), $count + 1); + } +// public function test_to_draft_new_plan_success(): void { $plan = Plan::factory()->make(); $user = User::factory()->create(); - +// $this->actingAs($user); - +// Livewire::test(Create::class) ->set('name', $plan->name) + ->assertSet('name', $plan->name) ->set('image', $plan->image) ->set('duration', $plan->duration) ->set('state', $plan->state) @@ -67,18 +80,20 @@ class CreateTest extends TestCase ->set('packet2_options', $plan->packet2_options) ->set('packet3_options', $plan->packet3_options) ->call('addToDrafts') - ->assertRedirect('/plan/'. $plan->id); + ->assertStatus(200) + ->assertRedirect('plan/'.$plan->count()); } - +// public function test_to_preview_new_plan_success(): void { $plan = Plan::factory()->make(); $user = User::factory()->create(); - +// $this->actingAs($user); - +// Livewire::test(Create::class) ->set('name', $plan->name) + ->assertSet('name', $plan->name) ->set('image', $plan->image) ->set('duration', $plan->duration) ->set('state', $plan->state) @@ -89,6 +104,10 @@ class CreateTest extends TestCase ->set('packet2_options', $plan->packet2_options) ->set('packet3_options', $plan->packet3_options) ->call('addToDrafts') - ->assertRedirect('/plan/'. $plan->id); + ->assertStatus(200) + ->assertRedirect('plan/'.$plan->count()); + + + // ->assertRedirect('/plan/'. $plan->id); } } From c8c3b5519dd94c72766030ae45ecff13828d7666 Mon Sep 17 00:00:00 2001 From: Anatoliy Poloz Date: Fri, 8 Dec 2023 14:09:59 +0300 Subject: [PATCH 18/21] WIP, plan transition fixes, WIP --- app/Http/Controllers/PlanController.php | 10 ++++++--- app/Models/Plan.php | 11 +++++++--- database/factories/PlanFactory.php | 5 ++++- database/seeders/PlanAuthor.php | 27 +++++++++++++++++++++++++ resources/views/plan/show.blade.php | 4 ++++ 5 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 database/seeders/PlanAuthor.php diff --git a/app/Http/Controllers/PlanController.php b/app/Http/Controllers/PlanController.php index 495cb18..474a66f 100644 --- a/app/Http/Controllers/PlanController.php +++ b/app/Http/Controllers/PlanController.php @@ -62,9 +62,13 @@ class PlanController extends Controller ->cooldown($expiresAt) ->record(); - $options1 = $this->unserializeOptions($plan->packet1_options); - $options2 = $this->unserializeOptions($plan->packet2_options); - $options3 = $this->unserializeOptions($plan->packet2_options); + // $options1 = $this->unserializeOptions($plan->packet1_options); + // $options2 = $this->unserializeOptions($plan->packet2_options); + // $options3 = $this->unserializeOptions($plan->packet2_options); + $options1 = $plan->packet1_options; + $options2 = $plan->packet2_options; + $options3 = $plan->packet2_options; + return view('plan/show', [ 'plan' => $plan, diff --git a/app/Models/Plan.php b/app/Models/Plan.php index 708d131..b718016 100644 --- a/app/Models/Plan.php +++ b/app/Models/Plan.php @@ -57,7 +57,9 @@ class Plan extends Model implements Viewable $result = []; for ($i = 1; $i <= $this->packets_count; $i++) { $key = "packet" . $i . "_options"; - $data = $this->unserializeOptionsObj($this->$key); + + // $data = $this->unserializeOptionsObj($this->$key); + $data = $this->$key; if (!is_null($data)) { $result = array_merge($result, data_get($data, "items", [])); } @@ -68,7 +70,8 @@ class Plan extends Model implements Viewable public function types(): Attribute { - $data = $this->unserializeOptionsArr($this->type); + // $data = $this->unserializeOptionsArr($this->type); + $data = $this->type; return new Attribute( get: fn () => array_keys($data), @@ -80,7 +83,9 @@ class Plan extends Model implements Viewable $result = 0; for ($i = 1; $i <= $this->packets_count; $i++) { $key = "packet" . $i . "_options"; - $data = $this->unserializeOptionsObj($this->$key); + // dd($this->$key); + // $data = $this->unserializeOptionsObj($this->$key); + $data = $this->$key; if (!is_null($data)) { $curPrice = (int)data_get($data, "price", 0); $result = $curPrice > $result ? $curPrice : $result ; diff --git a/database/factories/PlanFactory.php b/database/factories/PlanFactory.php index 9220ba6..a87d4b4 100755 --- a/database/factories/PlanFactory.php +++ b/database/factories/PlanFactory.php @@ -19,6 +19,7 @@ class PlanFactory extends Factory */ public function definition(): array { + $faker = \Faker\Factory::create(); $this->faker->addProvider(new Restaurant($faker)); @@ -37,11 +38,13 @@ class PlanFactory extends Factory ]; Storage::fake('plans'); + $file = UploadedFile::fake()->image('plan.png'); + $fileLocalPath = $file->store('plans', 'public'); return [ 'name' => $this->faker->foodName(), // 'image' => UploadedFile::fake()->image('plans/Photo_C.png'), - 'image' => UploadedFile::fake()->image('plan.png'), + 'image' => $fileLocalPath, 'duration' => $this->faker->randomElement([7, 14,21]), 'state' => $this->faker->randomElement(['active', 'draft', 'archived']), 'type' => $typeBody, diff --git a/database/seeders/PlanAuthor.php b/database/seeders/PlanAuthor.php new file mode 100644 index 0000000..805280a --- /dev/null +++ b/database/seeders/PlanAuthor.php @@ -0,0 +1,27 @@ + 0 && Plan::count() > 0) { + Plan::each( function ($plan) { + User::inRandomOrder() + ->first() + ->author_of_plans() + ->attach($plan->id); + }); + } + } +} diff --git a/resources/views/plan/show.blade.php b/resources/views/plan/show.blade.php index 29a1f2d..473264f 100644 --- a/resources/views/plan/show.blade.php +++ b/resources/views/plan/show.blade.php @@ -2,6 +2,10 @@ @php $author = $plan->author()->first(); $authorPhoto = Storage::url($author->profile_photo_path); + if(is_null($author->profile_photo_path)) { + $authorPhoto =$author->profile_photo_url; + } + $image = Storage::url($plan->image); $planViewsCount = views($plan)->unique()->count(); @endphp From 8ba6737fdc13cd17c603a5cc4fe3122b39a6d946 Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Fri, 8 Dec 2023 16:27:21 +0300 Subject: [PATCH 19/21] fixed error image in createTest --- tests/Feature/Plan/CreateTest.php | 137 +++++++++++++++++------------- 1 file changed, 79 insertions(+), 58 deletions(-) diff --git a/tests/Feature/Plan/CreateTest.php b/tests/Feature/Plan/CreateTest.php index b4609b4..ce132e2 100644 --- a/tests/Feature/Plan/CreateTest.php +++ b/tests/Feature/Plan/CreateTest.php @@ -1,6 +1,8 @@ image = UploadedFile::fake()->image('plan.png'); + + $this->user = User::factory()->create(['is_consultant' => true]); + $this->plan = Plan::factory()->make(); + + } + public function test_show_form_create_plan() { - $user = User::factory()->create(); - - $response = $this->actingAs($user) + $response = $this->actingAs($this->user) ->get('/plan/create'); $response @@ -31,83 +47,88 @@ class CreateTest extends TestCase public function test_publish_new_plan_success(): void { - $plan = Plan::factory()->make(); - $user = User::factory()->create(['is_consultant' => true]); + $countPlanBeforeCreated = $this->plan->count(); - $count = $plan->count(); - - - $this->actingAs($user); + $this->actingAs($this->user); Livewire::test(Create::class) - ->set('name', $plan->name) - ->assertSet('name', $plan->name) - ->set('image', $plan->image) - ->set('duration', $plan->duration) - ->set('state', $plan->state) - ->set('type', $plan->type) - ->set('details', $plan->details) - ->set('packets_count', $plan->packets_count) - ->set('packet1_options', $plan->packet1_options) - ->set('packet2_options', $plan->packet2_options) - ->set('packet3_options', $plan->packet3_options) + ->set('name', $this->plan->name) + ->assertSet('name', $this->plan->name) + ->set('image', $this->image) + ->set('duration', $this->plan->duration) + ->set('state', $this->plan->state) + ->set('type', $this->plan->type) + ->set('details', $this->plan->details) + ->set('packets_count', $this->plan->packets_count) + ->set('packet1_options', $this->plan->packet1_options) + ->set('packet2_options', $this->plan->packet2_options) + ->set('packet3_options', $this->plan->packet3_options) ->call('publish') // ->assertFileDownloaded('plan.png'); ->assertStatus(200) - ->assertRedirect('plan/'.$plan->count()); + ->assertRedirect('plan/'.$this->plan->count()); + + $countPlanAfterCreated = $this->plan->count(); - $this->assertEquals($plan->count(), $count + 1); + $this->assertEquals($countPlanBeforeCreated + 1, $countPlanAfterCreated); } // public function test_to_draft_new_plan_success(): void { - $plan = Plan::factory()->make(); - $user = User::factory()->create(); -// - $this->actingAs($user); -// + $countPlanBeforeCreated = $this->plan->count(); + + $this->actingAs($this->user); + Livewire::test(Create::class) - ->set('name', $plan->name) - ->assertSet('name', $plan->name) - ->set('image', $plan->image) - ->set('duration', $plan->duration) - ->set('state', $plan->state) - ->set('type', $plan->type) - ->set('details', $plan->details) - ->set('packets_count', $plan->packets_count) - ->set('packet1_options', $plan->packet1_options) - ->set('packet2_options', $plan->packet2_options) - ->set('packet3_options', $plan->packet3_options) + ->set('name', $this->plan->name) + ->assertSet('name', $this->plan->name) + ->set('image', $this->image) + ->set('duration', $this->plan->duration) + ->set('state', $this->plan->state) + ->set('type', $this->plan->type) + ->set('details', $this->plan->details) + ->set('packets_count', $this->plan->packets_count) + ->set('packet1_options', $this->plan->packet1_options) + ->set('packet2_options', $this->plan->packet2_options) + ->set('packet3_options', $this->plan->packet3_options) ->call('addToDrafts') + // ->assertFileDownloaded('plan.png'); ->assertStatus(200) - ->assertRedirect('plan/'.$plan->count()); + ->assertRedirect('plan/'.$this->plan->count()); + + $countPlanAfterCreated = $this->plan->count(); + + $this->assertEquals($countPlanBeforeCreated + 1, $countPlanAfterCreated); } // public function test_to_preview_new_plan_success(): void { - $plan = Plan::factory()->make(); - $user = User::factory()->create(); -// - $this->actingAs($user); -// + + $countPlanBeforeCreated = $this->plan->count(); + + $this->actingAs($this->user); + Livewire::test(Create::class) - ->set('name', $plan->name) - ->assertSet('name', $plan->name) - ->set('image', $plan->image) - ->set('duration', $plan->duration) - ->set('state', $plan->state) - ->set('type', $plan->type) - ->set('details', $plan->details) - ->set('packets_count', $plan->packets_count) - ->set('packet1_options', $plan->packet1_options) - ->set('packet2_options', $plan->packet2_options) - ->set('packet3_options', $plan->packet3_options) - ->call('addToDrafts') + ->set('name', $this->plan->name) + ->assertSet('name', $this->plan->name) + ->set('image', $this->image) + ->set('duration', $this->plan->duration) + ->set('state', $this->plan->state) + ->set('type', $this->plan->type) + ->set('details', $this->plan->details) + ->set('packets_count', $this->plan->packets_count) + ->set('packet1_options', $this->plan->packet1_options) + ->set('packet2_options', $this->plan->packet2_options) + ->set('packet3_options', $this->plan->packet3_options) + ->call('showPreview') + // ->assertFileDownloaded('plan.png'); ->assertStatus(200) - ->assertRedirect('plan/'.$plan->count()); + ->assertRedirect('plan/'.$this->plan->count()); + $countPlanAfterCreated = $this->plan->count(); - // ->assertRedirect('/plan/'. $plan->id); + $this->assertEquals($countPlanBeforeCreated + 1, $countPlanAfterCreated); } + } From ed24c3e1043d0c0cdaf47a1275a890660b85a51c Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Fri, 8 Dec 2023 16:45:37 +0300 Subject: [PATCH 20/21] added presenter package --- composer.json | 1 + composer.lock | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c8acd01..69c81d6 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ "guzzlehttp/guzzle": "^7.2", "iben12/laravel-statable": "^1.5", "jzonta/faker-restaurant": "^2.0", + "laracasts/presenter": "^0.2.6", "laravel/framework": "^10.0", "laravel/jetstream": "^4.0", "laravel/sanctum": "^3.2", diff --git a/composer.lock b/composer.lock index 910ad95..301c7ef 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d583b5e56204b55c62acc30999b7d1f5", + "content-hash": "2e254ae7b37d7841970bf3a2a4f56d80", "packages": [ { "name": "asantibanez/livewire-charts", @@ -2136,6 +2136,56 @@ }, "time": "2021-11-15T11:21:22+00:00" }, + { + "name": "laracasts/presenter", + "version": "0.2.6", + "source": { + "type": "git", + "url": "https://github.com/laracasts/Presenter.git", + "reference": "4353fb5a1a3b9b9073db66fd823eaaf04c0c5db0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laracasts/Presenter/zipball/4353fb5a1a3b9b9073db66fd823eaaf04c0c5db0", + "reference": "4353fb5a1a3b9b9073db66fd823eaaf04c0c5db0", + "shasum": "" + }, + "require": { + "illuminate/support": "~5.0|~6.0|~7.0|~8.0|^9.0|^10.0", + "php": ">=5.4.0" + }, + "require-dev": { + "mockery/mockery": "~0.9", + "phpspec/phpspec": "~2.0" + }, + "type": "library", + "autoload": { + "psr-0": { + "Laracasts\\Presenter": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jeffrey Way", + "email": "jeffrey@laracasts.com" + } + ], + "description": "Simple view presenters", + "keywords": [ + "laravel", + "presenter", + "view" + ], + "support": { + "issues": "https://github.com/laracasts/Presenter/issues", + "source": "https://github.com/laracasts/Presenter/tree/0.2.6" + }, + "time": "2023-02-21T16:06:10+00:00" + }, { "name": "laravel/fortify", "version": "v1.17.5", From dfc6b7b5c814aac6519600195adc73cac0f5e4cc Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Mon, 11 Dec 2023 11:35:07 +0300 Subject: [PATCH 21/21] 'Added Plan presenter' --- app/Models/Plan.php | 7 +++++++ app/Presenters/PlanPresenter.php | 22 ++++++++++++++++++++++ resources/views/plan/index.blade.php | 2 +- resources/views/plan/show.blade.php | 9 ++++----- 4 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 app/Presenters/PlanPresenter.php diff --git a/app/Models/Plan.php b/app/Models/Plan.php index b718016..20a25d3 100644 --- a/app/Models/Plan.php +++ b/app/Models/Plan.php @@ -1,11 +1,13 @@ belongsToMany(User::class, 'plan_author', 'plan_id', 'user_id'); diff --git a/app/Presenters/PlanPresenter.php b/app/Presenters/PlanPresenter.php new file mode 100644 index 0000000..85fcf1e --- /dev/null +++ b/app/Presenters/PlanPresenter.php @@ -0,0 +1,22 @@ +getAuthor(); + + return Storage::url($author->profile_photo_path); + } + + public function getAuthor() + { + return $this->author->first(); + } +} diff --git a/resources/views/plan/index.blade.php b/resources/views/plan/index.blade.php index 14803f2..c0790fe 100644 --- a/resources/views/plan/index.blade.php +++ b/resources/views/plan/index.blade.php @@ -49,7 +49,7 @@
    @php - $author = $plan->author()->first(); + $author = $plan->present()->getAuthor; @endphp diff --git a/resources/views/plan/show.blade.php b/resources/views/plan/show.blade.php index 473264f..ca3913f 100644 --- a/resources/views/plan/show.blade.php +++ b/resources/views/plan/show.blade.php @@ -1,10 +1,9 @@ @extends('layouts/eatvio') @php - $author = $plan->author()->first(); - $authorPhoto = Storage::url($author->profile_photo_path); - if(is_null($author->profile_photo_path)) { - $authorPhoto =$author->profile_photo_url; - } + + $author = $plan->present()->getAuthor; + + $authorPhoto = $plan->present()->getAuthorPhoto; $image = Storage::url($plan->image); $planViewsCount = views($plan)->unique()->count();