2025-03-21 12:11:18 +05:30
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\APIS\AdminApi;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use App\Models\DeviceProfileMaster;
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
use App\Services\AdminDeviceProfileMaster; // Include the service
|
|
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DeviceProfileMasterController extends Controller
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
protected $AdminDeviceProfileMaster;
|
|
|
|
|
|
|
|
|
|
public function __construct(AdminDeviceProfileMaster $AdminDeviceProfileMaster)
|
|
|
|
|
{
|
|
|
|
|
$this->AdminDeviceProfileMaster = $AdminDeviceProfileMaster;
|
|
|
|
|
}
|
2025-03-21 17:57:41 +05:30
|
|
|
|
2025-03-21 12:11:18 +05:30
|
|
|
public function deviceprofileMasterList()
|
|
|
|
|
{
|
|
|
|
|
try {
|
2025-03-21 17:57:41 +05:30
|
|
|
$deviceMaster = DeviceProfileMaster::select('id', 'name')->get();
|
2025-03-21 12:11:18 +05:30
|
|
|
|
2025-03-21 17:57:41 +05:30
|
|
|
return jsonResponseWithSuccessMessage('Device profile master fetched successfully', [
|
2025-03-21 12:11:18 +05:30
|
|
|
'deviceprofilemaster' => $deviceMaster
|
|
|
|
|
]);
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
Log::error("An error occurred: " . $e->getMessage());
|
|
|
|
|
return jsonResponseWithErrorMessage($e->getMessage(), 500);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updateDevice(Request $request, $deviceId)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$deviceProfileMaster = DeviceProfileMaster::find($deviceId);
|
|
|
|
|
if (!$deviceProfileMaster) {
|
2025-03-21 17:57:41 +05:30
|
|
|
return jsonResponseWithErrorMessage('No device found', 404);
|
2025-03-21 12:11:18 +05:30
|
|
|
}
|
|
|
|
|
$request->validate([
|
2025-03-21 17:57:41 +05:30
|
|
|
'name' => 'required|string|max:255'
|
|
|
|
|
]);
|
|
|
|
|
$deviceProfileMaster->name = $request->name;
|
|
|
|
|
$deviceProfileMaster->save();
|
|
|
|
|
$updatedDevice = $deviceProfileMaster->only(['id', 'name']);
|
|
|
|
|
return jsonResponseWithSuccessMessage('Device name updated successfully', [
|
|
|
|
|
'device' => $updatedDevice
|
2025-03-21 12:11:18 +05:30
|
|
|
]);
|
|
|
|
|
} catch (Exception $e) {
|
2025-03-21 17:57:41 +05:30
|
|
|
return jsonResponseWithErrorMessage('Failed to update device: ' . $e->getMessage(), 500);
|
2025-03-21 12:11:18 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|