From 17fe374e015b5d8ef349dece5c89f3b1ca33a13b Mon Sep 17 00:00:00 2001 From: Akex Date: Tue, 9 Apr 2024 01:56:24 +0500 Subject: [PATCH 1/2] make controller --- src/Controller/CountFriday13Controller.php | 28 ++++++++++++++++++++++ src/Repository/CountFriday13Repository.php | 23 ++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/Controller/CountFriday13Controller.php create mode 100644 src/Repository/CountFriday13Repository.php diff --git a/src/Controller/CountFriday13Controller.php b/src/Controller/CountFriday13Controller.php new file mode 100644 index 0000000..88e200c --- /dev/null +++ b/src/Controller/CountFriday13Controller.php @@ -0,0 +1,28 @@ +toArray()['year']; + + $returnableArray = countFriday13($year); + + return new JsonResponse($returnableArray, Response::HTTP_OK); + } +} diff --git a/src/Repository/CountFriday13Repository.php b/src/Repository/CountFriday13Repository.php new file mode 100644 index 0000000..8d3e0d7 --- /dev/null +++ b/src/Repository/CountFriday13Repository.php @@ -0,0 +1,23 @@ +setDate($year, $i, 13); + + if ($next13->format("D") === 'Fri'){ + $AllFri13[] = $next13; + } + } + return $AllFri13; +} -- GitLab From 2e9d064e336391d342f3c5da40f713c1da181120 Mon Sep 17 00:00:00 2001 From: "Alex. Plokhikh" Date: Tue, 16 Apr 2024 02:45:09 +0500 Subject: [PATCH 2/2] add controller | action | request --- src/Actions/CountFriday13Action.php | 27 ++++++++++++++++++++++ src/Controller/CountFriday13Controller.php | 15 +++++------- src/Repository/CountFriday13Repository.php | 23 ------------------ src/Requests/AllFri13Request.php | 21 +++++++++++++++++ 4 files changed, 54 insertions(+), 32 deletions(-) create mode 100644 src/Actions/CountFriday13Action.php delete mode 100644 src/Repository/CountFriday13Repository.php create mode 100644 src/Requests/AllFri13Request.php diff --git a/src/Actions/CountFriday13Action.php b/src/Actions/CountFriday13Action.php new file mode 100644 index 0000000..c7986cd --- /dev/null +++ b/src/Actions/CountFriday13Action.php @@ -0,0 +1,27 @@ +setDate($year, $i, 13); + + if ($next13->format("D") === "Fri") { + $AllFri13[] = $next13; + } + } + return $AllFri13; + } +} diff --git a/src/Controller/CountFriday13Controller.php b/src/Controller/CountFriday13Controller.php index 88e200c..dc3e741 100644 --- a/src/Controller/CountFriday13Controller.php +++ b/src/Controller/CountFriday13Controller.php @@ -2,27 +2,24 @@ namespace App\Controller; +use App\Actions\CountFriday13Action; +use App\Requests\AllFri13Request; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; -use function App\Repository\countFriday13; class CountFriday13Controller extends AbstractController { /** * git Контроллер вернет все пятницы 13 в году используя countFriday13 функцию - * @param Request $request + * @param AllFri13Request $request + * @param CountFriday13Action $action * @return Response */ #[Route('/count/friday13', name: 'app_count_friday13')] - public function index(Request $request): Response + public function index(AllFri13Request $request, CountFriday13Action $action): Response { - $year = $request->toArray()['year']; - - $returnableArray = countFriday13($year); - - return new JsonResponse($returnableArray, Response::HTTP_OK); + return new JsonResponse($action->act($request->serialise())); } } diff --git a/src/Repository/CountFriday13Repository.php b/src/Repository/CountFriday13Repository.php deleted file mode 100644 index 8d3e0d7..0000000 --- a/src/Repository/CountFriday13Repository.php +++ /dev/null @@ -1,23 +0,0 @@ -setDate($year, $i, 13); - - if ($next13->format("D") === 'Fri'){ - $AllFri13[] = $next13; - } - } - return $AllFri13; -} diff --git a/src/Requests/AllFri13Request.php b/src/Requests/AllFri13Request.php new file mode 100644 index 0000000..d98cebb --- /dev/null +++ b/src/Requests/AllFri13Request.php @@ -0,0 +1,21 @@ +year; + } +} \ No newline at end of file -- GitLab