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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,12 +3,7 @@
|
||||
use App\Http\Controllers\NotificationsController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::middleware(['web', 'auth:sanctum'])->get('/users/{id}/notifications', [NotificationsController::class, "getNotifications"])
|
||||
->whereNumber('id');
|
||||
Route::middleware(['web', 'auth:sanctum'])->get('/users/notifications', [NotificationsController::class, "getNotifications"]);
|
||||
|
||||
Route::middleware(['web', 'auth:sanctum'])->post("/users/{id}/create/notification", [NotificationsController::class, "createNotification"])
|
||||
->whereNumber('id');
|
||||
|
||||
Route::middleware(['web', 'auth:sanctum'])->delete('/users/{userId}/delete/notification/{notificationId}', [NotificationsController::class, 'deleteNotification'])
|
||||
->whereNumber('userId')
|
||||
Route::middleware(['web', 'auth:sanctum'])->delete('/users/delete/notification/{notificationId}', [NotificationsController::class, 'deleteNotification'])
|
||||
->whereNumber('notificationId');
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
meta {
|
||||
name: Create notification
|
||||
type: http
|
||||
seq: 12
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{url}}/api/users/{{id}}/create/notification
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"content": "{{content}}"
|
||||
}
|
||||
}
|
||||
|
||||
vars:pre-request {
|
||||
id: 12
|
||||
content: test
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
}
|
||||
@@ -5,14 +5,13 @@ meta {
|
||||
}
|
||||
|
||||
delete {
|
||||
url: {{url}}/api/users/{{userId}}/delete/notification/{{notificationId}}
|
||||
url: {{url}}/api/users/delete/notification/{{notificationId}}
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
vars:pre-request {
|
||||
userId:
|
||||
notificationId:
|
||||
notificationId: 3
|
||||
}
|
||||
|
||||
settings {
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
meta {
|
||||
name: Get user notifications
|
||||
type: http
|
||||
seq: 12
|
||||
seq: 2
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{url}}/api/users/{{id}}/notifications
|
||||
url: {{url}}/api/users/notifications
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
vars:pre-request {
|
||||
id: 12
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
|
||||
Reference in New Issue
Block a user