Add new items listing and counting
This commit is contained in:
22
src/Controller/NewController.php
Normal file
22
src/Controller/NewController.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Krzysiej\RyobiCrawler\Controller;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Krzysiej\RyobiCrawler\Models\Product;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
final class NewController extends BaseController
|
||||
{
|
||||
#[Route('/promos', name: 'app_new')]
|
||||
public function __invoke(): Response
|
||||
{
|
||||
$products = Product::whereHas('created_at', now()->subDays(30)->format('Y-m-d'))
|
||||
->orderByDesc('starred')
|
||||
->orderByDesc('created_by')
|
||||
->with(['currentPrice'])
|
||||
->get();
|
||||
return $this->render('productList.html.twig', ['products' => $products]);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,11 @@ class AppExtension extends AbstractExtension
|
||||
return Product::whereHas('currentPrice', fn(Builder $query) => $query->whereColumn('price', '<', 'productStandardPrice'))->with(['currentPrice'])->count();
|
||||
}
|
||||
|
||||
public function newCount(): int
|
||||
{
|
||||
return Product::whereHas('created_at', now()->subDays(30)->format('Y-m-d'))->count();
|
||||
}
|
||||
|
||||
public function findByCreatedAtDate(Collection $items, string $date): Stock|Price|null
|
||||
{
|
||||
return $items->first(fn($item) => str_starts_with($item->created_at, $date));
|
||||
|
||||
Reference in New Issue
Block a user