Conflicts resolved
This commit is contained in:
144
app/Http/Controllers/APIS/AdminApi/AlarmController.php
Normal file
144
app/Http/Controllers/APIS/AdminApi/AlarmController.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\APIS\AdminApi;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\AdminService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\AlarmService;
|
||||
use Exception;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class AlarmController extends Controller
|
||||
{
|
||||
//
|
||||
|
||||
protected $adminService;
|
||||
|
||||
public function __construct(AdminService $adminService)
|
||||
{
|
||||
$this->adminService = $adminService;
|
||||
}
|
||||
|
||||
|
||||
public function fetchAlarm(Request $request)
|
||||
{
|
||||
try {
|
||||
// Get parameters from request
|
||||
$severityList = $request->query('severityList', []);
|
||||
$startTime = $request->query('startTime', null);
|
||||
$endTime = $request->query('endTime', null);
|
||||
|
||||
// Convert string to array if severityList is a single value
|
||||
if (!is_array($severityList)) {
|
||||
$severityList = explode(',', $severityList);
|
||||
}
|
||||
|
||||
// Debugging: Check received parameters
|
||||
Log::info("Fetching alarms with severityList: " . implode(', ', $severityList) .
|
||||
", startTime: $startTime, endTime: $endTime");
|
||||
|
||||
// Get token for authentication
|
||||
$token = $this->adminService->getToken();
|
||||
if (!$token) {
|
||||
Log::error("Failed to authenticate with ThingsBoard.");
|
||||
return response()->json(['error' => 'Authentication failed'], 401);
|
||||
}
|
||||
|
||||
// Build API URL with required parameters
|
||||
$url = "http://65.0.131.117:8080/api/v2/alarms?pageSize=10&page=0";
|
||||
|
||||
// Append severityList if provided
|
||||
if (!empty($severityList)) {
|
||||
foreach ($severityList as $severity) {
|
||||
$url .= "&severityList=" . urlencode($severity);
|
||||
}
|
||||
}
|
||||
|
||||
// Append startTime and endTime if provided
|
||||
if (!empty($startTime)) {
|
||||
$url .= "&startTime=" . urlencode($startTime);
|
||||
}
|
||||
if (!empty($endTime)) {
|
||||
$url .= "&endTime=" . urlencode($endTime);
|
||||
}
|
||||
|
||||
Log::info("Final API URL: " . $url); // Debugging
|
||||
|
||||
// Make API request
|
||||
$response = Http::withHeaders([
|
||||
'Authorization' => "Bearer $token",
|
||||
'Accept' => 'application/json',
|
||||
])->get($url);
|
||||
|
||||
if (!$response->successful()) {
|
||||
Log::error("Failed to fetch ThingsBoard alarms: " . $response->body());
|
||||
return response()->json(['error' => 'Failed to fetch alarms'], 500);
|
||||
}
|
||||
|
||||
// Return filtered data
|
||||
return response()->json(['alarmResponse' => $response->json()['data'] ?? []]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error("Error fetching ThingsBoard alarms: " . $e->getMessage());
|
||||
return response()->json(['error' => 'Server error'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function acknowledgeAlarm(Request $request)
|
||||
{
|
||||
try {
|
||||
// Get alarmId from request
|
||||
$alarmId = $request->input('alarmId');
|
||||
dd($alarmId);
|
||||
|
||||
// Validate alarmId
|
||||
if (!$alarmId) {
|
||||
return response()->json(['error' => 'alarmId is required'], 400);
|
||||
}
|
||||
|
||||
// Debugging: Log received alarm ID
|
||||
Log::info("Acknowledging alarm with ID: $alarmId");
|
||||
|
||||
// Get token for authentication
|
||||
$token = $this->adminService->getToken();
|
||||
if (!$token) {
|
||||
Log::error("Failed to authenticate with ThingsBoard.");
|
||||
return response()->json(['error' => 'Authentication failed'], 401);
|
||||
}
|
||||
|
||||
// Build API URL using alarmId from request
|
||||
$url = "http://65.0.131.117:8080/api/v2/alarm/{$alarmId}/ack?alarmId={$alarmId}";
|
||||
|
||||
Log::info("Final API URL: " . $url); // Debugging
|
||||
|
||||
// Make API request
|
||||
$response = Http::withHeaders([
|
||||
'Authorization' => "Bearer $token",
|
||||
'Accept' => 'application/json',
|
||||
])->post($url);
|
||||
|
||||
if (!$response->successful()) {
|
||||
Log::error("Failed to acknowledge ThingsBoard alarm: " . $response->body());
|
||||
return response()->json(['error' => 'Failed to acknowledge alarm'], 500);
|
||||
}
|
||||
|
||||
// Return success response
|
||||
return response()->json([
|
||||
'message' => 'Alarm acknowledged successfully',
|
||||
'alarmId' => $alarmId
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error("Error acknowledging ThingsBoard alarm: " . $e->getMessage());
|
||||
return response()->json(['error' => 'Server error'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\APIS\CustomerApi;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Reports;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
|
||||
|
||||
class DownloadsController extends Controller
|
||||
{
|
||||
//
|
||||
public function storePdfData(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'user_id' => ['required'],
|
||||
'device_xid' => ['required'],
|
||||
'start_date' => ['required'],
|
||||
'end_date' => ['required'],
|
||||
'report_type' => ['required'],
|
||||
'download_status' => ['required'],
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'status' => 422,
|
||||
'message' => 'Validation failed',
|
||||
'errors' => $validator->errors()
|
||||
]);
|
||||
}
|
||||
|
||||
$data = Reports::create([
|
||||
'request_time' => Carbon::now(),
|
||||
'user_id' => $request->user_id,
|
||||
'device_xid' => $request->device_xid,
|
||||
'start_date' => $request->start_date,
|
||||
'end_date' => $request->end_date,
|
||||
'report_type' => $request->report_type,
|
||||
'download_status' => $request->download_status,
|
||||
]);
|
||||
|
||||
if ($data) {
|
||||
return response()->json([
|
||||
'status' => 200,
|
||||
'message' => 'Report data saved successfully',
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function fetchReport(Request $request)
|
||||
{
|
||||
$userId = Auth::id();
|
||||
$data = Reports::where('user_id', $userId)->whereNull('deleted_at')->get();
|
||||
if($data){
|
||||
return response()->json([
|
||||
'status' => 200,
|
||||
'message' => 'Report data fetch successfully',
|
||||
'data' => $data
|
||||
]);
|
||||
|
||||
}else{
|
||||
return response()->json([
|
||||
'status' => 404,
|
||||
'message' => 'Report data not found',
|
||||
'data' => $data
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function destroyReport()
|
||||
{
|
||||
$userId = Auth::id();
|
||||
$data = Reports::where('user_id', $userId)->whereNull('deleted_at')->delete();
|
||||
if ($data) {
|
||||
return response()->json([
|
||||
'status' => 200,
|
||||
'message' => 'Report data deleted successfully',
|
||||
'data' => $data
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'status' => 404,
|
||||
'message' => 'Report data not found',
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
16
app/Models/Reports.php
Normal file
16
app/Models/Reports.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
|
||||
class Reports extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
//
|
||||
protected $table ="reports";
|
||||
protected $guarded =[];
|
||||
protected $dates = ['deleted_at'];
|
||||
}
|
||||
@@ -2,107 +2,273 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\TimeseriesKeyMaster;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use App\Services\AdminService;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
|
||||
class AlarmService
|
||||
{
|
||||
private $baseUrl;
|
||||
private $username;
|
||||
private $password;
|
||||
protected $adminService;
|
||||
|
||||
public function __construct()
|
||||
public function __construct(AdminService $adminService)
|
||||
{
|
||||
$this->baseUrl = env('THINGSBOARD_URL', 'http://65.0.131.117:8080');
|
||||
$this->username = env('THINGSBOARD_USERNAME', 'tenant1@thingsboard.org');
|
||||
$this->password = env('THINGSBOARD_PASSWORD', 'tenant1');
|
||||
$this->adminService = $adminService;
|
||||
}
|
||||
|
||||
public function getToken()
|
||||
public function getAdminAlarm($data)
|
||||
{
|
||||
if (Cache::has('thingsboard_token')) {
|
||||
return Cache::get('thingsboard_token');
|
||||
}
|
||||
try {
|
||||
|
||||
$response = Http::withHeaders([
|
||||
'accept' => 'application/json',
|
||||
'Content-Type' => 'application/json',
|
||||
])
|
||||
->post("{$this->baseUrl}/api/auth/login", [
|
||||
'username' => $this->username,
|
||||
'password' => $this->password,
|
||||
]);
|
||||
$token = $this->adminService->getToken();
|
||||
|
||||
if (!$token) {
|
||||
Log::error("Failed to authenticate with ThingsBoard.");
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($response->successful()) {
|
||||
$token = $response->json('token');
|
||||
Cache::put('thingsboard_token', $token, now()->addMinutes(15));
|
||||
return $token;
|
||||
} else {
|
||||
Log::error("ThingsBoard Authentication Failed: " . $response->body());
|
||||
throw new Exception('Unable to authenticate with ThingsBoard: ' . $response->body());
|
||||
$response = Http::withHeaders([
|
||||
'Authorization' => "Bearer $token",
|
||||
'Accept' => 'application/json',
|
||||
])->get("http://65.0.131.117:8080/api/v2/alarms?pageSize=10&page=0");
|
||||
|
||||
if (!$response->successful()) {
|
||||
Log::error("Failed to fetch ThingsBoard devices: " . $response->body());
|
||||
return [];
|
||||
}
|
||||
|
||||
return $response->json()['data'] ?? [];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error("Error fetching ThingsBoard devices: " . $e->getMessage());
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// public function getTelemetryData($devices, $startTs, $endTs, $limit = 100)
|
||||
// {
|
||||
// try {
|
||||
// // Get ThingsBoard token from AdminService
|
||||
// $token = $this->adminService->getToken();
|
||||
|
||||
public function createOrUpdateAlarm(array $data)
|
||||
// if (!$token) {
|
||||
// Log::error("Failed to authenticate with ThingsBoard.");
|
||||
// return ['error' => 'Authentication failed'];
|
||||
// }
|
||||
|
||||
// $baseUrl = env('THINGSBOARD_URL', 'http://65.0.131.117:8080');
|
||||
// $telemetryData = [];
|
||||
|
||||
// foreach ($devices as $device) {
|
||||
// $deviceToken = $device->token;
|
||||
|
||||
// // Include asset_id, device_profile_id, and device name
|
||||
// $assetId = $device->asset_id;
|
||||
// $deviceProfileId = $device->device_profile_id;
|
||||
// $deviceName = $device->name;
|
||||
|
||||
// if (!$deviceToken) {
|
||||
// Log::warning("Device token missing for device: {$deviceName} (ID: {$device->id})");
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// $keys = $device->timeseriesKeys->pluck('key_name')->implode(',');
|
||||
|
||||
// if (empty($keys)) {
|
||||
// Log::warning("No telemetry keys found for device: {$deviceName} (Token: {$deviceToken})");
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// // Make the telemetry API call
|
||||
// $response = Http::withHeaders([
|
||||
// 'X-Authorization' => "Bearer $token",
|
||||
// 'Accept' => 'application/json',
|
||||
// ])->get("{$baseUrl}/api/plugins/telemetry/DEVICE/{$deviceToken}/values/timeseries", [
|
||||
// 'keys' => $keys,
|
||||
// 'startTs' => $startTs,
|
||||
// 'endTs' => $endTs,
|
||||
// 'limit' => $limit,
|
||||
// 'useStrictDataTypes' => 'false',
|
||||
// ]);
|
||||
|
||||
// if (!$response->successful()) {
|
||||
// Log::error("Failed to fetch telemetry for device: {$deviceName} (Token: {$deviceToken})");
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// $data = $response->json();
|
||||
|
||||
// // Format telemetry data with asset_id, device_profile_id, and name as key
|
||||
// $formattedTelemetry = [];
|
||||
|
||||
// if (!empty($data)) {
|
||||
// foreach ($data as $key => $values) {
|
||||
// foreach ($values as $item) {
|
||||
// $formattedTelemetry[] = [
|
||||
// 'key' => $key,
|
||||
// 'value' => $item['value'],
|
||||
// 'ts' => $item['ts']
|
||||
// ];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// $telemetryData[] = [
|
||||
// 'asset_id' => $assetId,
|
||||
// 'device_profile_id' => $deviceProfileId,
|
||||
// 'name' => $deviceName,
|
||||
// 'telemetry' => $formattedTelemetry,
|
||||
// ];
|
||||
// }
|
||||
|
||||
// return $telemetryData;
|
||||
|
||||
// } catch (\Exception $e) {
|
||||
// Log::error("Error fetching telemetry data: " . $e->getMessage());
|
||||
// return ['error' => 'Failed to fetch telemetry data'];
|
||||
// }
|
||||
// }
|
||||
|
||||
// public function getTelemetryData($devices, $startTs, $endTs)
|
||||
// {
|
||||
// $token = $this->adminService->getToken();
|
||||
|
||||
// if (!$token) {
|
||||
// Log::error('Failed to fetch ThingsBoard token');
|
||||
// return ['error' => 'Failed to fetch ThingsBoard token'];
|
||||
// }
|
||||
|
||||
// $baseUrl = env('THINGSBOARD_URL');
|
||||
|
||||
// $headers = [
|
||||
// 'Authorization: Bearer ' . $token,
|
||||
// 'accept: application/json'
|
||||
// ];
|
||||
|
||||
// $allTelemetry = [];
|
||||
|
||||
// foreach ($devices as $device) {
|
||||
// $deviceId = $device->id;
|
||||
// $keys = $device->timeseriesKeys->pluck('key_name')->filter()->implode(',');
|
||||
|
||||
// if (empty($keys)) {
|
||||
// Log::warning("No telemetry keys found for device: {$device->name}");
|
||||
// $allTelemetry[$deviceId] = [
|
||||
// 'status' => 'error',
|
||||
// 'message' => 'No telemetry keys found'
|
||||
// ];
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// $url = "$baseUrl/api/plugins/telemetry/DEVICE/{$deviceId}/values/timeseries"
|
||||
// . "?keys={$keys}&startTs={$startTs}&endTs={$endTs}&limit=100";
|
||||
|
||||
// $ch = curl_init($url);
|
||||
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
// $response = curl_exec($ch);
|
||||
// $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
// $error = curl_error($ch);
|
||||
// curl_close($ch);
|
||||
|
||||
// if ($error || $httpCode !== 200) {
|
||||
// Log::error("Failed to fetch telemetry for device: {$device->name} (ID: {$deviceId})", [
|
||||
// 'http_code' => $httpCode,
|
||||
// 'error' => $error,
|
||||
// 'url' => $url,
|
||||
// 'response' => $response
|
||||
// ]);
|
||||
|
||||
// $allTelemetry[$deviceId] = [
|
||||
// 'status' => 'error',
|
||||
// 'message' => "Failed to fetch telemetry. HTTP Code: $httpCode, Error: $error"
|
||||
// ];
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// $telemetry = json_decode($response, true);
|
||||
|
||||
// if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
// Log::error("Failed to decode telemetry response for device: {$device->name}", [
|
||||
// 'response' => $response
|
||||
// ]);
|
||||
|
||||
// $allTelemetry[$deviceId] = [
|
||||
// 'status' => 'error',
|
||||
// 'message' => 'Invalid telemetry response format'
|
||||
// ];
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// $allTelemetry[$deviceId] = [
|
||||
// 'status' => 'success',
|
||||
// 'telemetry' => $telemetry
|
||||
// ];
|
||||
// }
|
||||
|
||||
// return $allTelemetry; // Return telemetry data mapped by device_id
|
||||
// }
|
||||
|
||||
|
||||
|
||||
public function getTelemetryData($device, $keyNames, $startTs, $endTs)
|
||||
{
|
||||
$token = $this->adminService->getToken();
|
||||
|
||||
$token = $this->getToken();
|
||||
|
||||
$payload = [
|
||||
'type' => $data['type'] ?? null,
|
||||
'severity' => $data['severity'] ?? null,
|
||||
'acknowledged' => $data['acknowledged'] ?? null,
|
||||
'cleared' => $data['cleared'] ?? Carbon::now()->timestamp,
|
||||
'startTs' => $data['startTs'] ?? Carbon::now()->timestamp,
|
||||
'endTs' => $data['endTs'] ?? Carbon::now()->timestamp,
|
||||
'originator' => [
|
||||
'id' => $data['originator'] ?? null,
|
||||
'entityType' => 'DEVICE'
|
||||
],
|
||||
'assigneeId' => [
|
||||
'id' => $data['assigneeId'] ?? null,
|
||||
'entityType' => 'USER'
|
||||
],
|
||||
'details' => $data['details'] ?? [],
|
||||
'propagate' => $data['propagate'] ?? false,
|
||||
'propagateToOwner' => $data['propagateToOwner'] ?? false,
|
||||
|
||||
];
|
||||
|
||||
|
||||
// Optional fields
|
||||
if (!empty($data['id'])) {
|
||||
$payload['id'] = [
|
||||
'id' => $data['id'],
|
||||
'entityType' => 'ALARM'
|
||||
];
|
||||
if (!$token) {
|
||||
Log::error('Failed to fetch ThingsBoard token');
|
||||
return ['error' => 'Failed to fetch ThingsBoard token'];
|
||||
}
|
||||
|
||||
$baseUrl = env('THINGSBOARD_URL');
|
||||
$deviceId = $device->id;
|
||||
|
||||
$keys = implode(',', $keyNames);
|
||||
|
||||
|
||||
$url = "{$this->baseUrl}/api/alarm";
|
||||
$method = 'post';
|
||||
|
||||
$response = Http::withHeaders([
|
||||
'Authorization' => "Bearer $token",
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json',
|
||||
])->post($url, $payload);
|
||||
'Accept' => 'application/json'
|
||||
])->get("$baseUrl/api/plugins/telemetry/DEVICE/58bf81a0-0619-11f0-a9dc-45dd276e4cd5/values/timeseries", [
|
||||
// ])->get("$baseUrl/api/plugins/telemetry/DEVICE/{$deviceId}/values/timeseries", [
|
||||
|
||||
'keys' => $keys,
|
||||
// 'keys' => 'MechanicalHealth_valueInPercent',
|
||||
'startTs' => $startTs,
|
||||
'interval' => $endTs,
|
||||
'limit' => 100,
|
||||
'useStrictDataTypes' => false
|
||||
]);
|
||||
|
||||
// dd($response);
|
||||
|
||||
// Check if the response was successful
|
||||
if (!$response->successful()) {
|
||||
Log::error("API Error Response:", ['body' => $response->body()]);
|
||||
throw new Exception('API Error: ' . $response->body());
|
||||
Log::error("Failed to fetch telemetry for device: {$device->name} (ID: {$deviceId})", [
|
||||
'http_code' => $response->status(),
|
||||
'url' => $response->effectiveUri(),
|
||||
'response' => $response->body()
|
||||
]);
|
||||
|
||||
return ['error' => "Failed to fetch telemetry. HTTP Code: " . $response->status()];
|
||||
}
|
||||
|
||||
$apiResponse = $response->json();
|
||||
// Decode the telemetry response
|
||||
$telemetry = $response->json();
|
||||
|
||||
return $apiResponse;
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
Log::error("Failed to decode telemetry response for device: {$device->name}", [
|
||||
'response' => $response->body()
|
||||
]);
|
||||
|
||||
return ['error' => 'Invalid telemetry response format'];
|
||||
}
|
||||
|
||||
return $telemetry;
|
||||
}
|
||||
|
||||
|
||||
@@ -142,32 +308,32 @@ class AlarmService
|
||||
}
|
||||
|
||||
|
||||
public function deleteDevice(array $data)
|
||||
{
|
||||
$token = $this->getToken();
|
||||
// public function deleteDevice(array $data)
|
||||
// {
|
||||
// $token = $this->getToken();
|
||||
|
||||
|
||||
$url = "{$this->baseUrl}/api/device/{$data['deviceId']}";
|
||||
// $url = "{$this->baseUrl}/api/device/{$data['deviceId']}";
|
||||
|
||||
$response = Http::withHeaders([
|
||||
'Authorization' => "Bearer $token",
|
||||
'Accept' => 'application/json',
|
||||
])->delete($url);
|
||||
// $response = Http::withHeaders([
|
||||
// 'Authorization' => "Bearer $token",
|
||||
// 'Accept' => 'application/json',
|
||||
// ])->delete($url);
|
||||
|
||||
|
||||
|
||||
// If response body is empty, assume success
|
||||
if ($response->status() === 200 && empty($response->body())) {
|
||||
return ['message' => 'Device deleted successfully'];
|
||||
}
|
||||
// // If response body is empty, assume success
|
||||
// if ($response->status() === 200 && empty($response->body())) {
|
||||
// return ['message' => 'Device deleted successfully'];
|
||||
// }
|
||||
|
||||
if ($response->successful()) {
|
||||
return $response->json();
|
||||
} else {
|
||||
throw new Exception('Failed to create Device: ' . $response->body());
|
||||
Log::info('API Response:', ['response' => $response]);
|
||||
}
|
||||
// if ($response->successful()) {
|
||||
// return $response->json();
|
||||
// } else {
|
||||
// throw new Exception('Failed to create Device: ' . $response->body());
|
||||
// Log::info('API Response:', ['response' => $response]);
|
||||
// }
|
||||
|
||||
throw new Exception('Failed to create user: ' . $response->body());
|
||||
}
|
||||
// throw new Exception('Failed to create user: ' . $response->body());
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?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::create('reports', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->timestamp('request_time')->nullable();;
|
||||
$table->string('device_xid');
|
||||
$table->timestamp('start_date')->nullable();;
|
||||
$table->timestamp('end_date')->nullable();;
|
||||
$table->boolean('report_type')->default(false)->comment('Report status: 0 = pdf, 1 = spreadsheet');
|
||||
$table->boolean('download_status')->default(false)->comment('Download status: 0 = failed, 1 = completed');
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('reports');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
<?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('reports', function (Blueprint $table) {
|
||||
//
|
||||
$table->string('user_id')->nullable()->after('request_time'); // Change 'existing_column' to the column after which you want to add the new column
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('reports', function (Blueprint $table) {
|
||||
//
|
||||
$table->dropColumn('user_id');
|
||||
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -2,14 +2,13 @@
|
||||
|
||||
// use App\Http\Controllers\AssetController;
|
||||
|
||||
use App\Http\Controllers\AlarmController;
|
||||
use App\Http\Controllers\APIS\AdminApi\CustomerController;
|
||||
use App\Http\Controllers\APIS\AdminApi\AlarmController;
|
||||
use App\Http\Controllers\APIS\CustomerApi\CustomerController;
|
||||
use App\Http\Controllers\APIS\AdminApi\UsersController;
|
||||
use App\Http\Controllers\APIS\AdminApi\DeviceController;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use App\Http\Controllers\APIS\AdminApi\AssetadmintController;
|
||||
use App\Http\Controllers\APIS\AdminApi\TelemetryController;
|
||||
|
||||
use App\Http\Controllers\APIS\AdminApi\DeviceProfileMasterController;
|
||||
use App\Http\Controllers\APIS\AdminApi\LoginController;
|
||||
|
||||
@@ -8,6 +8,8 @@ use Tymon\JWTAuth\Facades\JWTAuth;
|
||||
use App\Http\Controllers\APIS\CustomerApi\AuthController;
|
||||
use App\Http\Controllers\APIS\CustomerApi\CustomerDeviceInfoController;
|
||||
use App\Http\Controllers\APIS\CustomerApi\TelemetryController;
|
||||
use App\Http\Controllers\APIS\CustomerApi\DownloadsController as CustomerApiDownloadsController;
|
||||
|
||||
|
||||
Route::get('/customerapi', function () {
|
||||
return ('Welcome to admin api routes.');
|
||||
@@ -20,10 +22,15 @@ Route::post('/telemetry-data-device-diagnostic',[TelemetryController::class,'tel
|
||||
Route::get('/customer-device-info',[CustomerDeviceInfoController::class,'customerDeviceInfo']);
|
||||
|
||||
|
||||
|
||||
// Route::post('/user-login', [AuthController::class, 'login']);
|
||||
Route::middleware(['customerApiBasicAuth'])->group(function () {
|
||||
Route::get('/user-assets', [UserAssetLinkController::class, 'index']);
|
||||
Route::post('/telemetry-data-asset',[TelemetryController::class,'telemetryDataAsset']);
|
||||
Route::post('/telemetry-data-device',[TelemetryController::class,'telemetryDataDevice']);
|
||||
|
||||
Route::get('/user-assets', [UserAssetLinkController::class, 'index']);
|
||||
Route::post('/store/report', [CustomerApiDownloadsController::class, 'storePdfData'])->name('store-report');
|
||||
Route::post('/fetch/report', [CustomerApiDownloadsController::class, 'fetchReport'])->name('fetch-report');
|
||||
Route::post('/destroy/report', [CustomerApiDownloadsController::class, 'destroyReport'])->name('destroy-report');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user