diff --git a/app/Http/Controllers/Dashboard/CVController.php b/app/Http/Controllers/Dashboard/CVController.php index c123a68..8582ba1 100644 --- a/app/Http/Controllers/Dashboard/CVController.php +++ b/app/Http/Controllers/Dashboard/CVController.php @@ -56,6 +56,17 @@ class CVController extends Controller ->with('success', 'Utworzono nowe CV dla firmy ' . $request->get('recipient')); } + public function updateSendStatus(CV $cv): RedirectResponse + { + $cv->update([ + 'sended' => true, + 'sended_timestamp' => now() + ]); + return redirect() + ->route('admin.cv.show', ['cv' => $cv]) + ->with('success', 'Status wysłania ustawiono jako "wysłano".'); + } + public function edit(CV $cv): InertiaResponse { return inertia('CV/Edit', [ @@ -65,16 +76,30 @@ class CVController extends Controller public function update(CVRequest $request, CV $cv): RedirectResponse { - $cv->update([ - 'recipient' => $request->get('recipient'), - 'email' => $request->get('email'), - 'phone_number' => $request->get('phone_number'), - 'locations' => ($locations = $request->get('locations')) === [''] ? [] : $locations, - 'mission' => ($mission = $request->get('mission')) === [''] ? [] : $mission, - 'rodo' => ($rodo =$request->get('rodo')) === '' ? null : $rodo, - 'position' => $request->get('position'), - 'notes' => $request->get('notes'), + $toUpdate = [ + 'recipient' => $request->get('recipient'), + 'email' => $request->get('email'), + 'phone_number' => $request->get('phone_number'), + 'locations' => ($locations = $request->get('locations')) === [''] ? [] : $locations, + 'mission' => ($mission = $request->get('mission')) === [''] ? [] : $mission, + 'rodo' => ($rodo =$request->get('rodo')) === '' ? null : $rodo, + 'position' => $request->get('position'), + 'notes' => $request->get('notes'), + ]; + + if ($cv->sended && ! $request->boolean('sended')) { + $toUpdate = array_merge($toUpdate, [ + 'sended' => false, + 'sended_timestamp' => null, ]); + } else if (! $cv->sended && $request->boolean('sended')) { + $toUpdate = array_merge($toUpdate, [ + 'sended' => true, + 'sended_timestamp' => now(), + ]); + } + + $cv->update($toUpdate); return redirect() ->back() ->with('success', 'Zaktualizowano CV dla firmy ' . $request->get('recipient')); diff --git a/app/Http/Requests/CVRequest.php b/app/Http/Requests/CVRequest.php index a617910..cb5b366 100644 --- a/app/Http/Requests/CVRequest.php +++ b/app/Http/Requests/CVRequest.php @@ -19,6 +19,19 @@ class CVRequest extends FormRequest 'rodo' => 'nullable|string', 'position' => 'nullable|string', 'notes' => 'nullable|string', + 'sended' => 'nullable|boolean', ]; } + + protected function prepareForValidation(): void + { + $this->merge([ + 'sended' => $this->toBoolean($this->sended), + ]); + } + + private function toBoolean($booleable): bool + { + return filter_var($booleable, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); + } } diff --git a/app/Http/Requests/ProjectRequest.php b/app/Http/Requests/ProjectRequest.php index c1f1d33..5801cea 100644 --- a/app/Http/Requests/ProjectRequest.php +++ b/app/Http/Requests/ProjectRequest.php @@ -23,7 +23,7 @@ class ProjectRequest extends FormRequest 'project_url' => 'nullable|string', 'project_version' => 'nullable|string', - 'description' => 'nullable|string', + 'description' => 'required|string|min:3', 'visible' => 'required|boolean' ]; } diff --git a/app/Http/Resources/FullCVResource.php b/app/Http/Resources/FullCVResource.php index fad962c..c40cf4f 100644 --- a/app/Http/Resources/FullCVResource.php +++ b/app/Http/Resources/FullCVResource.php @@ -21,6 +21,10 @@ class FullCVResource extends JsonResource 'locations' => $this->locations, 'views' => $this->resource->info()->select('id')->get()->count(), 'registeredViews' => $this->views, + 'sended' => [ + 'status' => $this->sended, + 'datetime' => $this->sended_timestamp?->format('d-m-Y H:i:s'), + ], 'position' => $this->position, 'mission' => explode(PHP_EOL, $this->mission ?? '', 5), 'rodo' => $this->rodo, diff --git a/app/Models/CV.php b/app/Models/CV.php index 94c0bd0..8498d1a 100644 --- a/app/Models/CV.php +++ b/app/Models/CV.php @@ -21,6 +21,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany; * @property string|null $position * @property string|null $notes * @property int $views + * @property bool $sended */ class CV extends Model { @@ -31,6 +32,8 @@ class CV extends Model protected $casts = [ 'locations' => 'array', 'views' => 'integer', + 'sended' => 'boolean', + 'sended_timestamp' => 'datetime', ]; protected function phoneNumber(): Attribute diff --git a/database/migrations/2023_08_04_130035_add_sended_to_cvs_table.php b/database/migrations/2023_08_04_130035_add_sended_to_cvs_table.php new file mode 100644 index 0000000..6f0f6b8 --- /dev/null +++ b/database/migrations/2023_08_04_130035_add_sended_to_cvs_table.php @@ -0,0 +1,26 @@ +boolean('sended')->nullable()->default(false)->after('views'); + $table->timestamp('sended_timestamp')->nullable()->after('sended'); + }); + } + + public function down(): void + { + Schema::table('cvs', function (Blueprint $table) { + $table->dropColumn('sended'); + $table->dropColumn('sended_timestamp'); + }); + } +}; diff --git a/resources/js/Pages/CV/Edit.vue b/resources/js/Pages/CV/Edit.vue index fd5bbb8..61a7d8e 100644 --- a/resources/js/Pages/CV/Edit.vue +++ b/resources/js/Pages/CV/Edit.vue @@ -40,6 +40,7 @@ const form = useForm({ rodo: props.cv.rodo, position: props.cv.position, notes: props.cv.notes, + sended: props.cv.sended.status, }); function updateCV() { @@ -128,6 +129,12 @@ function updateCV() { v-model="form.rodo" :error="form.errors.rodo" /> +
import { computed } from 'vue'; +import { router } from '@inertiajs/inertia'; const props = defineProps({ cv: { @@ -21,6 +22,15 @@ const cvNotes = computed(() => {