Add new feature of Booking Module - List Booking

This commit is contained in:
Hafiz
2021-01-03 22:16:55 +08:00
parent 8a2678b2dd
commit 822df0e115
4 changed files with 154 additions and 0 deletions
@@ -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;
}
}