mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
Merge branch 'List-Bookings' into 'master'
Add new feature of Booking Module - List Booking See merge request CIEFWorldwideSdnBhd/exchange-2.0!17
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Bookings\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllersLogic;
|
||||
use App\Classes\Modules\Bookings\Services\ListsBookings;
|
||||
use App\Classes\Modules\Bookings\Standards\Rules\CanListBookings;
|
||||
use App\Http\Resources\BookingResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListBookingsLogic extends AbstractControllersLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Bookings',
|
||||
'message' => 'You have successfully retrieved a list of Bookings'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanListBookings */
|
||||
private $canListBookings;
|
||||
|
||||
/** @var ListsBookings */
|
||||
private $listsBookings;
|
||||
|
||||
/**
|
||||
* ListBookingsLogic constructor.
|
||||
* @param CanListBookings $canListBookings
|
||||
* @param ListsBookings $listsBookings
|
||||
*/
|
||||
public function __construct(CanListBookings $canListBookings, ListsBookings $listsBookings)
|
||||
{
|
||||
$this->canListBookings = $canListBookings;
|
||||
$this->listsBookings = $listsBookings;
|
||||
}
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
$this->canListBookings->passes();
|
||||
|
||||
$query = $this->listsBookings->execute($this->listsBookings->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(BookingResource::collection($query));
|
||||
|
||||
} catch (\Exception $exception) {
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Bookings\Services;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
use App\Models\Booking;
|
||||
|
||||
class ListsBookings extends AbstractListRecord
|
||||
{
|
||||
/** @var Booking */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsBookings constructor.
|
||||
* @param Booking $repository
|
||||
*/
|
||||
public function __construct(Booking $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Booking
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Bookings\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject;
|
||||
|
||||
|
||||
class CanListBookings extends AbstractRule
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BookingObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BookingObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\Bookings;
|
||||
|
||||
use App\Classes\Modules\Addresses\ControllersLogic\ListAddressesLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\Modules\Bookings\ControllersLogic\ListBookingsLogic;
|
||||
|
||||
|
||||
class ListBookingsController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @param ListBookingsLogic
|
||||
*/
|
||||
|
||||
public function list(Request $request, ListBookingsLogic $logic) : JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user