Create unassignUser, unassignSelf methods and Bruno requests. Add call events when needed
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Events\EventParticipationCancelled;
|
||||
use App\Models\Events;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -83,12 +84,29 @@ class EventsController extends Controller
|
||||
}
|
||||
|
||||
try {
|
||||
$event = Events::with('tasks.users')->find($id);
|
||||
|
||||
if (!$event) {
|
||||
return response()->json(['message' => 'Event not found'], 404);
|
||||
}
|
||||
|
||||
$participants = $event->tasks->flatMap(function ($task) {
|
||||
return $task->users;
|
||||
})->unique('id');
|
||||
|
||||
foreach ($participants as $user) {
|
||||
broadcast(new EventParticipationCancelled(
|
||||
$user->id,
|
||||
$event
|
||||
));
|
||||
}
|
||||
|
||||
$event = Events::find($id);
|
||||
$event->delete();
|
||||
return response()->json(["message" => "Event deleted"]);
|
||||
|
||||
return response()->json(["message" => "Event deleted and participants notified"]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::info($e->getMessage());
|
||||
Log::error("Event delete error: " . $e->getMessage());
|
||||
return response()->json(['message' => "Server error"], 500);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user