55 lines
1.2 KiB
PHP
55 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use App\Services\FcmService;
|
|
|
|
class AlertController extends Controller
|
|
{
|
|
protected $fcm;
|
|
|
|
public function __construct(FcmService $fcm){
|
|
$this->fcm = $fcm;
|
|
}
|
|
|
|
public function send(Request $request)
|
|
{
|
|
$stationid = $request->stationid;
|
|
$level = $request->level;
|
|
$stationtype = $request->stationtype;
|
|
|
|
// $topic = match($level){
|
|
// 'Warning' => env('FCM_TOPIC_RAINFALL_WARNING'),
|
|
// 'Danger' => env('FCM_TOPIC_RAINFALL_DANGER'),
|
|
// default => env('FCM_TOPIC_RAINFALL_WARNING')
|
|
// };
|
|
|
|
$topic = env('FCM_TOPIC_RAINFALL_WARNING');
|
|
|
|
if($stationtype == 1)
|
|
{
|
|
$station = 'Rainfall';
|
|
}
|
|
elseif($stationtype == 2)
|
|
{
|
|
$station = 'Water Level';
|
|
}
|
|
elseif ($stationtype == 3)
|
|
{
|
|
$station = 'Siren';
|
|
}
|
|
|
|
$title = "{$station} {$level} Alert";
|
|
$body = "{$stationid} : {$station} Have Triggered {$level}";
|
|
|
|
$status = $this->fcm->sendToTopic($topic,$title,$body);
|
|
|
|
return response()->json(['status'=>$status]);
|
|
|
|
}
|
|
|
|
|
|
}
|