add readNotifications route and bruno's request
This commit is contained in:
@@ -38,4 +38,18 @@ class NotificationsController extends Controller
|
|||||||
return response()->json(['message' => 'Erreur lors de la suppression'], 500);
|
return response()->json(['message' => 'Erreur lors de la suppression'], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function readNotifications(Request $request): JsonResponse {
|
||||||
|
try {
|
||||||
|
$user = $request->user();
|
||||||
|
$notificationIds = $user->notifications()->pluck('notification_id');
|
||||||
|
|
||||||
|
$user->notifications()->updateExistingPivot($notificationIds, ['unread' => 0]);
|
||||||
|
|
||||||
|
return response()->json(['message' => "Notifications marquées comme lues"], 200);
|
||||||
|
} catch(\Exception $e) {
|
||||||
|
Log::info($e->getMessage());
|
||||||
|
return response()->json(['message' => "Server error"], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,3 +7,6 @@ Route::middleware(['web', 'auth:sanctum'])->get('/users/notifications', [Notific
|
|||||||
|
|
||||||
Route::middleware(['web', 'auth:sanctum'])->delete('/users/delete/notification/{notificationId}', [NotificationsController::class, 'deleteNotification'])
|
Route::middleware(['web', 'auth:sanctum'])->delete('/users/delete/notification/{notificationId}', [NotificationsController::class, 'deleteNotification'])
|
||||||
->whereNumber('notificationId');
|
->whereNumber('notificationId');
|
||||||
|
|
||||||
|
Route::middleware(['web', 'auth:sanctum'])->post('/users/notifications/read', [NotificationsController::class, "readNotifications"]);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
meta {
|
||||||
|
name: Read notifications
|
||||||
|
type: http
|
||||||
|
seq: 3
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
url: {{url}}/api/users/notifications/read
|
||||||
|
body: none
|
||||||
|
auth: inherit
|
||||||
|
}
|
||||||
|
|
||||||
|
settings {
|
||||||
|
encodeUrl: true
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
headers {
|
headers {
|
||||||
Accept: application/json
|
Accept: application/json
|
||||||
X-XSRF-TOKEN: eyJpdiI6IjZ3OWo1dG43ZFZrWkI0akozSkZOUnc9PSIsInZhbHVlIjoieE1kNTBPSGlReXlhOHY0MlF6MDUxa2VDc3c3ajdhVUFEUGdOZDNOcUJoZGdwaFBWQUZ2a2g3a1FOdnRwTnVNcW44V095bGlIaEkwZEZiUnIzWElVV29nNmZPZVNpSzlXU2FJMS9TOERqRWtOVStxVTEvVWZLQVFpQ2VzTlA1bkEiLCJtYWMiOiJiZjNkODFkMjk2YTZiNDU4ODlkMTAxNzU0ZTdlOTdmODU3YjEyNzI1ODk1ZjM0ZDVhN2U2YThhZmMwYWY4NjZhIiwidGFnIjoiIn0=
|
X-XSRF-TOKEN: eyJpdiI6ImFwSWk4NFdMcWJkcGF2YjRZQlQrRlE9PSIsInZhbHVlIjoiUXlyeFBkZFhDWmF1WE85OW1uY3c4ak1MM2dWMWlKRy9DRkN0MVNPNGVUUmthT1MxZ2hKREZhT0Y4d25idk5RdnZEcFh2UTRlbWpzYXRwSkNWL2Y5V2xlaEtYN09KMHpMQnQ4RzJvaElmWnFzTXEvSTJzZmZBenJEa2ZPelpydHoiLCJtYWMiOiIxNmIwNGRhNWQwYzIwZjBiYjA1ZTZlYzA2Y2NiY2FiNDY0NTZmNzU4NGIyZDYxODVhZGEwZWJiZmMwOGEwNzlmIiwidGFnIjoiIn0=
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user