- add CV management

This commit is contained in:
2023-06-16 13:41:39 +02:00
parent 9518d6a811
commit 390c5b8087
8 changed files with 173 additions and 3 deletions

View File

@@ -28,13 +28,15 @@ class CreateCV extends Command
CV::query()
->create([
// 'slug' => Str::ra,
'token' => Str::random(50),
'recipient' => $recipient,
'email' => $email,
'phone-number' => $phone,
'phone_number' => $phone,
'locations' => $locations,
]);
$this->info('Created!');
return CommandAlias::SUCCESS;
}
}

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace App\Console\Commands;
use App\Http\Resources\CVResource;
use App\Models\CV;
use Illuminate\Console\Command;
class ListCV extends Command
{
protected $signature = 'cv:list';
protected $description = 'List of CV';
public function handle(): int
{
$cvList = CV::all();
/** @var CV $cv */
foreach ($cvList as $cv) {
$resource = new CVResource($cv);
$this->line('ID: '. $resource->id);
$this->line('Token: '. $resource->token);
$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('');
}
return Command::SUCCESS;
}
}

View File

@@ -0,0 +1,67 @@
<?php
declare(strict_types=1);
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\CV;
class UpdateCV extends Command
{
protected $signature = 'cv:update
{id : ID CV element}
{--company= : Company name}
{--phone= : Phone number}
{--begin-location : Add begin}
{--add-location=* : Add locations}
{--remove-location=* : Remove lcoations}';
protected $description = 'Update CV element';
public function handle(): int
{
if (! ($id = $this->argument('id')) || $id <= 0) {
$this->error('Incorrect id');
return Command::FAILURE;
}
$cv = CV::find($id);
if ($company = $this->option('company')) {
$cv->recipient = $company;
}
if ($phone = $this->option('phone')) {
$cv->phone_number = $phone;
}
if (count($addLocations = $this->option('remove-location')) > 0) {
$locations = $cv->locations;
$locations = array_diff($locations, $addLocations);
$cv->locations = $locations;
}
if (count($addLocations = $this->option('add-location')) > 0) {
$locations = $cv->locations;
$clearLocations = [];
foreach ($addLocations as $location) {
if (in_array($location, $locations)) {
$this->warn('"'. $location .'" exists! This value was not added.');
$clearLocations[] = $location;
}
}
$addLocations = array_diff($addLocations, $clearLocations);
if ($this->option('begin-location'))
$locations = array_merge($addLocations, $locations);
else
$locations = array_merge($locations, $addLocations);
$cv->locations = $locations;
}
$cv->save();
$this->info('Updated!');
return Command::SUCCESS;
}
}