change notifications functions
This commit is contained in:
@@ -10,24 +10,10 @@ use Illuminate\Support\Facades\Log;
|
||||
|
||||
class NotificationsController extends Controller
|
||||
{
|
||||
public function createNotification(Request $request, int $id): JsonResponse {
|
||||
$notification = Notification::create([
|
||||
"content" => $request["content"]
|
||||
]);
|
||||
|
||||
$notification->users()->attach($id);
|
||||
|
||||
return response()->json(['message' => 'Notification created successfully']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getNotifications(Request $request, int $id): JsonResponse {
|
||||
public function getNotifications(Request $request): JsonResponse {
|
||||
try {
|
||||
$user = User::findOrFail($id);
|
||||
|
||||
return response()->json([
|
||||
'data' => $user->notifications
|
||||
'data' => $request->user()->notifications
|
||||
]);
|
||||
} catch(\Exception $e) {
|
||||
Log::info($e->getMessage());
|
||||
@@ -37,10 +23,9 @@ class NotificationsController extends Controller
|
||||
|
||||
|
||||
|
||||
public function deleteNotification(int $userId, int $notificationId): JsonResponse {
|
||||
public function deleteNotification(Request $request, int $notificationId): JsonResponse {
|
||||
try {
|
||||
$user = User::findOrFail($userId);
|
||||
$user->notifications()->detach($notificationId);
|
||||
$request->user()->notifications()->detach($notificationId);
|
||||
|
||||
$notification = Notification::find($notificationId);
|
||||
if ($notification && $notification->users()->count() === 0) {
|
||||
@@ -53,5 +38,4 @@ class NotificationsController extends Controller
|
||||
return response()->json(['message' => 'Erreur lors de la suppression'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user