Initial V2 commit
This commit is contained in:
52
app/Http/Controllers/NotificationController.php
Normal file
52
app/Http/Controllers/NotificationController.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Notification Controller
|
||||
* Replaces: ride/notification/*.php
|
||||
*/
|
||||
class NotificationController extends Controller
|
||||
{
|
||||
/** GET /v2/notifications */
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$userId = $request->input('_jwt_user_id');
|
||||
$userType = $request->input('_jwt_user_type');
|
||||
$page = (int) $request->input('page', 1);
|
||||
$limit = min((int) $request->input('limit', 20), 50);
|
||||
|
||||
if ($userType === 'driver') {
|
||||
$notifications = DB::connection('primary')->table('notificationCaptain')
|
||||
->where('driverID', $userId)
|
||||
->orderBy('dateCreated', 'desc')
|
||||
->skip(($page - 1) * $limit)->take($limit)
|
||||
->get();
|
||||
} else {
|
||||
$notifications = DB::connection('primary')->table('notifications')
|
||||
->where('passenger_id', $userId)
|
||||
->orderBy('created_at', 'desc')
|
||||
->skip(($page - 1) * $limit)->take($limit)
|
||||
->get();
|
||||
}
|
||||
|
||||
return response()->json(['status' => 'success', 'data' => $notifications]);
|
||||
}
|
||||
|
||||
/** PUT /v2/notifications/{id}/read */
|
||||
public function markRead(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$userType = $request->input('_jwt_user_type');
|
||||
$table = $userType === 'driver' ? 'notificationCaptain' : 'notifications';
|
||||
|
||||
DB::connection('primary')->table($table)
|
||||
->where('id', $id)
|
||||
->update(['isShown' => 'true']);
|
||||
|
||||
return response()->json(['status' => 'success']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user