5.2 - Removing the Need to Cancel Orders

This commit is contained in:
Adam Wathan
2016-11-17 14:21:35 -05:00
parent bb6944e63b
commit e0f49677d8
2 changed files with 19 additions and 7 deletions

View File

@@ -52,15 +52,26 @@ class Concert extends Model
public function orderTickets($email, $ticketQuantity)
{
$tickets = $this->tickets()->available()->take($ticketQuantity)->get();
$tickets = $this->findTickets($ticketQuantity);
return $this->createOrder($email, $tickets);
}
if ($tickets->count() < $ticketQuantity) {
public function findTickets($quantity)
{
$tickets = $this->tickets()->available()->take($quantity)->get();
if ($tickets->count() < $quantity) {
throw new NotEnoughTicketsException;
}
return $tickets;
}
public function createOrder($email, $tickets)
{
$order = $this->orders()->create([
'email' => $email,
'amount' => $ticketQuantity * $this->ticket_price,
'amount' => $tickets->count() * $this->ticket_price,
]);
foreach ($tickets as $ticket) {