From 9ddfb7622a273cd259a9827938e7953f85086b07 Mon Sep 17 00:00:00 2001 From: Leon Date: Mon, 5 Jan 2026 11:18:03 +0100 Subject: [PATCH] feat: unparticipate hunt --- app/Http/Controllers/HuntsController.php | 14 ++++++++++++++ routes/api.php | 1 + 2 files changed, 15 insertions(+) diff --git a/app/Http/Controllers/HuntsController.php b/app/Http/Controllers/HuntsController.php index e1b5ec9..8bcd69b 100644 --- a/app/Http/Controllers/HuntsController.php +++ b/app/Http/Controllers/HuntsController.php @@ -108,6 +108,20 @@ class HuntsController extends Controller return response()->json(['message' => 'Participation started'], 201); } + public function unparticipate(Request $request, $id) + { + $hunt = Hunts::findOrFail($id); + $user = $request->user(); + + if (!$user->participations()->where('hunt_id', $hunt->id)->exists()) { + return response()->json(['message' => 'Not participating'], 404); + } + + $hunt->participants()->detach($user->id); + + return response()->json(['message' => 'Participation stopped'], 200); + } + /** * Update the specified resource in storage. */ diff --git a/routes/api.php b/routes/api.php index 30b85ad..dba789c 100644 --- a/routes/api.php +++ b/routes/api.php @@ -38,6 +38,7 @@ Route::middleware('auth:sanctum')->group(function (): void { Route::get('users/{user}', [UsersController::class, 'show']); Route::post('users/{user}/avatar', [UsersController::class, 'updateAvatar']); Route::post('hunts/{hunt}/participate', [HuntsController::class, 'participate']); + Route::delete('hunts/{hunt}/participate', [HuntsController::class, 'unparticipate']); Route::get('auth/me', [AuthController::class, 'me']); Route::post('auth/logout', [AuthController::class, 'logout']); }); \ No newline at end of file