From 99f0bafe93492a003091b9bb2ba58cb5a5aee4b6 Mon Sep 17 00:00:00 2001 From: Kamil Niemczycki Date: Tue, 4 Jul 2023 01:12:05 +0200 Subject: [PATCH] - append more informations from api --- app/Console/Commands/CVInfo.php | 2 ++ app/Console/Commands/CreateCV.php | 8 ++++++- app/Console/Commands/ListCV.php | 2 +- app/Console/Commands/UpdateCV.php | 11 ++++++++- app/Http/Resources/CVResource.php | 8 +++++++ app/Models/CV.php | 2 ++ ..._07_03_194110_add_mission_to_cvs_table.php | 24 +++++++++++++++++++ ...023_07_03_205727_add_rodo_to_cvs_table.php | 24 +++++++++++++++++++ 8 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2023_07_03_194110_add_mission_to_cvs_table.php create mode 100644 database/migrations/2023_07_03_205727_add_rodo_to_cvs_table.php diff --git a/app/Console/Commands/CVInfo.php b/app/Console/Commands/CVInfo.php index dcd6781..5aa674a 100644 --- a/app/Console/Commands/CVInfo.php +++ b/app/Console/Commands/CVInfo.php @@ -27,6 +27,8 @@ class CVInfo extends Command $this->line('Phone: '. $cv->formattedPhoneNumber .', '. $cv->PhoneNumber); $this->line('Locations: '. implode(' / ', $cv->locations)); $this->line('Views: '. $cv->views); + $this->line('Mission: '. (is_null($mission = $cv->mission) ? 'domyślne' : $mission)); + $this->line('Rodo: '. (is_null($rodo = $cv->rodo) ? 'domyślne' : $rodo)); $this->line(''); $this->line('Showed list:'); diff --git a/app/Console/Commands/CreateCV.php b/app/Console/Commands/CreateCV.php index 084fd04..ed8b26d 100644 --- a/app/Console/Commands/CreateCV.php +++ b/app/Console/Commands/CreateCV.php @@ -15,7 +15,9 @@ class CreateCV extends Command {recipient : Company} {email : E-mail address} {phone : Phone number - with spaces} - {location?* : List of locations}'; + {location?* : List of locations} + {--mission= : Description of mission} + {--rodo= : Description of rodo}'; protected $description = 'Create CV'; @@ -25,6 +27,8 @@ class CreateCV extends Command $email = $this->argument('email'); $phone = $this->argument('phone'); $locations = $this->argument('location'); + $mission = $this->option('mission'); + $rodo = $this->option('rodo'); CV::query() ->create([ @@ -33,6 +37,8 @@ class CreateCV extends Command 'email' => $email, 'phone_number' => $phone, 'locations' => $locations, + 'mission' => $mission, + 'rodo' => $rodo, ]); $this->info('Created!'); diff --git a/app/Console/Commands/ListCV.php b/app/Console/Commands/ListCV.php index 01d3314..8d47db3 100644 --- a/app/Console/Commands/ListCV.php +++ b/app/Console/Commands/ListCV.php @@ -26,7 +26,7 @@ class ListCV extends Command $this->line('Company: '. $resource->recipient); $this->line('Phone: '. $resource->formattedPhoneNumber .', '. $resource->PhoneNumber); $this->line('Locations: '. implode(' / ', $resource->locations)); - $this->line('Views: '. $resource->views); + $this->line('Rodo: '. $resource->rodo); $this->line(''); } diff --git a/app/Console/Commands/UpdateCV.php b/app/Console/Commands/UpdateCV.php index ec550ff..4e51522 100644 --- a/app/Console/Commands/UpdateCV.php +++ b/app/Console/Commands/UpdateCV.php @@ -15,7 +15,9 @@ class UpdateCV extends Command {--phone= : Phone number} {--begin-location : Add begin} {--add-location=* : Add locations} - {--remove-location=* : Remove lcoations}'; + {--remove-location=* : Remove lcoations} + {--mission= : Set new text value} + {--rodo= : Set new text value}'; protected $description = 'Update CV element'; @@ -58,6 +60,13 @@ class UpdateCV extends Command $cv->locations = $locations; } + if ($mission = $this->option('mission')) { + $cv->mission = $mission === 'null' ? null : $mission; + } + if ($rodo = $this->option('rodo')) { + $cv->rodo = $rodo === 'null' ? null : $rodo; + } + $cv->save(); $this->info('Updated!'); diff --git a/app/Http/Resources/CVResource.php b/app/Http/Resources/CVResource.php index 6b6881f..7ba2b6e 100644 --- a/app/Http/Resources/CVResource.php +++ b/app/Http/Resources/CVResource.php @@ -19,6 +19,14 @@ class CVResource extends JsonResource 'formattedPhoneNumber' => $this->formattedPhoneNumber, 'phone' => new PhoneResource($this->resource), 'locations' => $this->locations, + 'mission' => $this->when( + !is_null($this->mission), + fn (): array => explode(PHP_EOL, $this->mission, 5) + ), + 'rodo' => $this->when( + !is_null($this->rodo), + $this->rodo + ), ]; } } diff --git a/app/Models/CV.php b/app/Models/CV.php index 669472a..b1547e7 100644 --- a/app/Models/CV.php +++ b/app/Models/CV.php @@ -16,6 +16,8 @@ use Illuminate\Database\Eloquent\Relations\HasMany; * @property string $email * @property string $phoneNumber * @property array $locations + * @property string|null $mission + * @property string|null $rodo * @property int $views */ class CV extends Model diff --git a/database/migrations/2023_07_03_194110_add_mission_to_cvs_table.php b/database/migrations/2023_07_03_194110_add_mission_to_cvs_table.php new file mode 100644 index 0000000..f32de4c --- /dev/null +++ b/database/migrations/2023_07_03_194110_add_mission_to_cvs_table.php @@ -0,0 +1,24 @@ +text('mission')->nullable(); + }); + } + + public function down(): void + { + Schema::table('cvs', function (Blueprint $table) { + $table->dropColumn('mission'); + }); + } +}; diff --git a/database/migrations/2023_07_03_205727_add_rodo_to_cvs_table.php b/database/migrations/2023_07_03_205727_add_rodo_to_cvs_table.php new file mode 100644 index 0000000..0f1c7f4 --- /dev/null +++ b/database/migrations/2023_07_03_205727_add_rodo_to_cvs_table.php @@ -0,0 +1,24 @@ +text('rodo')->nullable(); + }); + } + + public function down(): void + { + Schema::table('cvs', function (Blueprint $table) { + $table->dropColumn('rodo'); + }); + } +};