mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
95 lines
2.6 KiB
PHP
95 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Bookings\ControllersLogic;
|
|
|
|
use App\Http\Resources\BookingResource;
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
|
|
use App\Classes\Modules\Bookings\Services\FetchesBooking;
|
|
|
|
use App\Classes\Modules\Bookings\Standards\Rules\CanUpdateBooking;
|
|
use App\Classes\Modules\Bookings\Services\UpdatesBooking;
|
|
use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject;
|
|
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class UpdateBookingRecipientLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Updated Booking',
|
|
'message' => 'You have successfully updated the Booking'
|
|
];
|
|
}
|
|
|
|
/** @var CanUpdateBooking */
|
|
private $canUpdateBooking;
|
|
|
|
/** @var UpdatesBooking */
|
|
private $updatesBooking;
|
|
|
|
/** @var FetchesBooking */
|
|
private $fetchesBooking;
|
|
|
|
|
|
/**
|
|
* UpdateBookingRecipientLogic constructor.
|
|
* @param CanUpdateBooking $canUpdateBooking
|
|
* @param UpdatesBooking $updatesBooking
|
|
* @param FetchesBooking $fetchesBooking
|
|
*/
|
|
public function __construct(
|
|
CanUpdateBooking $canUpdateBooking,
|
|
UpdatesBooking $updatesBooking,
|
|
FetchesBooking $fetchesBooking
|
|
)
|
|
{
|
|
$this->canUpdateBooking = $canUpdateBooking;
|
|
$this->updatesBooking = $updatesBooking;
|
|
$this->fetchesBooking = $fetchesBooking;
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws ErrorException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
try {
|
|
DB::beginTransaction();
|
|
|
|
$booking = $this->fetchesBooking->execute(['id' => $request->route('id')]);
|
|
|
|
|
|
$booking_object = new BookingObject(
|
|
$booking->service_id,
|
|
$request->input('transferable_bank_id', $booking->transferable_bank_id),
|
|
$booking->marking,
|
|
$booking->fix_amount,
|
|
$booking->fix_currency_id,
|
|
$booking->convertible_currency_id,
|
|
$booking->conversion_currency_id
|
|
);
|
|
$this->canUpdateBooking->passes($booking_object);
|
|
$booking = $this->updatesBooking->execute($booking, $booking_object);
|
|
|
|
DB::commit();
|
|
|
|
return $this->resourceResponse(new BookingResource($booking));
|
|
|
|
} catch (\Exception $exception){
|
|
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
|
}
|
|
}
|
|
|
|
}
|