aboutsummaryrefslogtreecommitdiffstats
path: root/source/app/Services/MailService.php
blob: 1068c49d84ad96626c68ad2b9a91061d5445f1f5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php

namespace App\Services;


use App\Mail\AppointmentMail;
use App\Mail\CompanyAccountCreation;
use App\Mail\StudentProfileVerification;
use App\Mail\StudentResetPassword;
use App\Models\Appointment;
use App\Models\Company;
use App\Models\Student;
use GuzzleHttp\Exception\TransferException;
use Illuminate\Support\Facades\Mail;
use Symfony\Component\Mailer\Exception\TransportException;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;

// controllers dienen voor het maken van routes
// services dat een logische bewerking encapsuleert en die dan implementeert
class MailService
{
    public function sendStudentVerification(Student $student, LogService $logService): void
    {
        try {
            Mail::to($student->email)->send(new StudentProfileVerification($student));
            // gebruikte hiervoor de gewone exception maar voor mail dinges is transportexceptioninterface
        } catch (TransportException $e) {
            $logService->setLog("Student", $student->id, $e, "Student");
        }
    }

    public function sendAppointmentConfirmation(Appointment $appointment, LogService $logService): void
    {
        try {
            Mail::to($appointment->student->email)->send(new AppointmentMail($appointment));
        } catch (TransportException $e) {
            $logService->setLog("Student", $appointment->student_id, $e, "Appointment");
        }
    }

    public function sendCompanyAccountVerification(Company $company, LogService $logService): void
    {
        try {
            Mail::to($company->email)->send(new CompanyAccountCreation($company));
        } catch (TransferException $e) {
            $logService->setLog("Company", $company->id, $e, "Company");
        }

    }

    public function sendStudentPasswordReset(Student $student): void
    {
        try {
            Mail::to($student->email)->send(new StudentResetPassword($student));
        } catch (TransportExceptionInterface $e) {

        }
    }
}