c437a3f504
Build Docker Image / build-frontend (push) Successful in 53s
Co-authored-by: ISMAIL MASSERAN <topaz@Mac.dlinkrouter.local> Co-authored-by: ISMAIL MASSERAN <topaz@ISMAILs-Macbook.local> Reviewed-on: #24
33 lines
979 B
PHP
33 lines
979 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Services\NotificationService;
|
|
use Illuminate\Http\Request;
|
|
|
|
class InternalNotificationController extends Controller
|
|
{
|
|
public function store(Request $request, NotificationService $notifications)
|
|
{
|
|
$expected = (string) config('notifications.internal_secret');
|
|
$provided = (string) $request->header('X-Internal-Token', '');
|
|
|
|
if ($expected === '' || !hash_equals($expected, $provided)) {
|
|
return response()->json(['message' => 'Unauthorized'], 401);
|
|
}
|
|
|
|
$audience = $request->input('audience', []);
|
|
$role = is_array($audience) && !empty($audience['role']) ? $audience['role'] : null;
|
|
|
|
if (!$role) {
|
|
return response()->json(['message' => 'audience.role diperlukan'], 422);
|
|
}
|
|
|
|
$created = $notifications->dispatch($request->all());
|
|
|
|
return response()->json([
|
|
'created' => $created->count(),
|
|
], 201);
|
|
}
|
|
}
|