change notifications functions
This commit is contained in:
@@ -10,24 +10,10 @@ use Illuminate\Support\Facades\Log;
|
|||||||
|
|
||||||
class NotificationsController extends Controller
|
class NotificationsController extends Controller
|
||||||
{
|
{
|
||||||
public function createNotification(Request $request, int $id): JsonResponse {
|
public function getNotifications(Request $request): 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 {
|
|
||||||
try {
|
try {
|
||||||
$user = User::findOrFail($id);
|
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'data' => $user->notifications
|
'data' => $request->user()->notifications
|
||||||
]);
|
]);
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
Log::info($e->getMessage());
|
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 {
|
try {
|
||||||
$user = User::findOrFail($userId);
|
$request->user()->notifications()->detach($notificationId);
|
||||||
$user->notifications()->detach($notificationId);
|
|
||||||
|
|
||||||
$notification = Notification::find($notificationId);
|
$notification = Notification::find($notificationId);
|
||||||
if ($notification && $notification->users()->count() === 0) {
|
if ($notification && $notification->users()->count() === 0) {
|
||||||
@@ -53,5 +38,4 @@ class NotificationsController extends Controller
|
|||||||
return response()->json(['message' => 'Erreur lors de la suppression'], 500);
|
return response()->json(['message' => 'Erreur lors de la suppression'], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,7 @@
|
|||||||
use App\Http\Controllers\NotificationsController;
|
use App\Http\Controllers\NotificationsController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
Route::middleware(['web', 'auth:sanctum'])->get('/users/{id}/notifications', [NotificationsController::class, "getNotifications"])
|
Route::middleware(['web', 'auth:sanctum'])->get('/users/notifications', [NotificationsController::class, "getNotifications"]);
|
||||||
->whereNumber('id');
|
|
||||||
|
|
||||||
Route::middleware(['web', 'auth:sanctum'])->post("/users/{id}/create/notification", [NotificationsController::class, "createNotification"])
|
Route::middleware(['web', 'auth:sanctum'])->delete('/users/delete/notification/{notificationId}', [NotificationsController::class, 'deleteNotification'])
|
||||||
->whereNumber('id');
|
|
||||||
|
|
||||||
Route::middleware(['web', 'auth:sanctum'])->delete('/users/{userId}/delete/notification/{notificationId}', [NotificationsController::class, 'deleteNotification'])
|
|
||||||
->whereNumber('userId')
|
|
||||||
->whereNumber('notificationId');
|
->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 {
|
delete {
|
||||||
url: {{url}}/api/users/{{userId}}/delete/notification/{{notificationId}}
|
url: {{url}}/api/users/delete/notification/{{notificationId}}
|
||||||
body: none
|
body: none
|
||||||
auth: inherit
|
auth: inherit
|
||||||
}
|
}
|
||||||
|
|
||||||
vars:pre-request {
|
vars:pre-request {
|
||||||
userId:
|
notificationId: 3
|
||||||
notificationId:
|
|
||||||
}
|
}
|
||||||
|
|
||||||
settings {
|
settings {
|
||||||
|
|||||||
@@ -1,19 +1,15 @@
|
|||||||
meta {
|
meta {
|
||||||
name: Get user notifications
|
name: Get user notifications
|
||||||
type: http
|
type: http
|
||||||
seq: 12
|
seq: 2
|
||||||
}
|
}
|
||||||
|
|
||||||
get {
|
get {
|
||||||
url: {{url}}/api/users/{{id}}/notifications
|
url: {{url}}/api/users/notifications
|
||||||
body: none
|
body: none
|
||||||
auth: inherit
|
auth: inherit
|
||||||
}
|
}
|
||||||
|
|
||||||
vars:pre-request {
|
|
||||||
id: 12
|
|
||||||
}
|
|
||||||
|
|
||||||
settings {
|
settings {
|
||||||
encodeUrl: true
|
encodeUrl: true
|
||||||
timeout: 0
|
timeout: 0
|
||||||
|
|||||||
Reference in New Issue
Block a user