Clean up some code
This commit is contained in:
parent
bdc1981c36
commit
916fbad8af
|
@ -12,7 +12,7 @@ use Illuminate\Http\Request;
|
|||
class NotificationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Displays all notifications of an user.
|
||||
* Display all notifications of an user.
|
||||
* @param Request $request
|
||||
* @param int $userId
|
||||
* @return Response
|
||||
|
@ -26,7 +26,7 @@ class NotificationController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* Displays a specific notification
|
||||
* Display a specific notification
|
||||
*
|
||||
* @param int $userId
|
||||
* @param int $notificationId
|
||||
|
@ -45,19 +45,6 @@ class NotificationController extends Controller
|
|||
|
||||
return $notification;
|
||||
}
|
||||
/**
|
||||
* Shows all unread notifications of an user.
|
||||
* @param Request $request
|
||||
* @param int $userId
|
||||
* @return Response
|
||||
*/
|
||||
public function indexUnread(Request $request, int $userId)
|
||||
{
|
||||
$discordUser = DiscordUser::find($userId);
|
||||
$user = $discordUser ? $discordUser->user : User::findOrFail($userId);
|
||||
|
||||
return $user->unreadNotifications()->paginate($request->query("per_page", 50));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a notification to an user.
|
||||
|
@ -99,24 +86,9 @@ class NotificationController extends Controller
|
|||
return response()->json(["message" => "All notifications have been successfully deleted.", "count" => $count]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all read notifications from an user
|
||||
*
|
||||
* @param int $userId
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function deleteRead(int $userId)
|
||||
{
|
||||
$discordUser = DiscordUser::find($userId);
|
||||
$user = $discordUser ? $discordUser->user : User::findOrFail($userId);
|
||||
|
||||
$count = $user->notifications()->whereNotNull("read_at")->delete();
|
||||
|
||||
return response()->json(["message" => "All read notifications have been successfully deleted.", "count" => $count]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a specific notification
|
||||
* Delete a specific notification
|
||||
*
|
||||
* @param int $userId
|
||||
* @param int $notificationId
|
||||
|
|
|
@ -116,7 +116,8 @@ class VoucherController extends Controller
|
|||
* @param Voucher $voucher
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
public function users(Request $request, Voucher $voucher){
|
||||
public function users(Request $request, Voucher $voucher)
|
||||
{
|
||||
$request->validate([
|
||||
'include' => [
|
||||
'nullable',
|
||||
|
@ -125,7 +126,7 @@ class VoucherController extends Controller
|
|||
]
|
||||
]);
|
||||
|
||||
if($request->input('include') == 'discorduser'){
|
||||
if ($request->input('include') == 'discorduser') {
|
||||
return $voucher->users()->with('discordUser')->paginate($request->query('per_page') ?? 50);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,10 +28,8 @@ Route::middleware('api.token')->group(function () {
|
|||
Route::resource('vouchers', VoucherController::class)->except('create', 'edit');
|
||||
|
||||
Route::get('/notifications/{user}', [NotificationController::class, 'index']);
|
||||
Route::get('/notifications/{user}/unread', [NotificationController::class, 'indexUnread']);
|
||||
Route::get('/notifications/{user}/{notification}', [NotificationController::class, 'view']);
|
||||
Route::post('/notifications/{user}', [NotificationController::class, 'send']);
|
||||
Route::delete('/notifications/{user}', [NotificationController::class, 'delete']);
|
||||
Route::delete('/notifications/{user}/read', [NotificationController::class, 'deleteRead']);
|
||||
Route::delete('/notifications/{user}/{notification}', [NotificationController::class, 'deleteOne']);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue