51 - Green with Feature Envy

This commit is contained in:
Adam Wathan
2016-12-15 17:51:45 -05:00
parent d3b19b31ab
commit 4efdc94e2f
5 changed files with 22 additions and 27 deletions

View File

@@ -37,7 +37,7 @@ class ConcertOrdersController extends Controller
$this->paymentGateway->charge($reservation->totalCost(), request('payment_token'));
// Create an order for those tickets
$order = Order::forTickets($reservation->tickets(), $reservation->email(), $reservation->totalCost());
$order = $reservation->complete();
return response()->json($order, 201);

View File

@@ -22,18 +22,6 @@ class Order extends Model
return $order;
}
public static function fromReservation($reservation)
{
$order = self::create([
'email' => $reservation->email(),
'amount' => $reservation->totalCost(),
]);
$order->tickets()->saveMany($reservation->tickets());
return $order;
}
public function concert()
{
return $this->belongsTo(Concert::class);

View File

@@ -28,6 +28,11 @@ class Reservation
return $this->email;
}
public function complete()
{
return Order::forTickets($this->tickets(), $this->email(), $this->totalCost());
}
public function cancel()
{
foreach ($this->tickets as $ticket) {