migrate to gtea from bistbucket
This commit is contained in:
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Booking\Repositories;
|
||||
|
||||
use App\Abstracts\EntityRepository;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Modules\Booking\Models\Floor;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class FloorRepository extends EntityRepository
|
||||
{
|
||||
public string $table = Floor::TABLE_NAME;
|
||||
|
||||
protected array $fillableColumns = [
|
||||
'restaurant_id',
|
||||
'hotel_id',
|
||||
'name',
|
||||
'level',
|
||||
'status',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
protected function getQuery(): Builder
|
||||
{
|
||||
return parent::getQuery();
|
||||
}
|
||||
|
||||
protected function getFilterData(array $filterData = []): array
|
||||
{
|
||||
$defaultArgs = [
|
||||
'perPage' => 10,
|
||||
'search' => '',
|
||||
'orderBy' => 'id',
|
||||
'order' => 'desc',
|
||||
'with_deleted' => false,
|
||||
];
|
||||
|
||||
return array_merge($defaultArgs, $filterData);
|
||||
}
|
||||
|
||||
private function getFloorQuery(): Builder
|
||||
{
|
||||
return $this->getQuery()
|
||||
->select(
|
||||
"{$this->table}.id",
|
||||
"{$this->table}.restaurant_id",
|
||||
"{$this->table}.hotel_id",
|
||||
'hotels.name as hotel_name',
|
||||
"{$this->table}.name",
|
||||
"{$this->table}.level",
|
||||
"{$this->table}.status",
|
||||
"{$this->table}.created_at",
|
||||
"{$this->table}.deleted_at"
|
||||
)
|
||||
->leftJoin('hotels', 'hotels.id', '=', "{$this->table}.hotel_id");
|
||||
}
|
||||
|
||||
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
|
||||
{
|
||||
$searchable = "%$searchedText%";
|
||||
|
||||
return $query->where("{$this->table}.name", 'LIKE', $searchable)
|
||||
->orWhere("{$this->table}.status", 'LIKE', $searchable);
|
||||
}
|
||||
|
||||
public function getAll(array $filterData = []): Paginator
|
||||
{
|
||||
$filter = $this->getFilterData($filterData);
|
||||
$query = $this->getFloorQuery();
|
||||
|
||||
if (! $filter['with_deleted']) {
|
||||
$query->whereNull("{$this->table}.deleted_at");
|
||||
}
|
||||
|
||||
if (! empty($filter['search'])) {
|
||||
$query = $this->filterSearchQuery($query, $filter['search']);
|
||||
}
|
||||
|
||||
return $query
|
||||
->orderBy($filter['orderBy'], $filter['order'])
|
||||
->paginate($filter['perPage']);
|
||||
}
|
||||
|
||||
public function getCount(array $filterData = []): int
|
||||
{
|
||||
$filter = $this->getFilterData($filterData);
|
||||
$query = $this->getQuery();
|
||||
|
||||
if (! $filter['with_deleted']) {
|
||||
$query->whereNull("{$this->table}.deleted_at");
|
||||
}
|
||||
|
||||
return $query->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
|
||||
{
|
||||
$item = $this->getFloorQuery()
|
||||
->where($columnName, $columnValue)
|
||||
->first($selects);
|
||||
|
||||
if (empty($item)) {
|
||||
throw new Exception(
|
||||
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
|
||||
Response::HTTP_NOT_FOUND
|
||||
);
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function create(array $data): object
|
||||
{
|
||||
$data = $this->prepareForDB($data);
|
||||
$id = $this->getQuery()->insertGetId($data);
|
||||
|
||||
return Floor::find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update(int $id, array $data): object
|
||||
{
|
||||
$item = Floor::findOrFail($id);
|
||||
$data = $this->prepareForDB($data, $item);
|
||||
parent::update($id, $data);
|
||||
|
||||
return $this->getById($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function prepareForDB(array $data, ?object $item = null): array
|
||||
{
|
||||
$data = parent::prepareForDB($data, $item);
|
||||
|
||||
if (empty($item)) {
|
||||
$data['created_at'] = now();
|
||||
$data['restaurant_id'] = $this->getCurrentRestaurantId();
|
||||
$data['status'] = 1;
|
||||
|
||||
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
|
||||
$data['image'] = fileUploader('Booking/', 'png', $data['image']);
|
||||
}
|
||||
} else {
|
||||
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
|
||||
$data['image'] = fileUploader('Booking/', 'png', $data['image'], $item->image);
|
||||
}
|
||||
|
||||
$data['updated_at'] = now();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getExceptionMessages(): array
|
||||
{
|
||||
return [
|
||||
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Floor does not exist.',
|
||||
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Floor could not be deleted.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Booking\Repositories;
|
||||
|
||||
use App\Abstracts\EntityRepository;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Modules\Booking\Models\Hotel;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class HotelRepository extends EntityRepository
|
||||
{
|
||||
public string $table = Hotel::TABLE_NAME;
|
||||
|
||||
protected array $fillableColumns = [
|
||||
'restaurant_id',
|
||||
'name',
|
||||
'location',
|
||||
'email',
|
||||
'phone',
|
||||
'description',
|
||||
'latitude',
|
||||
'longitude',
|
||||
'check_in_time',
|
||||
'check_out_time',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected function getQuery(): Builder
|
||||
{
|
||||
return parent::getQuery();
|
||||
}
|
||||
|
||||
protected function getFilterData(array $filterData = []): array
|
||||
{
|
||||
$defaultArgs = [
|
||||
'perPage' => 10,
|
||||
'search' => '',
|
||||
'orderBy' => 'id',
|
||||
'order' => 'desc',
|
||||
'with_deleted' => false,
|
||||
];
|
||||
|
||||
return array_merge($defaultArgs, $filterData);
|
||||
}
|
||||
|
||||
private function getHotelQuery(): Builder
|
||||
{
|
||||
return $this->getQuery()
|
||||
->select(
|
||||
"{$this->table}.id",
|
||||
"{$this->table}.restaurant_id",
|
||||
"{$this->table}.name",
|
||||
"{$this->table}.location",
|
||||
"{$this->table}.email",
|
||||
"{$this->table}.phone",
|
||||
"{$this->table}.description",
|
||||
"{$this->table}.latitude",
|
||||
"{$this->table}.longitude",
|
||||
"{$this->table}.check_in_time",
|
||||
"{$this->table}.check_out_time",
|
||||
"{$this->table}.status",
|
||||
"{$this->table}.created_at",
|
||||
"{$this->table}.deleted_at"
|
||||
);
|
||||
}
|
||||
|
||||
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
|
||||
{
|
||||
$searchable = "%$searchedText%";
|
||||
|
||||
return $query->where("{$this->table}.name", 'LIKE', $searchable)
|
||||
->orWhere("{$this->table}.status", 'LIKE', $searchable);
|
||||
}
|
||||
|
||||
public function getAll(array $filterData = []): Paginator
|
||||
{
|
||||
$filter = $this->getFilterData($filterData);
|
||||
$query = $this->getHotelQuery();
|
||||
|
||||
if (! $filter['with_deleted']) {
|
||||
$query->whereNull("{$this->table}.deleted_at");
|
||||
}
|
||||
|
||||
if (! empty($filter['search'])) {
|
||||
$query = $this->filterSearchQuery($query, $filter['search']);
|
||||
}
|
||||
|
||||
return $query
|
||||
->orderBy($filter['orderBy'], $filter['order'])
|
||||
->paginate($filter['perPage']);
|
||||
}
|
||||
|
||||
public function getCount(array $filterData = []): int
|
||||
{
|
||||
$filter = $this->getFilterData($filterData);
|
||||
$query = $this->getQuery();
|
||||
|
||||
if (! $filter['with_deleted']) {
|
||||
$query->whereNull("{$this->table}.deleted_at");
|
||||
}
|
||||
|
||||
return $query->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
|
||||
{
|
||||
$item = $this->getHotelQuery()
|
||||
->where($columnName, $columnValue)
|
||||
->first($selects);
|
||||
|
||||
if (empty($item)) {
|
||||
throw new Exception(
|
||||
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
|
||||
Response::HTTP_NOT_FOUND
|
||||
);
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function create(array $data): object
|
||||
{
|
||||
$data = $this->prepareForDB($data);
|
||||
$id = $this->getQuery()->insertGetId($data);
|
||||
|
||||
return Hotel::find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update(int $id, array $data): object
|
||||
{
|
||||
$item = Hotel::findOrFail($id);
|
||||
$data = $this->prepareForDB($data, $item);
|
||||
parent::update($id, $data);
|
||||
|
||||
return $this->getById($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function prepareForDB(array $data, ?object $item = null): array
|
||||
{
|
||||
$data = parent::prepareForDB($data, $item);
|
||||
|
||||
if (empty($item)) {
|
||||
$data['created_at'] = now();
|
||||
$data['restaurant_id'] = $this->getCurrentRestaurantId();
|
||||
$data['status'] = 1;
|
||||
|
||||
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
|
||||
$data['image'] = fileUploader('Booking/', 'png', $data['image']);
|
||||
}
|
||||
} else {
|
||||
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
|
||||
$data['image'] = fileUploader('Booking/', 'png', $data['image'], $item->image);
|
||||
}
|
||||
|
||||
$data['updated_at'] = now();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getExceptionMessages(): array
|
||||
{
|
||||
return [
|
||||
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Hotel does not exist.',
|
||||
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Hotel could not be deleted.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Booking\Repositories;
|
||||
|
||||
use App\Abstracts\EntityRepository;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Modules\Booking\Models\RoomAvailability;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RoomAvailabilityRepository extends EntityRepository
|
||||
{
|
||||
public string $table = RoomAvailability::TABLE_NAME;
|
||||
|
||||
protected array $fillableColumns = [
|
||||
'restaurant_id',
|
||||
'hotel_id',
|
||||
'room_id',
|
||||
'date',
|
||||
'total_inventory',
|
||||
'available_inventory',
|
||||
'is_available',
|
||||
'is_closed_to_arrival',
|
||||
'is_closed_to_departure',
|
||||
'base_price',
|
||||
'extra_adult_price',
|
||||
'extra_child_price',
|
||||
'min_stay',
|
||||
'max_stay',
|
||||
'blocked_by_booking_id',
|
||||
'block_type',
|
||||
'note',
|
||||
'status',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
protected function getQuery(): Builder
|
||||
{
|
||||
return parent::getQuery();
|
||||
}
|
||||
|
||||
protected function getFilterData(array $filterData = []): array
|
||||
{
|
||||
$defaultArgs = [
|
||||
'perPage' => 10,
|
||||
'search' => '',
|
||||
'orderBy' => 'id',
|
||||
'order' => 'desc',
|
||||
'with_deleted' => false,
|
||||
];
|
||||
|
||||
return array_merge($defaultArgs, $filterData);
|
||||
}
|
||||
|
||||
private function getRoomAvailabilityQuery(): Builder
|
||||
{
|
||||
return $this->getQuery()
|
||||
->select(
|
||||
'room_availabilities.id',
|
||||
'room_availabilities.restaurant_id',
|
||||
'room_availabilities.hotel_id',
|
||||
'hotels.name as hotel_name',
|
||||
'room_availabilities.room_id',
|
||||
'rooms.room_number',
|
||||
'rooms.room_code',
|
||||
'rooms.slug as room_slug',
|
||||
'rooms.max_adults',
|
||||
'rooms.max_children',
|
||||
'room_types.name as room_type_name',
|
||||
'floors.name as floor_name',
|
||||
'floors.level as floor_level',
|
||||
'room_availabilities.date',
|
||||
'room_availabilities.total_inventory',
|
||||
'room_availabilities.available_inventory',
|
||||
'room_availabilities.is_available',
|
||||
'room_availabilities.is_closed_to_arrival',
|
||||
'room_availabilities.is_closed_to_departure',
|
||||
'room_availabilities.base_price',
|
||||
'room_availabilities.extra_adult_price',
|
||||
'room_availabilities.extra_child_price',
|
||||
'room_availabilities.min_stay',
|
||||
'room_availabilities.max_stay',
|
||||
'room_availabilities.blocked_by_booking_id',
|
||||
'room_availabilities.block_type',
|
||||
'room_availabilities.note',
|
||||
'room_availabilities.status',
|
||||
'room_availabilities.created_at',
|
||||
'room_availabilities.updated_at',
|
||||
'room_availabilities.deleted_at'
|
||||
)
|
||||
->leftJoin('rooms', 'room_availabilities.room_id', '=', 'rooms.id')
|
||||
->leftJoin('hotels', 'room_availabilities.hotel_id', '=', 'hotels.id')
|
||||
->leftJoin('floors', 'rooms.floor_id', '=', 'floors.id')
|
||||
->leftJoin('room_types', 'rooms.room_type_id', '=', 'room_types.id');
|
||||
}
|
||||
|
||||
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
|
||||
{
|
||||
$searchable = "%$searchedText%";
|
||||
|
||||
return $query->where("{$this->table}.name", 'LIKE', $searchable)
|
||||
->orWhere("{$this->table}.status", 'LIKE', $searchable);
|
||||
}
|
||||
|
||||
public function getAll(array $filterData = []): Paginator
|
||||
{
|
||||
$filter = $this->getFilterData($filterData);
|
||||
$query = $this->getRoomAvailabilityQuery();
|
||||
|
||||
if (! $filter['with_deleted']) {
|
||||
$query->whereNull("{$this->table}.deleted_at");
|
||||
}
|
||||
|
||||
if (! empty($filter['search'])) {
|
||||
$query = $this->filterSearchQuery($query, $filter['search']);
|
||||
}
|
||||
|
||||
return $query
|
||||
->orderBy($filter['orderBy'], $filter['order'])
|
||||
->paginate($filter['perPage']);
|
||||
}
|
||||
|
||||
public function getCount(array $filterData = []): int
|
||||
{
|
||||
$filter = $this->getFilterData($filterData);
|
||||
$query = $this->getQuery();
|
||||
|
||||
if (! $filter['with_deleted']) {
|
||||
$query->whereNull("{$this->table}.deleted_at");
|
||||
}
|
||||
|
||||
return $query->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
|
||||
{
|
||||
$item = $this->getRoomAvailabilityQuery()
|
||||
->where($columnName, $columnValue)
|
||||
->first($selects);
|
||||
|
||||
if (empty($item)) {
|
||||
throw new Exception(
|
||||
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
|
||||
Response::HTTP_NOT_FOUND
|
||||
);
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function create(array $data): object
|
||||
{
|
||||
$data = $this->prepareForDB($data);
|
||||
$id = $this->getQuery()->insertGetId($data);
|
||||
|
||||
return RoomAvailability::find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update(int $id, array $data): object
|
||||
{
|
||||
$item = RoomAvailability::findOrFail($id);
|
||||
$data = $this->prepareForDB($data, $item);
|
||||
parent::update($id, $data);
|
||||
|
||||
return $this->getById($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function prepareForDB(array $data, ?object $item = null): array
|
||||
{
|
||||
$data = parent::prepareForDB($data, $item);
|
||||
|
||||
if (empty($item)) {
|
||||
$data['created_at'] = now();
|
||||
$data['restaurant_id'] = $this->getCurrentRestaurantId();
|
||||
$data['status'] = 1;
|
||||
|
||||
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
|
||||
$data['image'] = fileUploader('Booking/', 'png', $data['image']);
|
||||
}
|
||||
} else {
|
||||
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
|
||||
$data['image'] = fileUploader('Booking/', 'png', $data['image'], $item->image);
|
||||
}
|
||||
|
||||
$data['updated_at'] = now();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getExceptionMessages(): array
|
||||
{
|
||||
return [
|
||||
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'RoomAvailability does not exist.',
|
||||
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'RoomAvailability could not be deleted.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Booking\Repositories;
|
||||
|
||||
use App\Abstracts\EntityRepository;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Modules\Booking\Models\RoomBlock;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RoomBlockRepository extends EntityRepository
|
||||
{
|
||||
public string $table = RoomBlock::TABLE_NAME;
|
||||
|
||||
protected array $fillableColumns = [
|
||||
'restaurant_id',
|
||||
'hotel_id',
|
||||
'room_id',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'start_time',
|
||||
'end_time',
|
||||
'block_type',
|
||||
'blocked_inventory',
|
||||
'priority',
|
||||
'reason',
|
||||
'auto_release',
|
||||
'created_by',
|
||||
'status',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
protected function getQuery(): Builder
|
||||
{
|
||||
return parent::getQuery();
|
||||
}
|
||||
|
||||
protected function getFilterData(array $filterData = []): array
|
||||
{
|
||||
$defaultArgs = [
|
||||
'perPage' => 10,
|
||||
'search' => '',
|
||||
'orderBy' => 'id',
|
||||
'order' => 'desc',
|
||||
'with_deleted' => false,
|
||||
];
|
||||
|
||||
return array_merge($defaultArgs, $filterData);
|
||||
}
|
||||
|
||||
private function getRoomBlockQuery(): Builder
|
||||
{
|
||||
return $this->getQuery()
|
||||
->select(
|
||||
'room_blocks.id',
|
||||
'room_blocks.restaurant_id',
|
||||
'room_blocks.hotel_id',
|
||||
'hotels.name as hotel_name',
|
||||
'room_blocks.room_id',
|
||||
'rooms.room_number',
|
||||
'rooms.room_code',
|
||||
'rooms.slug as room_slug',
|
||||
'rooms.max_adults',
|
||||
'rooms.max_children',
|
||||
'room_types.name as room_type_name',
|
||||
'floors.name as floor_name',
|
||||
'floors.level as floor_level',
|
||||
'room_blocks.start_date',
|
||||
'room_blocks.end_date',
|
||||
'room_blocks.start_time',
|
||||
'room_blocks.end_time',
|
||||
'room_blocks.block_type',
|
||||
'room_blocks.blocked_inventory',
|
||||
'room_blocks.priority',
|
||||
'room_blocks.reason',
|
||||
'room_blocks.auto_release',
|
||||
'room_blocks.created_by',
|
||||
'room_blocks.status',
|
||||
'room_blocks.created_at',
|
||||
'room_blocks.updated_at',
|
||||
'room_blocks.deleted_at'
|
||||
)
|
||||
->leftJoin('rooms', 'room_blocks.room_id', '=', 'rooms.id')
|
||||
->leftJoin('hotels', 'room_blocks.hotel_id', '=', 'hotels.id')
|
||||
->leftJoin('floors', 'rooms.floor_id', '=', 'floors.id')
|
||||
->leftJoin('room_types', 'rooms.room_type_id', '=', 'room_types.id');
|
||||
}
|
||||
|
||||
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
|
||||
{
|
||||
$searchable = "%$searchedText%";
|
||||
|
||||
return $query->where("{$this->table}.name", 'LIKE', $searchable)
|
||||
->orWhere("{$this->table}.status", 'LIKE', $searchable);
|
||||
}
|
||||
|
||||
public function getAll(array $filterData = []): Paginator
|
||||
{
|
||||
$filter = $this->getFilterData($filterData);
|
||||
$query = $this->getRoomBlockQuery();
|
||||
|
||||
if (! $filter['with_deleted']) {
|
||||
$query->whereNull("{$this->table}.deleted_at");
|
||||
}
|
||||
|
||||
if (! empty($filter['search'])) {
|
||||
$query = $this->filterSearchQuery($query, $filter['search']);
|
||||
}
|
||||
|
||||
return $query
|
||||
->orderBy($filter['orderBy'], $filter['order'])
|
||||
->paginate($filter['perPage']);
|
||||
}
|
||||
|
||||
public function getCount(array $filterData = []): int
|
||||
{
|
||||
$filter = $this->getFilterData($filterData);
|
||||
$query = $this->getQuery();
|
||||
|
||||
if (! $filter['with_deleted']) {
|
||||
$query->whereNull("{$this->table}.deleted_at");
|
||||
}
|
||||
|
||||
return $query->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
|
||||
{
|
||||
$item = $this->getRoomBlockQuery()
|
||||
->where($columnName, $columnValue)
|
||||
->first($selects);
|
||||
|
||||
if (empty($item)) {
|
||||
throw new Exception(
|
||||
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
|
||||
Response::HTTP_NOT_FOUND
|
||||
);
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function create(array $data): object
|
||||
{
|
||||
$data = $this->prepareForDB($data);
|
||||
$id = $this->getQuery()->insertGetId($data);
|
||||
|
||||
return RoomBlock::find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update(int $id, array $data): object
|
||||
{
|
||||
$item = RoomBlock::findOrFail($id);
|
||||
$data = $this->prepareForDB($data, $item);
|
||||
parent::update($id, $data);
|
||||
|
||||
return $this->getById($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function prepareForDB(array $data, ?object $item = null): array
|
||||
{
|
||||
$data = parent::prepareForDB($data, $item);
|
||||
|
||||
if (empty($item)) {
|
||||
$data['created_at'] = now();
|
||||
$data['restaurant_id'] = $this->getCurrentRestaurantId();
|
||||
$data['status'] = 1;
|
||||
} else {
|
||||
$data['updated_at'] = now();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getExceptionMessages(): array
|
||||
{
|
||||
return [
|
||||
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'RoomBlock does not exist.',
|
||||
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'RoomBlock could not be deleted.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Booking\Repositories;
|
||||
|
||||
use App\Abstracts\EntityRepository;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Modules\Booking\Models\Room;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RoomRepository extends EntityRepository
|
||||
{
|
||||
public string $table = Room::TABLE_NAME;
|
||||
|
||||
protected array $fillableColumns = [
|
||||
'restaurant_id',
|
||||
'hotel_id',
|
||||
'floor_id',
|
||||
'room_type_id',
|
||||
'room_number',
|
||||
'room_code',
|
||||
'slug',
|
||||
'max_adults',
|
||||
'max_children',
|
||||
'has_balcony',
|
||||
'has_bathtub',
|
||||
'view_type',
|
||||
'image',
|
||||
'banner_image',
|
||||
'gallery_images',
|
||||
'description',
|
||||
'regular_price',
|
||||
'offer_price',
|
||||
'is_clean',
|
||||
'is_available',
|
||||
'status',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
protected function getQuery(): Builder
|
||||
{
|
||||
return parent::getQuery();
|
||||
}
|
||||
|
||||
protected function getFilterData(array $filterData = []): array
|
||||
{
|
||||
$defaultArgs = [
|
||||
'perPage' => 10,
|
||||
'search' => '',
|
||||
'orderBy' => 'id',
|
||||
'order' => 'desc',
|
||||
'with_deleted' => false,
|
||||
];
|
||||
|
||||
return array_merge($defaultArgs, $filterData);
|
||||
}
|
||||
|
||||
private function getRoomQuery(): Builder
|
||||
{
|
||||
return $this->getQuery()
|
||||
->select(
|
||||
'rooms.id',
|
||||
'rooms.restaurant_id',
|
||||
'rooms.hotel_id',
|
||||
'hotels.name as hotel_name',
|
||||
'rooms.floor_id',
|
||||
'floors.name as floor_name',
|
||||
'floors.level as floor_level',
|
||||
'rooms.room_type_id',
|
||||
'room_types.name as room_type_name',
|
||||
'rooms.room_number',
|
||||
'rooms.room_code',
|
||||
'rooms.slug',
|
||||
'rooms.max_adults',
|
||||
'rooms.max_children',
|
||||
'rooms.has_balcony',
|
||||
'rooms.has_bathtub',
|
||||
'rooms.view_type',
|
||||
'rooms.image',
|
||||
'rooms.banner_image',
|
||||
'rooms.gallery_images',
|
||||
'rooms.description',
|
||||
'rooms.regular_price',
|
||||
'rooms.offer_price',
|
||||
'rooms.is_clean',
|
||||
'rooms.is_available',
|
||||
'rooms.status',
|
||||
'rooms.created_at',
|
||||
'rooms.deleted_at'
|
||||
)
|
||||
->leftJoin('hotels', 'rooms.hotel_id', '=', 'hotels.id')
|
||||
->leftJoin('floors', 'rooms.floor_id', '=', 'floors.id')
|
||||
->leftJoin('room_types', 'rooms.room_type_id', '=', 'room_types.id');
|
||||
}
|
||||
|
||||
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
|
||||
{
|
||||
$searchable = "%$searchedText%";
|
||||
|
||||
return $query->where("{$this->table}.name", 'LIKE', $searchable)
|
||||
->orWhere("{$this->table}.status", 'LIKE', $searchable);
|
||||
}
|
||||
|
||||
public function getAll(array $filterData = []): Paginator
|
||||
{
|
||||
$filter = $this->getFilterData($filterData);
|
||||
$query = $this->getRoomQuery();
|
||||
|
||||
if (! $filter['with_deleted']) {
|
||||
$query->whereNull("{$this->table}.deleted_at");
|
||||
}
|
||||
|
||||
if (! empty($filter['search'])) {
|
||||
$query = $this->filterSearchQuery($query, $filter['search']);
|
||||
}
|
||||
|
||||
return $query
|
||||
->orderBy($filter['orderBy'], $filter['order'])
|
||||
->paginate($filter['perPage']);
|
||||
}
|
||||
|
||||
public function getCount(array $filterData = []): int
|
||||
{
|
||||
$filter = $this->getFilterData($filterData);
|
||||
$query = $this->getQuery();
|
||||
|
||||
if (! $filter['with_deleted']) {
|
||||
$query->whereNull("{$this->table}.deleted_at");
|
||||
}
|
||||
|
||||
return $query->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
|
||||
{
|
||||
$item = $this->getRoomQuery()
|
||||
->where($columnName, $columnValue)
|
||||
->first($selects);
|
||||
|
||||
if (empty($item)) {
|
||||
throw new Exception(
|
||||
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
|
||||
Response::HTTP_NOT_FOUND
|
||||
);
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function create(array $data): object
|
||||
{
|
||||
$data = $this->prepareForDB($data);
|
||||
$id = $this->getQuery()->insertGetId($data);
|
||||
|
||||
return Room::find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update(int $id, array $data): object
|
||||
{
|
||||
$item = Room::findOrFail($id);
|
||||
$data = $this->prepareForDB($data, $item);
|
||||
parent::update($id, $data);
|
||||
|
||||
return $this->getById($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function prepareForDB(array $data, ?object $item = null): array
|
||||
{
|
||||
$data = parent::prepareForDB($data, $item);
|
||||
|
||||
if (empty($item)) {
|
||||
$data['created_at'] = now();
|
||||
$data['restaurant_id'] = $this->getCurrentRestaurantId();
|
||||
|
||||
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
|
||||
$data['image'] = fileUploader('rooms/', 'png', $data['image']);
|
||||
}
|
||||
|
||||
if (! empty($data['banner_image']) && $data['banner_image'] instanceof \Illuminate\Http\UploadedFile) {
|
||||
$data['banner_image'] = fileUploader('rooms/', 'png', $data['banner_image']);
|
||||
}
|
||||
|
||||
// Multiple gallery images
|
||||
if (! empty($data['gallery_images']) && is_array($data['gallery_images'])) {
|
||||
$gallery = [];
|
||||
foreach ($data['gallery_images'] as $file) {
|
||||
if ($file instanceof \Illuminate\Http\UploadedFile) {
|
||||
$gallery[] = fileUploader('rooms/', 'png', $file);
|
||||
}
|
||||
}
|
||||
$data['gallery_images'] = ! empty($gallery) ? json_encode($gallery) : null;
|
||||
}
|
||||
} else {
|
||||
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
|
||||
$data['image'] = fileUploader('rooms/', 'png', $data['image'], $item->image);
|
||||
}
|
||||
|
||||
if (! empty($data['banner_image']) && $data['banner_image'] instanceof \Illuminate\Http\UploadedFile) {
|
||||
$data['banner_image'] = fileUploader('rooms/', 'png', $data['banner_image'], $item->banner_image);
|
||||
}
|
||||
|
||||
// Gallery images update
|
||||
if (! empty($data['gallery_images']) && is_array($data['gallery_images'])) {
|
||||
$gallery = [];
|
||||
|
||||
// Keep old images if item exists
|
||||
if (! empty($item->gallery_images)) {
|
||||
$gallery = is_string($item->gallery_images)
|
||||
? json_decode($item->gallery_images, true)
|
||||
: (array) $item->gallery_images;
|
||||
}
|
||||
|
||||
foreach ($data['gallery_images'] as $file) {
|
||||
if ($file instanceof \Illuminate\Http\UploadedFile) {
|
||||
$gallery[] = fileUploader('rooms/', 'png', $file);
|
||||
}
|
||||
}
|
||||
|
||||
$data['gallery_images'] = ! empty($gallery) ? json_encode($gallery) : null;
|
||||
} else {
|
||||
unset($data['gallery_images']); // keep existing
|
||||
}
|
||||
|
||||
$data['updated_at'] = now();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getExceptionMessages(): array
|
||||
{
|
||||
return [
|
||||
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Room does not exist.',
|
||||
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Room could not be deleted.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Booking\Repositories;
|
||||
|
||||
use App\Abstracts\EntityRepository;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Modules\Booking\Models\RoomType;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RoomTypeRepository extends EntityRepository
|
||||
{
|
||||
public string $table = RoomType::TABLE_NAME;
|
||||
|
||||
protected array $fillableColumns = [
|
||||
'restaurant_id',
|
||||
'hotel_id',
|
||||
'name',
|
||||
'capacity',
|
||||
'beds',
|
||||
'bed_type',
|
||||
'has_ac',
|
||||
'has_wifi',
|
||||
'has_breakfast',
|
||||
'is_refundable',
|
||||
'base_price',
|
||||
'weekend_price',
|
||||
'extra_guest_price',
|
||||
'description',
|
||||
'status',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
protected function getQuery(): Builder
|
||||
{
|
||||
return parent::getQuery();
|
||||
}
|
||||
|
||||
protected function getFilterData(array $filterData = []): array
|
||||
{
|
||||
$defaultArgs = [
|
||||
'perPage' => 10,
|
||||
'search' => '',
|
||||
'orderBy' => 'id',
|
||||
'order' => 'desc',
|
||||
'with_deleted' => false,
|
||||
];
|
||||
|
||||
return array_merge($defaultArgs, $filterData);
|
||||
}
|
||||
|
||||
private function getRoomTypeQuery(): Builder
|
||||
{
|
||||
return $this->getQuery()
|
||||
->select(
|
||||
"{$this->table}.id",
|
||||
"{$this->table}.restaurant_id",
|
||||
"{$this->table}.hotel_id",
|
||||
'hotels.name as hotel_name',
|
||||
"{$this->table}.name",
|
||||
"{$this->table}.capacity",
|
||||
"{$this->table}.beds",
|
||||
"{$this->table}.bed_type",
|
||||
"{$this->table}.has_ac",
|
||||
"{$this->table}.has_wifi",
|
||||
"{$this->table}.has_breakfast",
|
||||
"{$this->table}.is_refundable",
|
||||
"{$this->table}.base_price",
|
||||
"{$this->table}.weekend_price",
|
||||
"{$this->table}.extra_guest_price",
|
||||
"{$this->table}.description",
|
||||
"{$this->table}.status",
|
||||
"{$this->table}.created_at",
|
||||
"{$this->table}.deleted_at"
|
||||
)
|
||||
->leftJoin('hotels', 'hotels.id', '=', "{$this->table}.hotel_id");
|
||||
}
|
||||
|
||||
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
|
||||
{
|
||||
$searchable = "%$searchedText%";
|
||||
|
||||
return $query->where("{$this->table}.name", 'LIKE', $searchable)
|
||||
->orWhere("{$this->table}.status", 'LIKE', $searchable);
|
||||
}
|
||||
|
||||
public function getAll(array $filterData = []): Paginator
|
||||
{
|
||||
$filter = $this->getFilterData($filterData);
|
||||
$query = $this->getRoomTypeQuery();
|
||||
|
||||
if (! $filter['with_deleted']) {
|
||||
$query->whereNull("{$this->table}.deleted_at");
|
||||
}
|
||||
|
||||
if (! empty($filter['search'])) {
|
||||
$query = $this->filterSearchQuery($query, $filter['search']);
|
||||
}
|
||||
|
||||
return $query
|
||||
->orderBy($filter['orderBy'], $filter['order'])
|
||||
->paginate($filter['perPage']);
|
||||
}
|
||||
|
||||
public function getCount(array $filterData = []): int
|
||||
{
|
||||
$filter = $this->getFilterData($filterData);
|
||||
$query = $this->getQuery();
|
||||
|
||||
if (! $filter['with_deleted']) {
|
||||
$query->whereNull("{$this->table}.deleted_at");
|
||||
}
|
||||
|
||||
return $query->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
|
||||
{
|
||||
$item = $this->getRoomTypeQuery()
|
||||
->where($columnName, $columnValue)
|
||||
->first($selects);
|
||||
|
||||
if (empty($item)) {
|
||||
throw new Exception(
|
||||
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
|
||||
Response::HTTP_NOT_FOUND
|
||||
);
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function create(array $data): object
|
||||
{
|
||||
$data = $this->prepareForDB($data);
|
||||
$id = $this->getQuery()->insertGetId($data);
|
||||
|
||||
return RoomType::find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update(int $id, array $data): object
|
||||
{
|
||||
$item = RoomType::findOrFail($id);
|
||||
$data = $this->prepareForDB($data, $item);
|
||||
parent::update($id, $data);
|
||||
|
||||
return $this->getById($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function prepareForDB(array $data, ?object $item = null): array
|
||||
{
|
||||
$data = parent::prepareForDB($data, $item);
|
||||
|
||||
if (empty($item)) {
|
||||
$data['created_at'] = now();
|
||||
$data['restaurant_id'] = $this->getCurrentRestaurantId();
|
||||
$data['status'] = 1;
|
||||
|
||||
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
|
||||
$data['image'] = fileUploader('Booking/', 'png', $data['image']);
|
||||
}
|
||||
} else {
|
||||
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
|
||||
$data['image'] = fileUploader('Booking/', 'png', $data['image'], $item->image);
|
||||
}
|
||||
|
||||
$data['updated_at'] = now();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getExceptionMessages(): array
|
||||
{
|
||||
return [
|
||||
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'RoomType does not exist.',
|
||||
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'RoomType could not be deleted.',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user