wip-feat: lists active & recent downloads on landing page
This commit is contained in:
@@ -2,17 +2,23 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Download\Framework\Repository\DownloadRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
final class IndexController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly DownloadRepository $downloadRepository,
|
||||
) {}
|
||||
|
||||
#[Route('/', name: 'app_index')]
|
||||
public function index(): Response
|
||||
{
|
||||
return $this->render('index/index.html.twig', [
|
||||
'controller_name' => 'IndexController',
|
||||
'active_downloads' => [],
|
||||
'recent_downloads' => $this->downloadRepository->latest(5)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,4 +115,15 @@ class DownloadRepository extends ServiceEntityRepository
|
||||
|
||||
return $query->getResult();
|
||||
}
|
||||
|
||||
public function latest(int $limit = 1)
|
||||
{
|
||||
return $this->createQueryBuilder('d')
|
||||
->andWhere('d.status IN (:statuses)')
|
||||
->setParameter('statuses', ['Complete'])
|
||||
->setMaxResults($limit)
|
||||
->orderBy('d.id', 'DESC')
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user