71 lines
2.7 KiB
PHP
71 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Concerns\ProxiesBackend;
|
|
use App\Services\BackendHttpClient;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
class BonusesController extends Controller
|
|
{
|
|
use ProxiesBackend;
|
|
|
|
public function __construct(private readonly BackendHttpClient $client)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Lightweight JSON for the in-app Bonuses page.
|
|
* Authenticated web users only (route middleware handles auth+throttle).
|
|
*/
|
|
public function appIndex(Request $request)
|
|
{
|
|
try {
|
|
$res = $this->client->get($request, '/bonuses/app', [
|
|
'limit' => min(100, (int) $request->query('limit', 50)),
|
|
], retry: true);
|
|
|
|
if ($res->successful()) {
|
|
$body = $res->json() ?: [];
|
|
$available = $body['available'] ?? $body['bonuses'] ?? [];
|
|
$active = $body['active'] ?? [];
|
|
$history = $body['history'] ?? [];
|
|
|
|
// Normalize available list to fields expected by UI (keep unknowns as-is)
|
|
$availableDto = [];
|
|
foreach ((array) $available as $b) {
|
|
if (!is_array($b)) continue;
|
|
$availableDto[] = [
|
|
'id' => $b['id'] ?? null,
|
|
'title' => $b['title'] ?? null,
|
|
'type' => $b['type'] ?? null,
|
|
'amount_value' => isset($b['amount_value']) ? (float) $b['amount_value'] : (isset($b['amount']) ? (float) $b['amount'] : null),
|
|
'amount_unit' => $b['amount_unit'] ?? $b['unit'] ?? null,
|
|
'min_deposit' => isset($b['min_deposit']) ? (float) $b['min_deposit'] : null,
|
|
'max_amount' => isset($b['max_amount']) ? (float) $b['max_amount'] : null,
|
|
'currency' => $b['currency'] ?? null,
|
|
'code' => $b['code'] ?? null,
|
|
'starts_at' => $b['starts_at'] ?? null,
|
|
'expires_at' => $b['expires_at'] ?? null,
|
|
'description' => $b['description'] ?? null,
|
|
];
|
|
}
|
|
|
|
return response()->json([
|
|
'available' => $availableDto,
|
|
'active' => $active,
|
|
'history' => $history,
|
|
'now' => $body['now'] ?? now()->toIso8601String(),
|
|
], 200);
|
|
}
|
|
|
|
if ($res->clientError()) return $this->mapClientError($res);
|
|
if ($res->serverError()) return $this->mapServiceUnavailable($res);
|
|
return $this->mapBadGateway();
|
|
} catch (\Throwable $e) {
|
|
return $this->mapBadGateway('API server not reachable');
|
|
}
|
|
}
|
|
}
|