Initialer Laravel Commit für BetiX
This commit is contained in:
54
app/Http/Controllers/UserBonusController.php
Normal file
54
app/Http/Controllers/UserBonusController.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Concerns\ProxiesBackend;
|
||||
use App\Services\BackendHttpClient;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UserBonusController extends Controller
|
||||
{
|
||||
use ProxiesBackend;
|
||||
|
||||
public function __construct(private readonly BackendHttpClient $client)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Return authenticated user's bonuses (active first), lightweight JSON.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$res = $this->client->get($request, '/users/me/bonuses', [], retry: true);
|
||||
if ($res->successful()) {
|
||||
$body = $res->json() ?: [];
|
||||
$items = $body['data'] ?? $body['bonuses'] ?? $body;
|
||||
$out = [];
|
||||
foreach ((array) $items as $b) {
|
||||
if (!is_array($b)) continue;
|
||||
$out[] = [
|
||||
'id' => $b['id'] ?? null,
|
||||
'amount' => isset($b['amount']) ? (float) $b['amount'] : 0.0,
|
||||
'wager_required' => isset($b['wager_required']) ? (float) $b['wager_required'] : 0.0,
|
||||
'wager_progress' => isset($b['wager_progress']) ? (float) $b['wager_progress'] : 0.0,
|
||||
'expires_at' => $b['expires_at'] ?? null,
|
||||
'is_active' => (bool) ($b['is_active'] ?? false),
|
||||
'completed_at' => $b['completed_at'] ?? null,
|
||||
'promo' => isset($b['promo']) && is_array($b['promo']) ? [
|
||||
'code' => $b['promo']['code'] ?? null,
|
||||
'wager_multiplier' => isset($b['promo']['wager_multiplier']) ? (int) $b['promo']['wager_multiplier'] : null,
|
||||
] : null,
|
||||
];
|
||||
}
|
||||
return response()->json(['data' => $out], 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');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user