feat: ✨ Add api routes for suspending and unsuspending an User
This commit adresses #359
This commit is contained in:
parent
74bdcffe75
commit
b831bd0c22
|
@ -181,6 +181,53 @@ class UserController extends Controller
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Suspends the user
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param int $id
|
||||||
|
* @return bool
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
public function suspend(Request $request, int $id)
|
||||||
|
{
|
||||||
|
$discordUser = DiscordUser::find($id);
|
||||||
|
$user = $discordUser ? $discordUser->user : User::findOrFail($id);
|
||||||
|
|
||||||
|
if ($user->isSuspended()) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'error' => 'The user is already suspended',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
$user->suspend();
|
||||||
|
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Suspends the user
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param int $id
|
||||||
|
* @return bool
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
public function unsuspend(Request $request, int $id)
|
||||||
|
{
|
||||||
|
$discordUser = DiscordUser::find($id);
|
||||||
|
$user = $discordUser ? $discordUser->user : User::findOrFail($id);
|
||||||
|
|
||||||
|
if (!$user->isSuspended()) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'error' => "You cannot unsuspend an User who is not suspended."
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$user->unSuspend();
|
||||||
|
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -20,6 +20,8 @@ use Illuminate\Support\Facades\Route;
|
||||||
Route::middleware('api.token')->group(function () {
|
Route::middleware('api.token')->group(function () {
|
||||||
Route::patch('/users/{user}/increment', [UserController::class, 'increment']);
|
Route::patch('/users/{user}/increment', [UserController::class, 'increment']);
|
||||||
Route::patch('/users/{user}/decrement', [UserController::class, 'decrement']);
|
Route::patch('/users/{user}/decrement', [UserController::class, 'decrement']);
|
||||||
|
Route::patch('/users/{user}/suspend', [UserController::class, 'suspend']);
|
||||||
|
Route::patch('/users/{user}/unsuspend', [UserController::class, 'unsuspend']);
|
||||||
Route::resource('users', UserController::class)->except(['create']);
|
Route::resource('users', UserController::class)->except(['create']);
|
||||||
|
|
||||||
Route::patch('/servers/{server}/suspend', [ServerController::class, 'suspend']);
|
Route::patch('/servers/{server}/suspend', [ServerController::class, 'suspend']);
|
||||||
|
|
Loading…
Reference in a new issue