Commit 57862f7a authored by Александр Плохих's avatar Александр Плохих 🌔
Browse files

STA-960 | controller&handle for restaurant listing

parent 7121b9d1
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
<?php

namespace App\Controller;

use App\Dto\ErrorDto;
use App\Request\AbstractRequest;
use App\Service\ServiceInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Throwable;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController as BundleController;

class AbstractController extends BundleController
{
    public function __construct(
        private readonly ServiceInterface $service
    ) {}

    protected function build(AbstractRequest $request): JsonResponse
    {
//        try {
            return new JsonResponse($this->service->serve($request));
//        } catch (Throwable $exception) {
//            $error = new ErrorDto();
//            return new JsonResponse($error, $error->status);
//        }
    }
}
+13 −8
Original line number Diff line number Diff line
@@ -2,19 +2,24 @@

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use App\Request\RestaurantListingRequest;
use App\Service\RestaurantListingService;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
use Symfony\Component\Routing\Attribute\Route;

#[Route('/api/v1/restaurants/')]
class RestaurantsController extends AbstractController
{
    /***
     * Листинг ресторанов
     * @return Response
     */
    #[Route('/restaurants/', name: 'restaurants')]
    public function restaurants(): Response
    public function __construct(RestaurantListingService $service)
    {
        parent::__construct($service);
    }

    /** Листинг ресторанов */
    #[Route(name: 'restaurants')]
    public function index(RestaurantListingRequest $request): JsonResponse
    {
        return $this->build($request);
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -4,9 +4,9 @@ namespace App\Dto;

class ErrorDto implements DtoInterface
{
    public string $status;
    public string $status = '500';

    public string $message;
    public string $message = 'Something went wrong';

    public string $code;
    public string $code = '100';
}
+12 −1
Original line number Diff line number Diff line
@@ -6,5 +6,16 @@ class PaginationDto implements DtoInterface
{
    public int $current_page = 1;
    public int $pages;
    public int $page_size;
    public int $page_size = 12;

    public function __construct(int $page, int $limit, int $total)
    {
        $this->pages = ceil($total/$limit);

        if (($page > 1) && ($page <= $this->pages)) {
            $this->current_page = $page;
        }

        $this->page_size = $limit;
    }
}
+10 −4
Original line number Diff line number Diff line
@@ -6,9 +6,15 @@ use Ramsey\Collection\Collection;

class RestaurantFilterVariantsDto implements DtoInterface
{
    /**
     * @param DtoCollection<RestaurantTypeDto> $type
     * @param DtoCollection<KitchenTypeDto> $kitchen
     */
    public function __construct(
        /** @var DtoCollection<RestaurantTypeDto>  */
    public DtoCollection $type;
        public DtoCollection $type,

        /** @var DtoCollection<KitchenTypeDto>  */
    public DtoCollection $kitchen;
        public DtoCollection $kitchen,
    ) {}
}
Loading