Wire seller push notifications with FCM, inbox API, and payment milestones.
Deploy Ladill Mini / deploy (push) Successful in 52s
Deploy Ladill Mini / deploy (push) Successful in 52s
Sellers get instant payment alerts on Android; withdrawals respect payout prefs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Mini;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class NotificationController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$account = ladill_account();
|
||||
|
||||
$notifications = $account->notifications()
|
||||
->latest()
|
||||
->limit(100)
|
||||
->get()
|
||||
->map(fn ($n) => $this->present($n));
|
||||
|
||||
$unread = $account->unreadNotifications()->count();
|
||||
|
||||
return response()->json([
|
||||
'data' => $notifications,
|
||||
'unread_count' => $unread,
|
||||
]);
|
||||
}
|
||||
|
||||
public function unreadCount(Request $request): JsonResponse
|
||||
{
|
||||
$account = ladill_account();
|
||||
|
||||
return response()->json([
|
||||
'data' => [
|
||||
'unread_count' => $account->unreadNotifications()->count(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function markAsRead(Request $request, string $id): JsonResponse
|
||||
{
|
||||
$notification = ladill_account()
|
||||
->notifications()
|
||||
->where('id', $id)
|
||||
->first();
|
||||
|
||||
if ($notification) {
|
||||
$notification->markAsRead();
|
||||
}
|
||||
|
||||
return response()->json(['data' => ['success' => true]]);
|
||||
}
|
||||
|
||||
public function markAllAsRead(Request $request): JsonResponse
|
||||
{
|
||||
ladill_account()->unreadNotifications->markAsRead();
|
||||
|
||||
return response()->json(['data' => ['success' => true]]);
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
private function present(mixed $notification): array
|
||||
{
|
||||
return [
|
||||
'id' => $notification->id,
|
||||
'type' => class_basename($notification->type),
|
||||
'title' => $notification->data['title'] ?? 'Notification',
|
||||
'message' => $notification->data['message'] ?? '',
|
||||
'icon' => $notification->data['icon'] ?? 'bell',
|
||||
'milestone' => $notification->data['milestone'] ?? null,
|
||||
'url' => $notification->data['url'] ?? null,
|
||||
'read_at' => $notification->read_at?->toIso8601String(),
|
||||
'created_at' => $notification->created_at?->toIso8601String(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user