Files
portal-api/routes/client.php
T

138 lines
5.8 KiB
PHP

<?php
use App\Http\Controllers\Api\Setting\SettingController;
use App\Http\Controllers\Api\Client\ClientController;
use App\Http\Controllers\Api\Service\OrderController;
use App\Http\Controllers\Api\Service\ProductCategoryController;
use App\Http\Controllers\Api\Service\ServiceController;
use App\Http\Controllers\Api\Transaction\TransactionController;
use Illuminate\Support\Facades\Route;
Route::prefix('v1')->as('api.')->group(function () {
// Auth
Route::prefix('client')->as('client.')
->group(function () {
Route::controller(ClientController::class)->group(function () {
Route::post('login', 'login')->name('login');
Route::post('register', 'register')->name('register');
Route::group(['middleware' => ['api.auth']], function () {
Route::get('me', 'me')->name('me');
Route::post('logout', 'logout')->name('logout');
Route::put('update', 'update')->name('update');
});
});
Route::middleware(['api.auth'])->controller(OrderController::class)->group(function () {
Route::get('orders', 'getClientOrders')->name('orders.list');
Route::get('orders/{id}', 'getClientOrderDetail')->name('orders.detail');
Route::get('invoices', 'getClientInvoices')->name('invoices.list');
Route::get('invoices/{id}', 'getClientInvoiceDetail')->name('invoices.detail');
Route::get('dich-vu', 'getClientServices')->name('services.list');
});
});
// Services (Products) - Public & Protected Routes
Route::prefix('services')->as('services.')->group(function () {
Route::controller(ServiceController::class)->group(function () {
Route::get('get-list', 'getService')->name('getList');
Route::get('{product:slug}', 'getDetailService')->name('detail');
});
});
Route::middleware(['api.auth'])->prefix('orders')->as('orders.')->group(function () {
Route::controller(OrderController::class)->group(function () {
Route::get('/', 'getList')->name('list');
Route::post('/', 'storeOrder')->name('store');
Route::post('{id}/pay', 'payOrder')->name('pay');
});
});
Route::prefix('setting')->as('setting.')->group(function () {
Route::controller(SettingController::class)->group(function () {
Route::get('/', 'getSetting')->name('get');
});
});
// Product Categories - Public Routes (no auth required)
Route::prefix('group')->as('product-categories.')->group(function () {
Route::controller(ProductCategoryController::class)->group(function () {
Route::get('get-list', 'getCategories')->name('getList');
Route::get('{product_categories:slug}', 'getDetailCategory')->name('detail');
Route::get('{parentSlug}/{childSlug}', 'getChildCategoryWithParent')->name('childWithParent');
});
});
// Addons - Get available addons for a product
Route::prefix('products')->as('products.')->group(function () {
Route::get('{productId}/addons', [ServiceController::class, 'getProductAddons'])->name('addons');
});
Route::middleware(['api.auth'])->prefix('transaction')->as('transaction.')->group(function () {
Route::controller(TransactionController::class)->group(function () {
Route::get('get-list', 'getTransactions')->name('getList');
Route::post('pay', 'handle')->name('pay');
Route::get('verify', 'verifyPayment')->name('verify');
Route::get('detail-by-code', 'getByPublicCode')->name('detailByCode');
});
});
});
Route::get('v1/payment/vnpay/return', [TransactionController::class, 'returnCallback']);
Route::prefix('v1/system')->middleware(['api.auth'])->group(function () {
Route::get('get-ticket-console', function (\Illuminate\Http\Request $request, \App\Http\Services\vCenter $serviceVCenter) {
$product_id = $request->get('product');
if (!$product_id) {
return response()->json(['error' => true, 'message' => "Please choose product"]);
}
$product = \App\Models\ModuleVmware::with('vCenter')->find($product_id);
if (!$product) {
return response()->json(['error' => true, 'message' => "Can't find product"]);
}
$vcenter = $product->vCenter;
if (!$vcenter) {
return response()->json(['error' => true, 'message' => "Can't find vCenter information"]);
}
if (!$serviceVCenter->loginServer($vcenter)) {
return response()->json(['error' => true, 'message' => 'Không thể đăng nhập vào vCenter']);
}
$ConsoleTicket = $serviceVCenter->GetConsoleTickets($product->vmware_id);
if ($ConsoleTicket === 'Login_Again') {
if ($serviceVCenter->loginServer($vcenter)) {
$ConsoleTicket = $serviceVCenter->GetConsoleTickets($product->vmware_id);
} else {
return response()->json(['error' => true, 'message' => 'Không thể đăng nhập lại vào vCenter']);
}
}
if (is_string($ConsoleTicket)) {
return response()->json(['error' => true, 'message' => "Failed to get console ticket: $ConsoleTicket"]);
}
if ($ConsoleTicket['error']) {
return response()->json(['error' => true, 'message' => $ConsoleTicket['data']]);
}
return response()->json([
'error' => false,
'data' => $ConsoleTicket['data'], // wss://10.10.10.120:443/ticket/...
]);
});
});
Route::any('{any}', function () {
return response()->json([
'error' => true,
'message' => 'API Route not found'
], 404);
})->where('any', '.*');