90 lines
2.4 KiB
PHP
90 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Services\Api\UserManagementService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Session;
|
|
|
|
class UserManagementController extends Controller
|
|
{
|
|
protected $userService;
|
|
protected $apiBaseUrl = 'http://192.168.100.6:8081/api'; // Same as in AuthController
|
|
|
|
public function __construct(UserManagementService $userService)
|
|
{
|
|
$this->userService = $userService;
|
|
}
|
|
|
|
/**
|
|
* Display the user management page with user data
|
|
*/
|
|
public function index()
|
|
{
|
|
$response = $this->userService->getAllUsers();
|
|
|
|
if (!$response['success']) {
|
|
return back()->with('error', $response['message']);
|
|
}
|
|
|
|
return view('pages.user-management.index', [
|
|
'users' => $response['data']
|
|
]);
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
return view('pages.user-management.create');
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$response = $this->userService->createUser($request->all());
|
|
|
|
if (!$response['success']) {
|
|
return back()->withInput()->with('error', $response['message']);
|
|
}
|
|
|
|
return redirect()->route('user-management.index')
|
|
->with('success', 'User created successfully');
|
|
}
|
|
|
|
public function edit($id)
|
|
{
|
|
$response = $this->userService->getUser($id);
|
|
|
|
if (!$response['success']) {
|
|
return back()->with('error', $response['message']);
|
|
}
|
|
|
|
return view('pages.user-management.edit', [
|
|
'user' => $response['data']
|
|
]);
|
|
}
|
|
|
|
public function update(Request $request, $id)
|
|
{
|
|
$response = $this->userService->updateUser($id, $request->all());
|
|
|
|
if (!$response['success']) {
|
|
return back()->withInput()->with('error', $response['message']);
|
|
}
|
|
|
|
return redirect()->route('user-management.index')
|
|
->with('success', 'User updated successfully');
|
|
}
|
|
|
|
public function destroy($id)
|
|
{
|
|
$response = $this->userService->deleteUser($id);
|
|
|
|
if (!$response['success']) {
|
|
return back()->with('error', $response['message']);
|
|
}
|
|
|
|
return redirect()->route('user-management.index')
|
|
->with('success', 'User deleted successfully');
|
|
}
|
|
} |