fix: working copy, caching ASP, notworking orders though
This commit is contained in:
parent
dc5d204cfc
commit
390ad23e03
32 changed files with 246 additions and 194 deletions
|
@ -112,3 +112,47 @@ Route::delete('/user/{id}/assignment', function ($id) {
|
|||
$user->save();
|
||||
return $user->cinemas;
|
||||
})->name('api.user.assignment');
|
||||
|
||||
// POST /api/order
|
||||
Route::middleware('auth:sanctum')->post('/order', function (Request $request) {
|
||||
// [0] showing = showing_id
|
||||
// [1] seats = [{seat: seat_id, price: price_id}, ...]
|
||||
|
||||
// check user
|
||||
if ($request->user()->exists()) {
|
||||
return response()->json(['error' => 'user not logged in'], 400);
|
||||
}
|
||||
|
||||
if (!isset($request->showing) || !isset($request->seats)) { // check if user is logged in and showings and seats are set
|
||||
return response()->json(['error' => 'showing or seats not set'], 400);
|
||||
}
|
||||
|
||||
if ($request->user()->addresses()->count() == 0) { // check if user has an address
|
||||
return response()->json(['error' => 'no address set'], 400);
|
||||
}
|
||||
|
||||
$order = (new App\Models\Order)->create([
|
||||
'user_id' => $request->user()->user_id,
|
||||
'order_number' => substr(str_shuffle(str_repeat($x = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil(10 / strlen($x)))), 1, 10),
|
||||
'order_status' => 'pending',
|
||||
'billing_address_id' => Auth::user()->address()->address_id
|
||||
]);
|
||||
$order->save();
|
||||
|
||||
// create tickets for each seat
|
||||
foreach ($request->seats as $seat) {
|
||||
Log::info('Creating ticket for seat ' . $seat['seat']);
|
||||
$ticket = (new App\Models\Ticket)->create([
|
||||
'seat_id' => $seat['seat'],
|
||||
'price_id' => $seat['price'],
|
||||
'showing_id' => $request->showing,
|
||||
'order_id' => $order->order_id,
|
||||
'user_id' => $request->user()->user_id
|
||||
]);
|
||||
$ticket->save();
|
||||
}
|
||||
|
||||
Log::info('Order created: ' . $order->order_number);
|
||||
|
||||
return $order;
|
||||
})->name('api.order');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue