migrate to gtea from bistbucket
This commit is contained in:
54
public/restaurant/app/Services/Firebase/FirebaseService.php
Normal file
54
public/restaurant/app/Services/Firebase/FirebaseService.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services\Firebase;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Kreait\Firebase\Exception\FirebaseException;
|
||||
use Kreait\Firebase\Exception\MessagingException;
|
||||
use Kreait\Firebase\Factory;
|
||||
use Kreait\Firebase\Messaging\CloudMessage;
|
||||
use Kreait\Firebase\Messaging\Notification;
|
||||
|
||||
class FirebaseService
|
||||
{
|
||||
protected $messaging;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$factory = (new Factory)
|
||||
->withServiceAccount(storage_path('firebase/firebase_credentials.json'));
|
||||
|
||||
$this->messaging = $factory->createMessaging();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send FCM notification to a device token
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function sendNotification(string $token, string $title, string $body, array $data = [])
|
||||
{
|
||||
$message = CloudMessage::withTarget('token', $token)
|
||||
->withNotification(Notification::create($title, $body))
|
||||
->withData($data);
|
||||
|
||||
try {
|
||||
$this->messaging->send($message);
|
||||
|
||||
return true; // Notification sent successfully
|
||||
} catch (MessagingException|FirebaseException $e) {
|
||||
// Log the error
|
||||
Log::error('Firebase notification failed', [
|
||||
'token' => $token,
|
||||
'title' => $title,
|
||||
'body' => $body,
|
||||
'data' => $data,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return $e->getMessage(); // Return error message
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Onboarding;
|
||||
|
||||
use App\Interfaces\Onboarding\OnboardingInterface;
|
||||
use Modules\Frontend\Models\Onboarding;
|
||||
|
||||
final class OnboardingService implements OnboardingInterface
|
||||
{
|
||||
public function __construct(
|
||||
protected Onboarding $model
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get categories by filtering args.
|
||||
*/
|
||||
public function get(array $args = []): \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Builder
|
||||
{
|
||||
$orderBy = empty($args['order_by']) ? 'id' : $args['order_by']; // column restaurant_name
|
||||
$order = empty($args['order']) ? 'desc' : $args['order']; // asc, desc
|
||||
$query = Onboarding::where('status', 'pending')->orderBy($orderBy, $order);
|
||||
|
||||
if (isset($args['is_query']) && $args['is_query']) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
public function index($request, int $per_page = 50)
|
||||
{
|
||||
$orderColumn = request('sort_column', 'id');
|
||||
$orderDirection = request('sort_direction', 'desc');
|
||||
|
||||
if (! in_array($orderColumn, ['id', 'restaurant_name', 'created_at'])) {
|
||||
$orderColumn = 'id';
|
||||
}
|
||||
if (! in_array($orderDirection, ['asc', 'desc'])) {
|
||||
$orderDirection = 'desc';
|
||||
}
|
||||
|
||||
return $this->model::query()
|
||||
->when($request->search, function ($query) use ($request) {
|
||||
$query->where('restaurant_name', 'like', '%'.$request->search.'%');
|
||||
})
|
||||
->orderBy($orderColumn, $orderDirection)
|
||||
->paginate($per_page);
|
||||
}
|
||||
|
||||
public function getAll($request)
|
||||
{
|
||||
$orderColumn = request('sort_column', 'id');
|
||||
$orderDirection = request('sort_direction', 'desc');
|
||||
|
||||
if (! in_array($orderColumn, ['id', 'restaurant_name', 'created_at'])) {
|
||||
$orderColumn = 'id';
|
||||
}
|
||||
if (! in_array($orderDirection, ['asc', 'desc'])) {
|
||||
$orderDirection = 'desc';
|
||||
}
|
||||
|
||||
return $this->model::query()
|
||||
->when($request->search, function ($query) use ($request) {
|
||||
$query->where('restaurant_name', 'like', $request->search.'%');
|
||||
})
|
||||
->orderBy($orderColumn, $orderDirection)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getById(int $id)
|
||||
{
|
||||
$record = $this->model::find($id);
|
||||
|
||||
return $record ?? null;
|
||||
}
|
||||
|
||||
public function create(array $data)
|
||||
{
|
||||
return $this->model::create($data);
|
||||
}
|
||||
|
||||
public function update(int $id, array $data)
|
||||
{
|
||||
$model = $this->model::findOrFail($id);
|
||||
$model->update($data);
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function delete(int $id)
|
||||
{
|
||||
$model = $this->model::findOrFail($id);
|
||||
|
||||
return $model->delete();
|
||||
}
|
||||
}
|
||||
96
public/restaurant/app/Services/Package/PackageService.php
Normal file
96
public/restaurant/app/Services/Package/PackageService.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Package;
|
||||
|
||||
use App\Interfaces\Package\PackageInterface;
|
||||
use Modules\Authentication\Models\Package;
|
||||
|
||||
final class PackageService implements PackageInterface
|
||||
{
|
||||
public function __construct(
|
||||
protected Package $model
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get categories by filtering args.
|
||||
*/
|
||||
public function get(array $args = []): \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Builder
|
||||
{
|
||||
$orderBy = empty($args['order_by']) ? 'id' : $args['order_by']; // column name
|
||||
$order = empty($args['order']) ? 'desc' : $args['order']; // asc, desc
|
||||
$query = Package::orderBy($orderBy, $order);
|
||||
|
||||
if (isset($args['is_query']) && $args['is_query']) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
public function index($request, int $per_page = 50)
|
||||
{
|
||||
$orderColumn = request('sort_column', 'id');
|
||||
$orderDirection = request('sort_direction', 'desc');
|
||||
|
||||
if (! in_array($orderColumn, ['id', 'name', 'created_at'])) {
|
||||
$orderColumn = 'id';
|
||||
}
|
||||
if (! in_array($orderDirection, ['asc', 'desc'])) {
|
||||
$orderDirection = 'desc';
|
||||
}
|
||||
|
||||
return $this->model::query()
|
||||
->when($request->search, function ($query) use ($request) {
|
||||
$query->where('name', 'like', '%'.$request->search.'%');
|
||||
})
|
||||
->orderBy($orderColumn, $orderDirection)
|
||||
->paginate($per_page);
|
||||
}
|
||||
|
||||
public function getAll($request)
|
||||
{
|
||||
$orderColumn = request('sort_column', 'id');
|
||||
$orderDirection = request('sort_direction', 'desc');
|
||||
|
||||
if (! in_array($orderColumn, ['id', 'name', 'created_at'])) {
|
||||
$orderColumn = 'id';
|
||||
}
|
||||
if (! in_array($orderDirection, ['asc', 'desc'])) {
|
||||
$orderDirection = 'desc';
|
||||
}
|
||||
|
||||
return $this->model::query()
|
||||
->when($request->search, function ($query) use ($request) {
|
||||
$query->where('name', 'like', $request->search.'%');
|
||||
})
|
||||
->orderBy($orderColumn, $orderDirection)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getById(int $id)
|
||||
{
|
||||
$record = $this->model::find($id);
|
||||
|
||||
return $record ?? null;
|
||||
}
|
||||
|
||||
public function create(array $data)
|
||||
{
|
||||
return $this->model::create($data);
|
||||
}
|
||||
|
||||
public function update(int $id, array $data)
|
||||
{
|
||||
$model = $this->model::findOrFail($id);
|
||||
$model->update($data);
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function delete(int $id)
|
||||
{
|
||||
$model = $this->model::findOrFail($id);
|
||||
|
||||
return $model->delete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Restaurant;
|
||||
|
||||
use App\Interfaces\Restaurant\RestaurantInterface;
|
||||
use Modules\Authentication\Models\Restaurant;
|
||||
|
||||
final class RestaurantService implements RestaurantInterface
|
||||
{
|
||||
public function __construct(
|
||||
protected Restaurant $model
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get categories by filtering args.
|
||||
*/
|
||||
public function get(array $args = []): \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Builder
|
||||
{
|
||||
$orderBy = empty($args['order_by']) ? 'id' : $args['order_by']; // column name
|
||||
$order = empty($args['order']) ? 'desc' : $args['order']; // asc, desc
|
||||
$query = Restaurant::orderBy($orderBy, $order);
|
||||
|
||||
if (isset($args['is_query']) && $args['is_query']) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
public function index($request, int $per_page = 50)
|
||||
{
|
||||
$orderColumn = request('sort_column', 'id');
|
||||
$orderDirection = request('sort_direction', 'desc');
|
||||
|
||||
if (! in_array($orderColumn, ['id', 'name', 'created_at'])) {
|
||||
$orderColumn = 'id';
|
||||
}
|
||||
if (! in_array($orderDirection, ['asc', 'desc'])) {
|
||||
$orderDirection = 'desc';
|
||||
}
|
||||
|
||||
return $this->model::query()
|
||||
->when($request->search, function ($query) use ($request) {
|
||||
$query->where('name', 'like', '%'.$request->search.'%');
|
||||
})
|
||||
->orderBy($orderColumn, $orderDirection)
|
||||
->paginate($per_page);
|
||||
}
|
||||
|
||||
public function getAll($request)
|
||||
{
|
||||
$orderColumn = request('sort_column', 'id');
|
||||
$orderDirection = request('sort_direction', 'desc');
|
||||
|
||||
if (! in_array($orderColumn, ['id', 'name', 'created_at'])) {
|
||||
$orderColumn = 'id';
|
||||
}
|
||||
if (! in_array($orderDirection, ['asc', 'desc'])) {
|
||||
$orderDirection = 'desc';
|
||||
}
|
||||
|
||||
return $this->model::query()
|
||||
->when($request->search, function ($query) use ($request) {
|
||||
$query->where('name', 'like', $request->search.'%');
|
||||
})
|
||||
->orderBy($orderColumn, $orderDirection)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getById(int $id)
|
||||
{
|
||||
$record = $this->model::find($id);
|
||||
|
||||
return $record ?? null;
|
||||
}
|
||||
|
||||
public function create(array $data)
|
||||
{
|
||||
return $this->model::create($data);
|
||||
}
|
||||
|
||||
public function update(int $id, array $data)
|
||||
{
|
||||
$model = $this->model::findOrFail($id);
|
||||
$model->update($data);
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function delete(int $id)
|
||||
{
|
||||
$model = $this->model::findOrFail($id);
|
||||
|
||||
return $model->delete();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user