#29: add more tests
This commit is contained in:
parent
c4cd275c83
commit
9afa7fe431
8 changed files with 331 additions and 184 deletions
|
@ -15,28 +15,45 @@ use Symfony\Component\Routing\Attribute\Route;
|
|||
final class FoodOrderController extends AbstractController
|
||||
{
|
||||
#[Route(
|
||||
path: '/list/{page}',
|
||||
path: '/list',
|
||||
name: 'app_food_order_index',
|
||||
methods: ['GET']
|
||||
)]
|
||||
public function index(FoodOrderRepository $foodOrderRepository): Response
|
||||
{
|
||||
|
||||
return $this->render('food_order/index.html.twig', [
|
||||
'food_orders' => $foodOrderRepository->findLatestEntries(days: 3),
|
||||
'current_page' => 0,
|
||||
'next_page' => 0,
|
||||
'prev_page' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route(
|
||||
path: '/list/archive/{page}',
|
||||
name: 'app_food_order_archive',
|
||||
requirements: [
|
||||
'page' => '\d+',
|
||||
],
|
||||
methods: ['GET']
|
||||
)]
|
||||
public function index(FoodOrderRepository $foodOrderRepository, int $page = 1): Response
|
||||
public function archive(FoodOrderRepository $foodOrderRepository, int $page = 1): Response
|
||||
{
|
||||
$days = 4;
|
||||
if ($page > 1) {
|
||||
$days = 0;
|
||||
}
|
||||
$nextPage = $page + 1;
|
||||
$prevPage = $page - 1;
|
||||
$itemsPerPage = 10;
|
||||
if($foodOrderRepository->count() < $page * $itemsPerPage) {
|
||||
$count = $foodOrderRepository->count();
|
||||
if($count < $page * $itemsPerPage) {
|
||||
$nextPage = $page;
|
||||
}
|
||||
|
||||
return $this->render('food_order/index.html.twig', [
|
||||
'food_orders' => $foodOrderRepository->findLatestEntries(page: $page, pagesize: $itemsPerPage, days: $days),
|
||||
'food_orders' => $foodOrderRepository->findLatestEntries(
|
||||
page: $page,
|
||||
pagesize: $itemsPerPage,
|
||||
days: 0
|
||||
),
|
||||
'current_page' => $page,
|
||||
'next_page' => $nextPage,
|
||||
'prev_page' => $prevPage,
|
||||
|
|
|
@ -8,19 +8,12 @@ use DateTimeImmutable;
|
|||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
|
||||
use Symfony\Bridge\Doctrine\Types\UlidType;
|
||||
use Symfony\Component\Uid\Ulid;
|
||||
|
||||
#[ORM\Entity(repositoryClass: FoodOrderRepository::class)]
|
||||
class FoodOrder
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
||||
#[ORM\Column(type: UlidType::NAME, unique: true)]
|
||||
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
|
||||
private Ulid|null $id = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private DateTimeImmutable|null $closedAt = null;
|
||||
|
||||
|
@ -39,8 +32,11 @@ class FoodOrder
|
|||
])]
|
||||
private string|null $createdBy = 'nobody';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
public function __construct(
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(type: UlidType::NAME, unique: true)]
|
||||
private Ulid|null $id = new Ulid
|
||||
) {
|
||||
$this->orderItems = new ArrayCollection;
|
||||
$this->open();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue