Merge pull request 'add three column in user_gateways and use them in controller' (#30) from feature/GetClient into develop

Reviewed-on: #30
This commit was merged in pull request #30.
This commit is contained in:
2026-06-01 13:06:13 +00:00
3 changed files with 49 additions and 7 deletions

View File

@@ -14,6 +14,7 @@ use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Laravel\Passport\ClientRepository;
use Throwable;
class GatewayManagementController extends Controller
@@ -27,7 +28,7 @@ class GatewayManagementController extends Controller
$request,
allowedFilters: ['*'],
allowedSortings: ['*'],
allowedSelects: ['id', 'name', 'domain', 'tax_id', 'bank_name', 'account_holder', 'iban', 'business_type_id', 'business_type_name'],
allowedSelects: ['*'],
);
}
@@ -38,9 +39,15 @@ class GatewayManagementController extends Controller
{
$user = Auth::guard('web')->user();
$logo = $request->has('logo') ? FileFacade::save($request->file('logo'), "{$user->id}") : null;
$logo = $request->hasFile('logo')
? FileFacade::save($request->file('logo'), "{$user->id}")
: null;
$passportClient = DB::transaction(function () use ($user, $logo, $request) {
$clientName = "Gateway {$request->name} - User {$user->id}";
$client = app(ClientRepository::class)->createPasswordGrantClient($clientName, 'users');
DB::transaction(function () use ($user, $logo, $request) {
UserGateway::query()->create([
'user_id' => $user->id,
'username' => $user->username,
@@ -53,15 +60,20 @@ class GatewayManagementController extends Controller
'business_type_id' => $request->business_type_id,
'business_type_name' => BusinessTypeEnum::name($request->business_type_id),
'logo' => $logo,
'client_id' => $client->id,
'client_secret' => $client->secret,
]);
$user->update(['authority_level' => 1]);
return $client;
});
return $this->successResponse();
return $this->successResponse([
'client_id' => $passportClient->id,
'client_secret' => $passportClient->secret,
]);
}
public function show(UserGateway $gateway): JsonResponse
{
return $this->successResponse($gateway);

View File

@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('user_gateways', function (Blueprint $table) {
$table->string('client_id')->nullable();
$table->string('client_secret')->nullable();
$table->integer('status')->default(0);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('user_gateways', function (Blueprint $table) {
$table->dropColumn(['client_id', 'client_secret','status']);
});
}
};

View File

@@ -77,7 +77,7 @@ Route::prefix('expert')
Route::prefix('profile')
->name('profile.')
->middleware('auth')
->middleware('auth:expert')
->controller(ProfileController::class)
->group(function () {
Route::get('info', 'info')->name('info');