-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCheckinController.php
More file actions
92 lines (80 loc) · 2.46 KB
/
CheckinController.php
File metadata and controls
92 lines (80 loc) · 2.46 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
namespace App\Http\Controllers;
use App\Http\Resources\TicketResource;
use App\Models\Checkin;
use App\Http\Requests\StoreCheckinRequest;
use App\Http\Requests\UpdateCheckinRequest;
use App\Models\Event;
use App\Models\Ticket;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Auth;
use Ramsey\Uuid\Uuid;
class CheckinController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(StoreCheckinRequest $request, string $event_uuid): JsonResponse
{
$args = $request->validated();
$event = Event::where('uuid', $event_uuid)
->firstOrFail();
$ticket = Ticket::where('event_id', $event->id)
->where('ticket_nonce', Uuid::fromString($args['ticket_code'])
->getBytes())
->where('asset_id', $args['asset_id'])
->withCount(['checkins', 'checkouts'])
->firstOrFail();
if ($ticket->checkins_count !== $ticket->checkouts_count) {
// The only way this should exist is when a ticket has been checked in
// already and has never been checked out. You can't check-in a ticket
// twice!!!
// TODO: Add ability to scan a ticket multiple times to potentially handle
// a situation where we want to track a ticket holder's movement
// throughout an event
return response()->json([
'message' => 'Ticket has already been checked in!'
], 400);
}
// Since we've arrive here it is probably safe to insert the "checkin"
// record now
$checkin = new Checkin();
$checkin->ticket()
->associate($ticket);
$checkin->user()
->associate(Auth::user());
$checkin->save();
$checkin->setVisible([
'id'
]);
return response()->json($checkin);
}
/**
* Display the specified resource.
*/
public function show(Checkin $checkin)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(UpdateCheckinRequest $request, Checkin $checkin)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Checkin $checkin)
{
//
}
}