aboutsummaryrefslogtreecommitdiffstats
path: root/source/app/Http/Controllers/AppointmentController.php
blob: ae0615efaece49c09ab2b29906279a47502a4016 (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
60
<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Http;
use Illuminate\Http\Request;

class AppointmentController extends Controller
{
    //apiUrls in parent class

    //Make an appointment
    function store(Request $request) {
        try {
            $validated = $request->validate([
                'student_id' => 'required|integer',
                'company_id' => 'required|integer',
                'time_slot' => 'required|string|max:100'
            ]);
        } catch (\Exception $e) {
            return redirect()->back()->with('error', 'Er is een fout opgetreden bij het maken van de afspraak: ' . $e->getMessage());
        }
        try {
            $response = Http::post($this->appointmentApiUrl, $validated);

            return redirect()->back()->with('success', 'Afspraak succesvol gemaakt!');

        } catch (\Exception $e) {
            return redirect()->back()->with('error', 'Er is een fout opgetreden: ' . $e->getMessage());
        }
    }
    function update(Request $request, $id) {
        try {
            $validated = $request->validate([
                'time_slot' => 'required|string|max:100'
            ]);
        } catch (\Exception $e) {
            return redirect()->back()->with('error', 'Er is een fout opgetreden bij het bijwerken van de afspraak: ' . $e->getMessage());
        }
        try {
            $response = Http::put("{$this->appointmentApiUrl}/{$id}", $validated);

            return redirect()->back()->with('success', 'Afspraak succesvol bijgewerkt!');

        } catch (\Exception $e) {
            return redirect()->back()->with('error', 'Er is een fout opgetreden: ' . $e->getMessage());
        }
    }
    function destroy($id) {
        try {
            $response = Http::delete("{$this->appointmentApiUrl}/{$id}");

            return redirect()->back()->with('success', 'Afspraak succesvol verwijderd!');

        } catch (\Exception $e) {
            return redirect()->back()->with('error', 'Er is een fout opgetreden: ' . $e->getMessage());
        }
    }
}