diff --git a/backend/app/Http/Controllers/InternshipStatusController.php b/backend/app/Http/Controllers/InternshipStatusController.php index f02784b..c3f30c8 100644 --- a/backend/app/Http/Controllers/InternshipStatusController.php +++ b/backend/app/Http/Controllers/InternshipStatusController.php @@ -2,10 +2,12 @@ namespace App\Http\Controllers; +use App\Mail\InternshipStatusUpdated; use App\Models\Internship; use App\Models\InternshipStatus; use App\Models\User; use Illuminate\Http\Request; +use Mail; class InternshipStatusController extends Controller { @@ -127,6 +129,8 @@ class InternshipStatusController extends Controller 'modified_by' => $user->id ]); + Mail::to($internship->student)->sendNow(new InternshipStatusUpdated($internship, $user->name, $internship->student->name, $internship->company->name, $internshipStatus->status, $request->status, $request->note)); + return response()->noContent(); } diff --git a/backend/app/Mail/InternshipStatusUpdated.php b/backend/app/Mail/InternshipStatusUpdated.php new file mode 100644 index 0000000..53bd204 --- /dev/null +++ b/backend/app/Mail/InternshipStatusUpdated.php @@ -0,0 +1,88 @@ +internship = $internship; + $this->changedByName = $changedByName; + $this->studentName = $studentName; + $this->companyName = $companyName; + $this->oldStatus = $oldStatus; + $this->newStatus = $newStatus; + $this->note = $note; + } + + /** + * Get the message envelope. + */ + public function envelope(): Envelope + { + return new Envelope( + subject: 'Internship Status Updated', + ); + } + + /** + * Get the message content definition. + */ + public function content(): Content + { + return new Content( + view: 'mail.internship.status_updated', + with: [ + "internship" => $this->internship, + "changedByName" => $this->changedByName, + "studentName" => $this->studentName, + "companyName" => $this->companyName, + "oldStatus" => $this->prettyStatus($this->oldStatus), + "newStatus" => $this->prettyStatus($this->newStatus), + "note" => $this->note, + ] + ); + } + + /** + * Get the attachments for the message. + * + * @return array + */ + public function attachments(): array + { + return []; + } + + private function prettyStatus(string $status): string + { + return match ($status) { + 'SUBMITTED' => 'Zadané', + 'CONFIRMED' => 'Potvrdená', + 'DENIED' => 'Zamietnutá', + 'DEFENDED' => 'Obhájená', + 'NOT_DEFENDED' => 'Neobhájená', + default => throw new \Exception("Invalid status: $status") + }; + } +} diff --git a/backend/app/Models/Internship.php b/backend/app/Models/Internship.php index 4974156..82dcd51 100644 --- a/backend/app/Models/Internship.php +++ b/backend/app/Models/Internship.php @@ -40,6 +40,11 @@ class Internship extends Model ]; } + public function student() + { + return $this->belongsTo(User::class, 'user_id'); + } + public function company() { return $this->belongsTo(Company::class, 'company_id'); diff --git a/backend/resources/views/mail/internship/status_updated.blade.php b/backend/resources/views/mail/internship/status_updated.blade.php new file mode 100644 index 0000000..1b9b960 --- /dev/null +++ b/backend/resources/views/mail/internship/status_updated.blade.php @@ -0,0 +1,14 @@ +@include("parts.header") +

Vážená/ý {{ $studentName }},

+

stav vašej praxe vo firme {{ $companyName }} bola aktualizovaná zo stavu "{{ $oldStatus }}" na + "{{ $newStatus }}".

+

Zmenu vykonal {{ $changedByName }}.

+
+ +

Poznámka: {{ $note }}.

+ +
+ +

s pozdravom

+

Systém ISOP UKF

+@include("parts.footer") \ No newline at end of file diff --git a/frontend/app/components/InternshipStatusEditor.vue b/frontend/app/components/InternshipStatusEditor.vue index 2d594fd..a975be5 100644 --- a/frontend/app/components/InternshipStatusEditor.vue +++ b/frontend/app/components/InternshipStatusEditor.vue @@ -61,6 +61,9 @@ async function submit() {