From 19237b0dcf119ef01654ff1f5c03b7b7244e52f3 Mon Sep 17 00:00:00 2001 From: Akex Date: Tue, 9 Apr 2024 02:09:49 +0500 Subject: [PATCH 1/4] make controller --- src/Controller/DiffDaysController.php | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/Controller/DiffDaysController.php diff --git a/src/Controller/DiffDaysController.php b/src/Controller/DiffDaysController.php new file mode 100644 index 0000000..a5c7c11 --- /dev/null +++ b/src/Controller/DiffDaysController.php @@ -0,0 +1,29 @@ +toArray()['date_start']); + $dateEnd = new DateTimeImmutable($request->toArray()['date_end']); + + return new JsonResponse(["interval"=>($dateStart->diff($dateEnd)->format("%a"))] + , Response::HTTP_OK); + } +} -- GitLab From 48b0e95da20d7859eb912cffa1f96f0beb7467b9 Mon Sep 17 00:00:00 2001 From: "Alex. Plokhikh" Date: Tue, 16 Apr 2024 03:24:28 +0500 Subject: [PATCH 2/4] add diff days action | controller | req --- src/Actions/DiffDaysAction.php | 21 +++++++++++++++++++ src/Controller/DiffDaysController.php | 14 ++++++------- src/Requests/DiffDaysRequest.php | 29 +++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 src/Actions/DiffDaysAction.php create mode 100644 src/Requests/DiffDaysRequest.php diff --git a/src/Actions/DiffDaysAction.php b/src/Actions/DiffDaysAction.php new file mode 100644 index 0000000..c3ee3c2 --- /dev/null +++ b/src/Actions/DiffDaysAction.php @@ -0,0 +1,21 @@ +diff($dateEnd)->format('%a'); + } +} diff --git a/src/Controller/DiffDaysController.php b/src/Controller/DiffDaysController.php index a5c7c11..8c74584 100644 --- a/src/Controller/DiffDaysController.php +++ b/src/Controller/DiffDaysController.php @@ -2,6 +2,8 @@ namespace App\Controller; +use App\Actions\DiffDaysAction; +use App\Requests\DiffDaysRequest; use DateTimeImmutable; use HttpResponse; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -14,16 +16,14 @@ class DiffDaysController extends AbstractController { /** * Контроллер вернет кол-во дней между датами - * @param Request $request + * @param DiffDaysRequest $request + * @param DiffDaysAction $action * @return Response */ #[Route('/diff/days', name: 'app_diff_days', methods: ['POST'])] - public function index(Request $request): Response + public function index(DiffDaysRequest $request, DiffDaysAction $action): Response { - $dateStart = new DateTimeImmutable($request->toArray()['date_start']); - $dateEnd = new DateTimeImmutable($request->toArray()['date_end']); - - return new JsonResponse(["interval"=>($dateStart->diff($dateEnd)->format("%a"))] - , Response::HTTP_OK); + $array = $request->serialise(); + return new JsonResponse($action->act($array[0], $array[1])); } } diff --git a/src/Requests/DiffDaysRequest.php b/src/Requests/DiffDaysRequest.php new file mode 100644 index 0000000..95295fd --- /dev/null +++ b/src/Requests/DiffDaysRequest.php @@ -0,0 +1,29 @@ + new DateTimeImmutable($this->startDate), + 'endDate' => new DateTimeImmutable($this->endDate), + ]; + } +} \ No newline at end of file -- GitLab From ac83168a362a5469e70b1d6891b5ecb38d74cc6d Mon Sep 17 00:00:00 2001 From: "Alex. Plokhikh" Date: Tue, 16 Apr 2024 04:19:28 +0500 Subject: [PATCH 3/4] rm uselsess use --- src/Controller/DiffDaysController.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Controller/DiffDaysController.php b/src/Controller/DiffDaysController.php index 8c74584..a82687e 100644 --- a/src/Controller/DiffDaysController.php +++ b/src/Controller/DiffDaysController.php @@ -4,11 +4,8 @@ namespace App\Controller; use App\Actions\DiffDaysAction; use App\Requests\DiffDaysRequest; -use DateTimeImmutable; -use HttpResponse; 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; -- GitLab From 06ac412f0f37e8a3cdc354b07d6cd0b6a6634777 Mon Sep 17 00:00:00 2001 From: "Alex. Plokhikh" Date: Wed, 17 Apr 2024 10:26:11 +0500 Subject: [PATCH 4/4] chenge array indexation --- src/Controller/DiffDaysController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/DiffDaysController.php b/src/Controller/DiffDaysController.php index a82687e..7dc8cd8 100644 --- a/src/Controller/DiffDaysController.php +++ b/src/Controller/DiffDaysController.php @@ -21,6 +21,6 @@ class DiffDaysController extends AbstractController public function index(DiffDaysRequest $request, DiffDaysAction $action): Response { $array = $request->serialise(); - return new JsonResponse($action->act($array[0], $array[1])); + return new JsonResponse($action->act($array['startDate'], $array['endDate'])); } } -- GitLab