migrate to gtea from bistbucket

This commit is contained in:
2026-03-15 17:08:23 +07:00
commit 129ca2260c
3716 changed files with 566316 additions and 0 deletions

View File

@@ -0,0 +1,187 @@
<?php
namespace Modules\Frontend\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\Frontend\Models\AboutUs;
use Symfony\Component\HttpFoundation\Response;
class AboutUsRepository extends EntityRepository
{
public string $table = AboutUs::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'title',
'description',
'image',
'status',
'created_by',
'created_at',
'updated_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getAboutUsQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (isset($filter['search']) && strlen($filter['search']) > 0) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getAboutUsQuery(): Builder
{
return $this->getQuery()
->select(
'about_us.id',
'about_us.restaurant_id',
'about_us.title',
'about_us.description',
'about_us.image',
'about_us.status',
'about_us.created_at',
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where('about_us.question', 'LIKE', $searchable)
->orWhere('about_us.title', 'LIKE', $searchable)
->orWhere('about_us.description', 'LIKE', $searchable)
->orWhere('about_us.status', 'LIKE', $searchable);
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$user = $this->getAboutUsQuery()
->where($columnName, $columnValue)
->first();
if (empty($user)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $user;
}
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 create(array $data): object
{
try {
$data = $this->prepareForDB($data);
$userId = $this->getQuery()->insertGetId($data);
$user = AboutUs::find($userId);
return $user;
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
/**
* @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('about_us/', 'png', $data['image']);
}
} else {
$data['updated_at'] = now();
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('about_us/', 'png', $data['image'], $item->image);
}
}
return $data;
}
/**
* @throws Exception
*/
public function update(int $id, array $data): ?object
{
try {
$user = AboutUs::find($id);
$data = $this->prepareForDB($data, $user);
parent::update($id, $data);
return $this->getById($id);
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
protected function getExceptionMessages(): array
{
$exceptionMessages = parent::getExceptionMessages();
$userExceptionMessages = [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'AboutUs does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'AboutUs could not be deleted.',
];
return array_merge($exceptionMessages, $userExceptionMessages);
}
}

View File

@@ -0,0 +1,189 @@
<?php
namespace Modules\Frontend\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\Frontend\Models\AcademicImage;
use Symfony\Component\HttpFoundation\Response;
class AcademicImageRepository extends EntityRepository
{
public string $table = AcademicImage::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'title',
'heading',
'description',
'image',
'status',
'created_by',
'created_at',
'updated_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getAcademicImageQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (isset($filter['search']) && strlen($filter['search']) > 0) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getAcademicImageQuery(): Builder
{
return $this->getQuery()
->select(
'academic_images.id',
'academic_images.restaurant_id',
'academic_images.title',
'academic_images.heading',
'academic_images.description',
'academic_images.image',
'academic_images.status',
'academic_images.created_at',
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where('academic_images.question', 'LIKE', $searchable)
->orWhere('academic_images.title', 'LIKE', $searchable)
->orWhere('academic_images.heading', 'LIKE', $searchable)
->orWhere('academic_images.status', 'LIKE', $searchable);
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$user = $this->getAcademicImageQuery()
->where($columnName, $columnValue)
->first();
if (empty($user)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $user;
}
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 create(array $data): object
{
try {
$data = $this->prepareForDB($data);
$userId = $this->getQuery()->insertGetId($data);
$user = AcademicImage::find($userId);
return $user;
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['created_by'] = $this->getCurrentUserId();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('academic_images/', 'png', $data['image']);
}
} else {
$data['updated_at'] = now();
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('academic_images/', 'png', $data['image'], $item->image);
}
}
return $data;
}
/**
* @throws Exception
*/
public function update(int $id, array $data): ?object
{
try {
$user = AcademicImage::find($id);
$data = $this->prepareForDB($data, $user);
parent::update($id, $data);
return $this->getById($id);
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
protected function getExceptionMessages(): array
{
$exceptionMessages = parent::getExceptionMessages();
$userExceptionMessages = [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'AcademicImage does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'AcademicImage could not be deleted.',
];
return array_merge($exceptionMessages, $userExceptionMessages);
}
}

View File

@@ -0,0 +1,189 @@
<?php
namespace Modules\Frontend\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\Frontend\Models\Banner;
use Symfony\Component\HttpFoundation\Response;
class BannerRepository extends EntityRepository
{
public string $table = Banner::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'title',
'description',
'button_name',
'button_link',
'image',
'status',
'created_by',
'created_at',
'updated_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getBannerQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (isset($filter['search']) && strlen($filter['search']) > 0) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getBannerQuery(): Builder
{
return $this->getQuery()
->select(
'banners.id',
'banners.restaurant_id',
'banners.title',
'banners.description',
'banners.button_name',
'banners.button_link',
'banners.image',
'banners.status',
'banners.created_at'
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where('banners.first_name', 'LIKE', $searchable)
->orWhere('banners.title', 'LIKE', $searchable)
->orWhere('banners.status', 'LIKE', $searchable);
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$user = $this->getBannerQuery()
->where($columnName, $columnValue)
->first();
if (empty($user)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $user;
}
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 create(array $data): object
{
try {
$data = $this->prepareForDB($data);
$userId = $this->getQuery()->insertGetId($data);
$user = Banner::find($userId);
return $user;
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
/**
* @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('banners/', 'png', $data['image']);
}
} else {
$data['updated_at'] = now();
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('banners/', 'png', $data['image'], $item->image);
}
}
return $data;
}
/**
* @throws Exception
*/
public function update(int $id, array $data): ?object
{
try {
$user = Banner::find($id);
$data = $this->prepareForDB($data, $user);
parent::update($id, $data);
return $this->getById($id);
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
protected function getExceptionMessages(): array
{
$exceptionMessages = parent::getExceptionMessages();
$userExceptionMessages = [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Banner does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Banner could not be deleted.',
];
return array_merge($exceptionMessages, $userExceptionMessages);
}
}

View File

@@ -0,0 +1,178 @@
<?php
namespace Modules\Frontend\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\Frontend\Models\CMSSection;
use Symfony\Component\HttpFoundation\Response;
class CMSSectionRepository extends EntityRepository
{
public string $table = CMSSection::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'name',
'serial',
'title',
'description',
'image',
'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 getCMSSectionQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.name",
"{$this->table}.serial",
"{$this->table}.title",
"{$this->table}.description",
"{$this->table}.image",
"{$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->getCMSSectionQuery();
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->getCMSSectionQuery()
->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 CMSSection::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = CMSSection::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('cms_background_images/', 'png', $data['image']);
}
} else {
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('cms_background_images/', 'png', $data['image'], $item->image);
}
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'CMSSection does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'CMSSection could not be deleted.',
];
}
}

View File

@@ -0,0 +1,180 @@
<?php
namespace Modules\Frontend\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\Frontend\Models\Contact;
use Symfony\Component\HttpFoundation\Response;
class ContactRepository extends EntityRepository
{
public string $table = Contact::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'name',
'phone',
'email',
'subject',
'message',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getContactQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (isset($filter['search']) && strlen($filter['search']) > 0) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getContactQuery(): Builder
{
return $this->getQuery()
->select(
'frontend_contacts.id',
'frontend_contacts.restaurant_id',
'frontend_contacts.name',
'frontend_contacts.phone',
'frontend_contacts.email',
'frontend_contacts.subject',
'frontend_contacts.message',
'frontend_contacts.created_at',
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where('frontend_contacts.name', 'LIKE', $searchable)
->orWhere('frontend_contacts.phone', 'LIKE', $searchable)
->orWhere('frontend_contacts.email', 'LIKE', $searchable)
->orWhere('frontend_contacts.subject', 'LIKE', $searchable)
->orWhere('frontend_contacts.message', 'LIKE', $searchable)
->orWhere('frontend_contacts.status', 'LIKE', $searchable);
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$user = $this->getContactQuery()
->where($columnName, $columnValue)
->first();
if (empty($user)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $user;
}
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 create(array $data): object
{
try {
$data = $this->prepareForDB($data);
$userId = $this->getQuery()->insertGetId($data);
$user = Contact::find($userId);
return $user;
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
/**
* @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();
} else {
$data['updated_at'] = now();
}
return $data;
}
/**
* @throws Exception
*/
public function update(int $id, array $data): ?object
{
try {
$user = Contact::find($id);
$data = $this->prepareForDB($data, $user);
parent::update($id, $data);
return $this->getById($id);
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
protected function getExceptionMessages(): array
{
$exceptionMessages = parent::getExceptionMessages();
$userExceptionMessages = [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Contact does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Contact could not be deleted.',
];
return array_merge($exceptionMessages, $userExceptionMessages);
}
}

View File

@@ -0,0 +1,195 @@
<?php
namespace Modules\Frontend\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\Frontend\Models\Coupon;
use Symfony\Component\HttpFoundation\Response;
class CouponRepository extends EntityRepository
{
public string $table = Coupon::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'user_id',
'name',
'added_by',
'discount_type',
'coupon_type',
'amount',
'valid_from',
'valid_to',
'usage_limit',
'max_uses_per_customer',
'min_order_amount',
'image',
'source',
'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 getCouponQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.user_id",
"{$this->table}.name",
"{$this->table}.added_by",
"{$this->table}.discount_type",
"{$this->table}.coupon_type",
"{$this->table}.amount",
"{$this->table}.valid_from",
"{$this->table}.valid_to",
"{$this->table}.usage_limit",
"{$this->table}.max_uses_per_customer",
"{$this->table}.min_order_amount",
"{$this->table}.image",
"{$this->table}.source",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.updated_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->getCouponQuery();
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->getCouponQuery()
->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 Coupon::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = Coupon::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('coupons/', 'png', $data['image']);
}
} else {
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('coupons/', 'png', $data['image'], $item->image);
}
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Coupon does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Coupon could not be deleted.',
];
}
}

View File

@@ -0,0 +1,177 @@
<?php
namespace Modules\Frontend\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\Frontend\Models\FaqQuestion;
use Symfony\Component\HttpFoundation\Response;
class FaqQuestionRepository extends EntityRepository
{
public string $table = FaqQuestion::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'question',
'answer',
'status',
'created_by',
'created_at',
'updated_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getFaqQuestionQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (isset($filter['search']) && strlen($filter['search']) > 0) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getFaqQuestionQuery(): Builder
{
return $this->getQuery()
->select(
'faq_questions.id',
'faq_questions.restaurant_id',
'faq_questions.question',
'faq_questions.answer',
'faq_questions.status',
'faq_questions.created_at'
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where('faq_questions.question', 'LIKE', $searchable)
->orWhere('faq_questions.answer', 'LIKE', $searchable)
->orWhere('faq_questions.status', 'LIKE', $searchable);
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$user = $this->getFaqQuestionQuery()
->where($columnName, $columnValue)
->first();
if (empty($user)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $user;
}
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 create(array $data): object
{
try {
$data = $this->prepareForDB($data);
$userId = $this->getQuery()->insertGetId($data);
$user = FaqQuestion::find($userId);
return $user;
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
/**
* @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;
}
/**
* @throws Exception
*/
public function update(int $id, array $data): ?object
{
try {
$user = FaqQuestion::find($id);
$data = $this->prepareForDB($data, $user);
parent::update($id, $data);
return $this->getById($id);
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
protected function getExceptionMessages(): array
{
$exceptionMessages = parent::getExceptionMessages();
$userExceptionMessages = [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'FaqQuestion does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'FaqQuestion could not be deleted.',
];
return array_merge($exceptionMessages, $userExceptionMessages);
}
}

View File

@@ -0,0 +1,194 @@
<?php
namespace Modules\Frontend\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\Frontend\Models\MobileAppSection;
use Symfony\Component\HttpFoundation\Response;
class MobileAppSectionRepository extends EntityRepository
{
public string $table = MobileAppSection::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'title',
'heading',
'description',
'image',
'feature_one',
'feature_two',
'feature_three',
'play_store_link',
'app_store_link',
'created_at',
'updated_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getMobileAppSectionQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (isset($filter['search']) && strlen($filter['search']) > 0) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getMobileAppSectionQuery(): Builder
{
return $this->getQuery()
->select(
'mobile_app_sections.id',
'mobile_app_sections.restaurant_id',
'mobile_app_sections.title',
'mobile_app_sections.heading',
'mobile_app_sections.description',
'mobile_app_sections.image',
'mobile_app_sections.feature_one',
'mobile_app_sections.feature_two',
'mobile_app_sections.feature_three',
'mobile_app_sections.play_store_link',
'mobile_app_sections.app_store_link',
'mobile_app_sections.created_at',
'mobile_app_sections.updated_at',
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where('mobile_app_sections.title', 'LIKE', $searchable)
->orWhere('mobile_app_sections.heading', 'LIKE', $searchable);
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$user = $this->getMobileAppSectionQuery()
->where($columnName, $columnValue)
->first();
if (empty($user)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $user;
}
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 create(array $data): object
{
try {
$data = $this->prepareForDB($data);
$userId = $this->getQuery()->insertGetId($data);
$user = MobileAppSection::find($userId);
return $user;
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
/**
* @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('mobile_app_sections/', 'png', $data['image']);
}
} else {
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('mobile_app_sections/', 'png', $data['image'], $item->image);
}
$data['updated_at'] = now();
}
return $data;
}
/**
* @throws Exception
*/
public function update(int $id, array $data): ?object
{
try {
$user = MobileAppSection::find($id);
$data = $this->prepareForDB($data, $user);
parent::update($id, $data);
return $this->getById($id);
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
protected function getExceptionMessages(): array
{
$exceptionMessages = parent::getExceptionMessages();
$userExceptionMessages = [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'MobileAppSection does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'MobileAppSection could not be deleted.',
];
return array_merge($exceptionMessages, $userExceptionMessages);
}
}

View File

@@ -0,0 +1,177 @@
<?php
namespace Modules\Frontend\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\Frontend\Models\Policy;
use Symfony\Component\HttpFoundation\Response;
class PolicyRepository extends EntityRepository
{
public string $table = Policy::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'type',
'description',
'status',
'created_by',
'created_at',
'updated_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getPolicyQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (isset($filter['search']) && strlen($filter['search']) > 0) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getPolicyQuery(): Builder
{
return $this->getQuery()
->select(
'policies.id',
'policies.restaurant_id',
'policies.type',
'policies.description',
'policies.status',
'policies.created_at'
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where('policies.type', 'LIKE', $searchable)
->orWhere('policies.description', 'LIKE', $searchable)
->orWhere('policies.status', 'LIKE', $searchable);
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$user = $this->getPolicyQuery()
->where($columnName, $columnValue)
->first();
if (empty($user)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $user;
}
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 create(array $data): object
{
try {
$data = $this->prepareForDB($data);
$userId = $this->getQuery()->insertGetId($data);
$user = Policy::find($userId);
return $user;
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
/**
* @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;
}
/**
* @throws Exception
*/
public function update(int $id, array $data): ?object
{
try {
$user = Policy::find($id);
$data = $this->prepareForDB($data, $user);
parent::update($id, $data);
return $this->getById($id);
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
protected function getExceptionMessages(): array
{
$exceptionMessages = parent::getExceptionMessages();
$userExceptionMessages = [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Policy does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Policy could not be deleted.',
];
return array_merge($exceptionMessages, $userExceptionMessages);
}
}

View File

@@ -0,0 +1,174 @@
<?php
namespace Modules\Frontend\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\Frontend\Models\ReadyToJoinUs;
use Symfony\Component\HttpFoundation\Response;
class ReadyToJoinUsRepository extends EntityRepository
{
public string $table = ReadyToJoinUs::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'title',
'description',
'icon',
'created_at',
'updated_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getReadyToJoinUsQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (isset($filter['search']) && strlen($filter['search']) > 0) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getReadyToJoinUsQuery(): Builder
{
return $this->getQuery()
->select('*');
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where('ready_to_join_us.title', 'LIKE', $searchable)
->orWhere('ready_to_join_us.description', 'LIKE', $searchable);
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$user = $this->getReadyToJoinUsQuery()
->where($columnName, $columnValue)
->first();
if (empty($user)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $user;
}
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 create(array $data): object
{
try {
$data = $this->prepareForDB($data);
$userId = $this->getQuery()->insertGetId($data);
$user = ReadyToJoinUs::find($userId);
return $user;
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
/**
* @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['icon']) && $data['icon'] instanceof \Illuminate\Http\UploadedFile) {
$data['icon'] = fileUploader('ready_to_join_us/', 'png', $data['icon']);
}
} else {
if (! empty($data['icon']) && $data['icon'] instanceof \Illuminate\Http\UploadedFile) {
$data['icon'] = fileUploader('ready_to_join_us/', 'png', $data['icon'], $item->icon);
}
$data['updated_at'] = now();
}
return $data;
}
/**
* @throws Exception
*/
public function update(int $id, array $data): ?object
{
try {
$user = ReadyToJoinUs::find($id);
$data = $this->prepareForDB($data, $user);
parent::update($id, $data);
return $this->getById($id);
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
protected function getExceptionMessages(): array
{
$exceptionMessages = parent::getExceptionMessages();
$userExceptionMessages = [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Ready To Join Us does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Ready To Join Us could not be deleted.',
];
return array_merge($exceptionMessages, $userExceptionMessages);
}
}

View File

@@ -0,0 +1,191 @@
<?php
namespace Modules\Frontend\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\Frontend\Models\Testimonial;
use Symfony\Component\HttpFoundation\Response;
class TestimonialRepository extends EntityRepository
{
public string $table = Testimonial::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'name',
'description',
'thumbnail_image',
'video_url',
'note',
'ratting',
'status',
'created_at',
'updated_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getTestimonialQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (isset($filter['search']) && strlen($filter['search']) > 0) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getTestimonialQuery(): Builder
{
return $this->getQuery()
->select(
'testimonials.id',
'testimonials.restaurant_id',
'testimonials.name',
'testimonials.description',
'testimonials.thumbnail_image',
'testimonials.video_url',
'testimonials.note',
'testimonials.ratting',
'testimonials.status',
'testimonials.created_at',
'testimonials.updated_at'
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where('testimonials.restaurant_id', 'LIKE', $searchable)
->orWhere('testimonials.name', 'LIKE', $searchable)
->orWhere('testimonials.description', 'LIKE', $searchable)
->orWhere('testimonials.status', 'LIKE', $searchable);
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$user = $this->getTestimonialQuery()
->where($columnName, $columnValue)
->first();
if (empty($user)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $user;
}
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 create(array $data): object
{
try {
$data = $this->prepareForDB($data);
$userId = $this->getQuery()->insertGetId($data);
$user = Testimonial::find($userId);
return $user;
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
/**
* @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['thumbnail_image']) && $data['thumbnail_image'] instanceof \Illuminate\Http\UploadedFile) {
$data['thumbnail_image'] = fileUploader('testimonials/', 'png', $data['thumbnail_image']);
}
} else {
if (! empty($data['thumbnail_image']) && $data['thumbnail_image'] instanceof \Illuminate\Http\UploadedFile) {
$data['thumbnail_image'] = fileUploader('testimonials/', 'png', $data['thumbnail_image'], $item->thumbnail_image);
}
$data['updated_at'] = now();
}
return $data;
}
/**
* @throws Exception
*/
public function update(int $id, array $data): ?object
{
try {
$user = Testimonial::find($id);
$data = $this->prepareForDB($data, $user);
parent::update($id, $data);
return $this->getById($id);
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
protected function getExceptionMessages(): array
{
$exceptionMessages = parent::getExceptionMessages();
$userExceptionMessages = [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Testimonial does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Testimonial could not be deleted.',
];
return array_merge($exceptionMessages, $userExceptionMessages);
}
}

View File

@@ -0,0 +1,175 @@
<?php
namespace Modules\Frontend\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\Frontend\Models\WhyChooseUs;
use Symfony\Component\HttpFoundation\Response;
class WhyChooseUsRepository extends EntityRepository
{
public string $table = WhyChooseUs::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'title',
'description',
'icon',
'created_at',
'updated_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getWhyChooseUsQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (isset($filter['search']) && strlen($filter['search']) > 0) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getWhyChooseUsQuery(): Builder
{
return $this->getQuery()
->select('*');
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where('why_choose_us.title', 'LIKE', $searchable)
->orWhere('why_choose_us.description', 'LIKE', $searchable);
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$user = $this->getWhyChooseUsQuery()
->where($columnName, $columnValue)
->first();
if (empty($user)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $user;
}
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 create(array $data): object
{
try {
$data = $this->prepareForDB($data);
$userId = $this->getQuery()->insertGetId($data);
$user = WhyChooseUs::find($userId);
return $user;
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
/**
* @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['icon']) && $data['icon'] instanceof \Illuminate\Http\UploadedFile) {
$data['icon'] = fileUploader('why_choose_us/', 'png', $data['icon']);
}
} else {
if (! empty($data['icon']) && $data['icon'] instanceof \Illuminate\Http\UploadedFile) {
$data['icon'] = fileUploader('why_choose_us/', 'png', $data['icon'], $item->icon);
}
$data['updated_at'] = now();
}
return $data;
}
/**
* @throws Exception
*/
public function update(int $id, array $data): ?object
{
try {
$user = WhyChooseUs::find($id);
$data = $this->prepareForDB($data, $user);
parent::update($id, $data);
return $this->getById($id);
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
protected function getExceptionMessages(): array
{
$exceptionMessages = parent::getExceptionMessages();
$userExceptionMessages = [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'WhyChooseUs does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'WhyChooseUs could not be deleted.',
];
return array_merge($exceptionMessages, $userExceptionMessages);
}
}