Loading src/Application/Controller/Request/Manager/GetRequestByIdController.php 0 → 100644 +34 −0 Original line number Diff line number Diff line <?php namespace App\Application\Controller\Request\Manager; use App\Application\Services\Request\GetRequestsService; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; #[AsController] final class GetRequestByIdController { public function __construct( private readonly GetRequestsService $requestService, private readonly NormalizerInterface $normalizer ) { } #[Route('/api/requests/{requestId}', name: 'get_request_detail', methods: ['GET'])] #[IsGranted('ROLE_MANAGER')] public function __invoke(string $requestId): Response { $response = $this->requestService->get($requestId); if (!$response) { return new Response(status: Response::HTTP_NOT_FOUND); } return new JsonResponse($this->normalizer->normalize($response)); } } No newline at end of file src/Application/Controller/Request/Manager/GetRequestsController.php 0 → 100644 +36 −0 Original line number Diff line number Diff line <?php namespace App\Application\Controller\Request\Manager; use App\Application\Services\Request\GetRequestsService; use App\Domain\Request\DTO\Request\Query\GetRequestsDTO; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; use Symfony\Component\HttpKernel\Attribute\MapQueryString; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; #[AsController] final class GetRequestsController { public function __construct( private readonly GetRequestsService $requestService, private readonly NormalizerInterface $normalizer ) { } #[Route('/api/requests', name: 'get_requests', methods: ['GET'])] #[IsGranted('ROLE_MANAGER')] public function __invoke(#[MapQueryString] ?GetRequestsDTO $query): Response { if (!$query) { $query = new GetRequestsDTO(); } $response = $this->requestService->getAll($query); return new JsonResponse($this->normalizer->normalize($response)); } } No newline at end of file src/Application/Controller/Request/Manager/ManageRequestController.php 0 → 100644 +38 −0 Original line number Diff line number Diff line <?php namespace App\Application\Controller\Request\Manager; use App\Application\Services\Request\UpdateRequestService; use App\Domain\Request\DTO\Request\Query\ChangeStatusRequestDTO; use App\Domain\Request\Exception\NotAvailableStatusException; use App\Domain\Request\Exception\RequestNotExistException; use Symfony\Component\HttpFoundation\Exception\BadRequestException; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; use Symfony\Component\HttpKernel\Attribute\MapRequestPayload; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; #[AsController] final class ManageRequestController { public function __construct( private readonly UpdateRequestService $requestService, ) { } #[Route('/api/requests/{requestId}', name: 'update_request_detail', methods: ['PATCH'])] #[IsGranted('ROLE_MANAGER')] public function __invoke(string $requestId, #[MapRequestPayload] ChangeStatusRequestDTO $requestDTO): Response { try { $this->requestService->updateRequestStatus($requestId, $requestDTO); } catch (RequestNotExistException) { return new Response(status: Response::HTTP_NOT_FOUND); } catch (NotAvailableStatusException) { throw new BadRequestException('Невалидный статус запроса'); } return new Response(Response::HTTP_NO_CONTENT); } } No newline at end of file src/Application/Services/Request/GetRequestsService.php 0 → 100644 +39 −0 Original line number Diff line number Diff line <?php namespace App\Application\Services\Request; use App\Domain\Request\DTO\PaginationDataDTO; use App\Domain\Request\DTO\Request\Query\GetRequestsDTO; use App\Domain\Request\DTO\Request\Response\RequestDTO; use App\Domain\Request\Interfaces\RequestReaderInterface; use Doctrine\DBAL\Exception; final class GetRequestsService { public function __construct( private readonly RequestReaderInterface $reader, ) { } /** * Список запросов * * @param GetRequestsDTO $query * @return PaginationDataDTO */ public function getAll(GetRequestsDTO $query): PaginationDataDTO { return $this->reader->getRequests($query); } /** * Запрос по его идентификатору * * @param string $requestId * @return RequestDTO|null */ public function get(string $requestId): ?RequestDTO { return $this->reader->getRequestById($requestId); } } No newline at end of file src/Application/Services/Request/UpdateRequestService.php 0 → 100644 +45 −0 Original line number Diff line number Diff line <?php namespace App\Application\Services\Request; use App\Domain\Request\DTO\Request\Query\ChangeStatusRequestDTO; use App\Domain\Request\Exception\NotAvailableStatusException; use App\Domain\Request\Exception\RequestNotExistException; use App\Domain\Request\Interfaces\RequestRepositoryInterface; use App\Domain\Request\Status\Status; final class UpdateRequestService { public function __construct( private readonly RequestRepositoryInterface $repository, ) { } /** * Обновить статус запроса * * @param string $id * @param ChangeStatusRequestDTO $requestDTO * @return void * @throws RequestNotExistException * @throws NotAvailableStatusException */ public function updateRequestStatus(string $id, ChangeStatusRequestDTO $requestDTO): void { $request = $this->repository->getById($id); if ($request === null) { throw new RequestNotExistException(); } $status = Status::tryFrom($requestDTO->status); if ($status === null) { throw new NotAvailableStatusException(); } $request->setNewStatus($status, $requestDTO->comment); $this->repository->persist($request); } } No newline at end of file Loading
src/Application/Controller/Request/Manager/GetRequestByIdController.php 0 → 100644 +34 −0 Original line number Diff line number Diff line <?php namespace App\Application\Controller\Request\Manager; use App\Application\Services\Request\GetRequestsService; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; #[AsController] final class GetRequestByIdController { public function __construct( private readonly GetRequestsService $requestService, private readonly NormalizerInterface $normalizer ) { } #[Route('/api/requests/{requestId}', name: 'get_request_detail', methods: ['GET'])] #[IsGranted('ROLE_MANAGER')] public function __invoke(string $requestId): Response { $response = $this->requestService->get($requestId); if (!$response) { return new Response(status: Response::HTTP_NOT_FOUND); } return new JsonResponse($this->normalizer->normalize($response)); } } No newline at end of file
src/Application/Controller/Request/Manager/GetRequestsController.php 0 → 100644 +36 −0 Original line number Diff line number Diff line <?php namespace App\Application\Controller\Request\Manager; use App\Application\Services\Request\GetRequestsService; use App\Domain\Request\DTO\Request\Query\GetRequestsDTO; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; use Symfony\Component\HttpKernel\Attribute\MapQueryString; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; #[AsController] final class GetRequestsController { public function __construct( private readonly GetRequestsService $requestService, private readonly NormalizerInterface $normalizer ) { } #[Route('/api/requests', name: 'get_requests', methods: ['GET'])] #[IsGranted('ROLE_MANAGER')] public function __invoke(#[MapQueryString] ?GetRequestsDTO $query): Response { if (!$query) { $query = new GetRequestsDTO(); } $response = $this->requestService->getAll($query); return new JsonResponse($this->normalizer->normalize($response)); } } No newline at end of file
src/Application/Controller/Request/Manager/ManageRequestController.php 0 → 100644 +38 −0 Original line number Diff line number Diff line <?php namespace App\Application\Controller\Request\Manager; use App\Application\Services\Request\UpdateRequestService; use App\Domain\Request\DTO\Request\Query\ChangeStatusRequestDTO; use App\Domain\Request\Exception\NotAvailableStatusException; use App\Domain\Request\Exception\RequestNotExistException; use Symfony\Component\HttpFoundation\Exception\BadRequestException; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; use Symfony\Component\HttpKernel\Attribute\MapRequestPayload; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; #[AsController] final class ManageRequestController { public function __construct( private readonly UpdateRequestService $requestService, ) { } #[Route('/api/requests/{requestId}', name: 'update_request_detail', methods: ['PATCH'])] #[IsGranted('ROLE_MANAGER')] public function __invoke(string $requestId, #[MapRequestPayload] ChangeStatusRequestDTO $requestDTO): Response { try { $this->requestService->updateRequestStatus($requestId, $requestDTO); } catch (RequestNotExistException) { return new Response(status: Response::HTTP_NOT_FOUND); } catch (NotAvailableStatusException) { throw new BadRequestException('Невалидный статус запроса'); } return new Response(Response::HTTP_NO_CONTENT); } } No newline at end of file
src/Application/Services/Request/GetRequestsService.php 0 → 100644 +39 −0 Original line number Diff line number Diff line <?php namespace App\Application\Services\Request; use App\Domain\Request\DTO\PaginationDataDTO; use App\Domain\Request\DTO\Request\Query\GetRequestsDTO; use App\Domain\Request\DTO\Request\Response\RequestDTO; use App\Domain\Request\Interfaces\RequestReaderInterface; use Doctrine\DBAL\Exception; final class GetRequestsService { public function __construct( private readonly RequestReaderInterface $reader, ) { } /** * Список запросов * * @param GetRequestsDTO $query * @return PaginationDataDTO */ public function getAll(GetRequestsDTO $query): PaginationDataDTO { return $this->reader->getRequests($query); } /** * Запрос по его идентификатору * * @param string $requestId * @return RequestDTO|null */ public function get(string $requestId): ?RequestDTO { return $this->reader->getRequestById($requestId); } } No newline at end of file
src/Application/Services/Request/UpdateRequestService.php 0 → 100644 +45 −0 Original line number Diff line number Diff line <?php namespace App\Application\Services\Request; use App\Domain\Request\DTO\Request\Query\ChangeStatusRequestDTO; use App\Domain\Request\Exception\NotAvailableStatusException; use App\Domain\Request\Exception\RequestNotExistException; use App\Domain\Request\Interfaces\RequestRepositoryInterface; use App\Domain\Request\Status\Status; final class UpdateRequestService { public function __construct( private readonly RequestRepositoryInterface $repository, ) { } /** * Обновить статус запроса * * @param string $id * @param ChangeStatusRequestDTO $requestDTO * @return void * @throws RequestNotExistException * @throws NotAvailableStatusException */ public function updateRequestStatus(string $id, ChangeStatusRequestDTO $requestDTO): void { $request = $this->repository->getById($id); if ($request === null) { throw new RequestNotExistException(); } $status = Status::tryFrom($requestDTO->status); if ($status === null) { throw new NotAvailableStatusException(); } $request->setNewStatus($status, $requestDTO->comment); $this->repository->persist($request); } } No newline at end of file