device user list based on customer, login, create alarm

This commit is contained in:
sayliraut
2025-03-26 11:37:58 +05:30
parent 6cfc5cd0dd
commit 0d7103ebbe
10 changed files with 350 additions and 37 deletions

View File

@@ -0,0 +1,65 @@
<?php
namespace App\Http\Controllers;
use App\Services\AlarmService;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Exception;
use Illuminate\Http\Request;
class AlarmController extends Controller
{
protected $alarmService;
public function __construct(AlarmService $alarmService)
{
$this->alarmService = $alarmService;
}
public function createOrUpdateAlarm(Request $request)
{
try {
$alarmData = [
'type' => $request->type ?? null,
'severity' => $request->severity ?? null,
'acknowledged' => false ?? null,
'cleared' => $request->cleared ?? Carbon::now()->timestamp,
'startTs' => $request->startTs ?? Carbon::now()->timestamp,
'endTs' => $request->endTs ?? Carbon::now()->timestamp,
'details' => $request->details ?? [],
'propagate' => $request->propagate ?? false,
'propagateToOwner' => $request->propagateToOwner ?? false,
'propagateToTenant' => $request->propagateToTenant ?? false,
'originator' => $request->originator ?? 1,
'assigneeId' => $request->assigneeId ?? 1,
];
// Handle updating existing alarm
if (!empty($request->id)) {
$alarmData['id'] = $request->id;
}
// Call Service to create/update device
$apiResponse = $this->alarmService->createOrUpdateAlarm($alarmData);
return jsonResponseWithSuccessMessage(
!empty($request->id) ? 'Alarm updated successfully' : 'Alarm created successfully',
['api_response' => $apiResponse]
);
} catch (Exception $e) {
Log::error("Error: " . $e->getMessage());
$errorResponse = json_decode($e->getMessage(), true);
if (json_last_error() === JSON_ERROR_NONE) {
return jsonResponseWithErrorMessage($errorResponse['message'] ?? 'Something went wrong', 400, $errorResponse);
}
return jsonResponseWithErrorMessage($e->getMessage(), 500);
}
}
}