mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
79 lines
2.1 KiB
PHP
79 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Bookings\ControllersLogic;
|
|
|
|
use App\Classes\Modules\Segments\Services\UpdatesSegment;
|
|
use App\Classes\Modules\Segments\Standards\Rules\CanUpdateSegment;
|
|
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\CanDeleteBooking;
|
|
use App\Classes\Modules\Bookings\Services\DeletesBooking;
|
|
use App\Classes\Modules\Bookings\DataTransferObjects\SegmentObject;
|
|
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class DeleteBookingLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Delete Booking',
|
|
'message' => 'You have successfully deleted the Booking'
|
|
];
|
|
}
|
|
|
|
/** @var CanDeleteBooking */
|
|
private $canDeleteBooking;
|
|
|
|
/** @var DeletesBooking */
|
|
private $deletesBooking;
|
|
|
|
/** @var FetchesBooking */
|
|
private $fetchesBooking;
|
|
|
|
|
|
public function __construct(
|
|
CanDeleteBooking $canDeleteBooking,
|
|
DeletesBooking $deletesBooking,
|
|
FetchesBooking $fetchesBooking
|
|
)
|
|
{
|
|
$this->canDeleteBooking = $canDeleteBooking;
|
|
$this->deletesBooking = $deletesBooking;
|
|
$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')]);
|
|
$this->canDeleteBooking->passes();
|
|
$this->deletesBooking->execute($booking);
|
|
|
|
DB::commit();
|
|
|
|
return $this->resourceResponse(new BookingResource($booking));
|
|
|
|
} catch (\Exception $exception){
|
|
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
|
}
|
|
}
|
|
|
|
} |