notifications api update

This commit is contained in:
Čarodej
2022-05-04 09:20:48 +02:00
parent 67b9f7f4dc
commit f9b762de43
2 changed files with 21 additions and 13 deletions
@@ -1,22 +1,25 @@
<?php <?php
namespace Domain\Notifications\Controllers; namespace Domain\Notifications\Controllers;
use Illuminate\Http\Response; use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Routing\ResponseFactory;
class FlushUserNotificationsController extends Controller class FlushUserNotificationsController extends Controller
{ {
public function __invoke(): Response|Application|ResponseFactory public function __invoke(): JsonResponse
{ {
$successMessage = [
'type' => 'success',
'message' => 'All your notifications was deleted.',
];
if (isDemoAccount()) { if (isDemoAccount()) {
return response('Done', 204); return response()->json($successMessage);
} }
// Delete all notifications // Delete all notifications
auth()->user()->notifications()->delete(); auth()->user()->notifications()->delete();
return response('Done', 204); return response()->json($successMessage);
} }
} }
@@ -1,22 +1,27 @@
<?php <?php
namespace Domain\Notifications\Controllers; namespace Domain\Notifications\Controllers;
use Illuminate\Http\Response; use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Routing\ResponseFactory;
class MarkUserNotificationsAsReadController extends Controller class MarkUserNotificationsAsReadController extends Controller
{ {
public function __invoke(): Response|Application|ResponseFactory public function __invoke(): JsonResponse
{ {
$successMessage = [
'type' => 'success',
'message' => 'All your notifications was marked as read.',
];
if (isDemoAccount()) { if (isDemoAccount()) {
return response('Done', 204); return response()->json($successMessage);
} }
// Mark all notifications as read // Mark all notifications as read
auth()->user()->unreadNotifications()->update(['read_at' => now()]); auth()->user()->unreadNotifications()->update([
'read_at' => now()
]);
return response('Done', 204); return response()->json($successMessage);
} }
} }