36 lines
1.1 KiB
PHP
36 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Services\Recommendations\PersonalizedFeedService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
final class FeedController extends Controller
|
|
{
|
|
public function __construct(private readonly PersonalizedFeedService $feedService)
|
|
{
|
|
}
|
|
|
|
public function index(Request $request): JsonResponse
|
|
{
|
|
$payload = $request->validate([
|
|
'limit' => ['nullable', 'integer', 'min:1', 'max:50'],
|
|
'cursor' => ['nullable', 'string', 'max:512'],
|
|
'algo_version' => ['nullable', 'string', 'max:64'],
|
|
]);
|
|
|
|
$result = $this->feedService->getFeed(
|
|
userId: (int) $request->user()->id,
|
|
limit: isset($payload['limit']) ? (int) $payload['limit'] : 24,
|
|
cursor: isset($payload['cursor']) ? (string) $payload['cursor'] : null,
|
|
algoVersion: isset($payload['algo_version']) ? (string) $payload['algo_version'] : null
|
|
);
|
|
|
|
return response()->json($result);
|
|
}
|
|
}
|