feat: Implement new admin API endpoints for product, customer, vCenter, and authentication, and add vCenter resource management UI.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\Customer;
|
||||
|
||||
use App\Models\Customer;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
class AdminCustomerRepository implements AdminCustomerRepositoryInterface
|
||||
{
|
||||
private const STATUS_MAP = [
|
||||
'active' => 1,
|
||||
'inactive' => 2,
|
||||
'pending' => 0,
|
||||
'suspended' => 3,
|
||||
];
|
||||
|
||||
public function paginate(array $filters, int $perPage): LengthAwarePaginator
|
||||
{
|
||||
$query = Customer::query()->orderBy('id', 'desc');
|
||||
|
||||
if ($filter = $filters['filter'] ?? null) {
|
||||
$query->where(function ($q) use ($filter) {
|
||||
$q->where('fullname', 'like', "%{$filter}%")
|
||||
->orWhere('email', 'like', "%{$filter}%")
|
||||
->orWhere('phone', 'like', "%{$filter}%");
|
||||
});
|
||||
}
|
||||
|
||||
if ($status = $filters['status'] ?? null) {
|
||||
$statusInt = self::STATUS_MAP[$status] ?? null;
|
||||
if ($statusInt !== null) {
|
||||
$query->where('status', $statusInt);
|
||||
}
|
||||
}
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\Customer;
|
||||
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
interface AdminCustomerRepositoryInterface
|
||||
{
|
||||
public function paginate(array $filters, int $perPage): LengthAwarePaginator;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\Invoice;
|
||||
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
class AdminInvoiceRepository implements AdminInvoiceRepositoryInterface
|
||||
{
|
||||
public function paginate(array $filters, int $perPage): LengthAwarePaginator
|
||||
{
|
||||
$query = Invoice::with('customer')->orderBy('id', 'desc');
|
||||
|
||||
if ($filter = $filters['filter'] ?? null) {
|
||||
$query->where(function ($q) use ($filter) {
|
||||
$q->where('order_num', 'like', "%{$filter}%")
|
||||
->orWhereHas('customer', fn($q2) =>
|
||||
$q2->where('fullname', 'like', "%{$filter}%")
|
||||
->orWhere('email', 'like', "%{$filter}%")
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
if (($status = $filters['status'] ?? null) !== null && $status !== '') {
|
||||
$query->where('status', (int) $status);
|
||||
}
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\Invoice;
|
||||
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
interface AdminInvoiceRepositoryInterface
|
||||
{
|
||||
public function paginate(array $filters, int $perPage): LengthAwarePaginator;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\Order;
|
||||
|
||||
use App\Models\Order;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
class AdminOrderRepository implements AdminOrderRepositoryInterface
|
||||
{
|
||||
public function paginate(array $filters, int $perPage): LengthAwarePaginator
|
||||
{
|
||||
$query = Order::with('customer')->orderBy('id', 'desc');
|
||||
|
||||
if ($filter = $filters['filter'] ?? null) {
|
||||
$query->where(function ($q) use ($filter) {
|
||||
$q->where('order_num', 'like', "%{$filter}%")
|
||||
->orWhereHas('customer', fn($q2) =>
|
||||
$q2->where('fullname', 'like', "%{$filter}%")
|
||||
->orWhere('email', 'like', "%{$filter}%")
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
if (($status = $filters['status'] ?? null) !== null && $status !== '') {
|
||||
$query->where('status', (int) $status);
|
||||
}
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\Order;
|
||||
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
interface AdminOrderRepositoryInterface
|
||||
{
|
||||
public function paginate(array $filters, int $perPage): LengthAwarePaginator;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\Product;
|
||||
|
||||
use App\Models\Product;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
class AdminProductRepository implements AdminProductRepositoryInterface
|
||||
{
|
||||
public function paginate(array $filters, int $perPage): LengthAwarePaginator
|
||||
{
|
||||
$query = Product::with(['category', 'pricings' => fn($q) => $q->where('is_active', true)])
|
||||
->orderBy('id', 'desc');
|
||||
|
||||
if ($filter = $filters['filter'] ?? null) {
|
||||
$query->where('name', 'like', "%{$filter}%");
|
||||
}
|
||||
|
||||
if ($type = $filters['type'] ?? null) {
|
||||
$query->where('product_type', $type);
|
||||
}
|
||||
|
||||
if (isset($filters['is_active']) && $filters['is_active'] !== '') {
|
||||
$query->where('is_active', filter_var($filters['is_active'], FILTER_VALIDATE_BOOLEAN));
|
||||
}
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
|
||||
public function findWithPricings(int $id): ?Product
|
||||
{
|
||||
return Product::with(['category', 'pricings'])->find($id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\Product;
|
||||
|
||||
use App\Models\Product;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
interface AdminProductRepositoryInterface
|
||||
{
|
||||
public function paginate(array $filters, int $perPage): LengthAwarePaginator;
|
||||
public function findWithPricings(int $id): ?Product;
|
||||
}
|
||||
Reference in New Issue
Block a user