Skip to content

Commit

Permalink
add agif warning
Browse files Browse the repository at this point in the history
  • Loading branch information
tomahock committed May 29, 2024
1 parent cb48332 commit 0aba1de
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
24 changes: 24 additions & 0 deletions app/Http/Controllers/WarningsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace App\Http\Controllers;

use App\Models\Warning;
use App\Models\WarningAgif;
use App\Models\WeatherStation;
use App\Tools\BlueskyTool;
use App\Tools\FacebookTool;
use App\Tools\NotificationTool;
use App\Tools\TelegramTool;
Expand Down Expand Up @@ -42,4 +44,26 @@ public function add(Request $request)
$message = "ALERTA: %0A" . $status;
FacebookTool::publish($message);
}

public function addAgif(Request $request)
{
$key = $request->header('key');

if(env('API_WRITE_KEY') !== $key){
abort(401);
}

$status = $request->get('status');

$warning = new WarningAgif();
$warning->text = $status;
$warning->save();

NotificationTool::sendWarningNotification($status);

TwitterTool::tweet($status);
TelegramTool::publish($status);
FacebookTool::publish($status);
BlueskyTool::publish($status);
}
}
20 changes: 20 additions & 0 deletions app/Models/WarningAgif.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Models;

use Jenssegers\Mongodb\Eloquent\Model;

class WarningAgif extends Model
{
protected $connection = 'mongodb';
protected $collection = 'warning_agif';
protected $primaryKey = '_id';

public const CREATED_AT = 'created';
public const UPDATED_AT = 'updated';

protected $fillable = [
'id',
'text',
];
}
9 changes: 8 additions & 1 deletion app/Tools/NotificationTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ private static function sendRequest($topic, $status, $location, $id)

private static function sendCustomTitleRequest($topic, $status, $title, $forceEnable = false)
{
Log::debug();
if (!env('NOTIFICATIONS_ENABLE')) {
return;
}
Expand Down Expand Up @@ -205,6 +204,7 @@ public static function sendWarning($status, $topic)
$response = $client->request('POST', 'https://fcm.googleapis.com/fcm/send', $headers);
}


public static function sendNewCosNotification(Incident $incident)
{
$status = 'Novo Comandante de Operações de socorro: '.$incident->cos;
Expand Down Expand Up @@ -300,4 +300,11 @@ public static function sendWarningNotification($status)

self::sendWarning($status, $topic);
}

public static function senAllNotification($status)
{
$topic = "all";

self::sendWarning($status, $topic);
}
}
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@

$router->group(['prefix' => 'warnings'], function () use ($router) {
$router->post('add', '\App\Http\Controllers\WarningsController@add');
$router->post('add/agif', '\App\Http\Controllers\WarningsController@addAgif');
});

$router->group(['prefix' => 'stats'], function () use ($router) {
Expand Down

0 comments on commit 0aba1de

Please sign in to comment.