From 6994e1f1475b351cf77f7e4d572d97c0ee0ff694 Mon Sep 17 00:00:00 2001 From: "Alex. Plokhikh" Date: Mon, 15 Apr 2024 15:58:59 +0500 Subject: [PATCH 1/5] create search actions controller and req --- src/Actions/IdSearchAction.php | 29 +++++++++++++++++ src/Controller/IdSearchController.php | 27 ++++++++++++++++ src/Requests/UsersRequest.php | 45 +++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 src/Actions/IdSearchAction.php create mode 100644 src/Controller/IdSearchController.php create mode 100644 src/Requests/UsersRequest.php diff --git a/src/Actions/IdSearchAction.php b/src/Actions/IdSearchAction.php new file mode 100644 index 0000000..6953291 --- /dev/null +++ b/src/Actions/IdSearchAction.php @@ -0,0 +1,29 @@ + 30, + * 'name' => 'Jhon', + * 'age' => 23, + * ] + * @param $id - ид искомого элемента + * @return array|null - найденный элемент/ вернет null при его отсутствии + */ + public static function act(array $array): ?array + { + + foreach ($array['users'] as $item){ + if ($item['id'] === $array['id']){ + return $item; + } + } + + return null; + } +} diff --git a/src/Controller/IdSearchController.php b/src/Controller/IdSearchController.php new file mode 100644 index 0000000..86ba514 --- /dev/null +++ b/src/Controller/IdSearchController.php @@ -0,0 +1,27 @@ +act($request->serialise()), + 200 + ); + } +} \ No newline at end of file diff --git a/src/Requests/UsersRequest.php b/src/Requests/UsersRequest.php new file mode 100644 index 0000000..1d5bd95 --- /dev/null +++ b/src/Requests/UsersRequest.php @@ -0,0 +1,45 @@ + [ + new Type('integer'), + new NotBlank(), + ], + 'name' => [ + new Type('string'), + new NotBlank(), + ], + 'age' => new Optional([ + new Type('integer'), + ]) + ]) + )] + public $users; + + /** + * @return array + */ + public function serialise(): array + { + return [ + 'id' => $this->id, + 'users' => $this->users, + ]; + } +} \ No newline at end of file -- GitLab From 90b33d9eecf870666ea555970f64b5e0a6ee45b2 Mon Sep 17 00:00:00 2001 From: "Alex. Plokhikh" Date: Mon, 15 Apr 2024 16:05:21 +0500 Subject: [PATCH 2/5] rm twig --- templates/id_search/index.html.twig | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 templates/id_search/index.html.twig diff --git a/templates/id_search/index.html.twig b/templates/id_search/index.html.twig deleted file mode 100644 index 69a280e..0000000 --- a/templates/id_search/index.html.twig +++ /dev/null @@ -1,20 +0,0 @@ -{% extends 'base.html.twig' %} - -{% block title %}Hello IdSearchController!{% endblock %} - -{% block body %} - - -
-

Hello {{ controller_name }}! ✅

- - This friendly message is coming from: -
    -
  • Your controller at /home/tamanit/myProj/iqdevTranningProgram/src/Controller/IdSearchController.php
  • -
  • Your template at /home/tamanit/myProj/iqdevTranningProgram/templates/id_search/index.html.twig
  • -
-
-{% endblock %} -- GitLab From b1b65e4ea0f8dfc30e071856d3291faf913fff1a Mon Sep 17 00:00:00 2001 From: "Alex. Plokhikh" Date: Tue, 16 Apr 2024 01:16:40 +0500 Subject: [PATCH 3/5] rm manual http status init in resp --- src/Controller/SortPriceController.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Controller/SortPriceController.php b/src/Controller/SortPriceController.php index 313d3dc..1b2b9ca 100644 --- a/src/Controller/SortPriceController.php +++ b/src/Controller/SortPriceController.php @@ -15,16 +15,13 @@ class SortPriceController extends AbstractController { /** * Контроллер волняет сортировку массива по убыванию цены используя sortPrice - * @param Request $request + * @param PricesRequest $request * @param SortPriceAction $action * @return JsonResponse */ #[Route('/sort/price', name: 'app_sort_price', methods: ['POST'])] public function index(PricesRequest $request, SortPriceAction $action): JsonResponse { - return new JsonResponse( - $action->act($request->serialise()), - 200 - ); + return new JsonResponse($action->act($request->serialise())); } } -- GitLab From b175b9eaff0db789d7d94ba0636d2a309c37431c Mon Sep 17 00:00:00 2001 From: "Alex. Plokhikh" Date: Tue, 16 Apr 2024 01:21:16 +0500 Subject: [PATCH 4/5] rm uselsess use --- src/Controller/SortPriceController.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Controller/SortPriceController.php b/src/Controller/SortPriceController.php index 1b2b9ca..0f1d250 100644 --- a/src/Controller/SortPriceController.php +++ b/src/Controller/SortPriceController.php @@ -3,12 +3,9 @@ namespace App\Controller; use App\Actions\SortPriceAction; -use App\Entity\PricesEntity; use App\Requests\PricesRequest; -use App\Service\ValidationService; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Attribute\Route; class SortPriceController extends AbstractController -- GitLab From d8d5f596de625eb69fc9823f1ffc56adee19a5b7 Mon Sep 17 00:00:00 2001 From: "Alex. Plokhikh" Date: Tue, 16 Apr 2024 01:40:36 +0500 Subject: [PATCH 5/5] rm another 200 status --- src/Controller/IdSearchController.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Controller/IdSearchController.php b/src/Controller/IdSearchController.php index 86ba514..3dd1716 100644 --- a/src/Controller/IdSearchController.php +++ b/src/Controller/IdSearchController.php @@ -19,9 +19,6 @@ class IdSearchController extends AbstractController #[Route('/search', name: 'app_search', methods: ['POST'])] public function index(UsersRequest $request, IdSearchAction $action): JsonResponse { - return new JsonResponse( - $action->act($request->serialise()), - 200 - ); + return new JsonResponse($action->act($request->serialise())); } } \ No newline at end of file -- GitLab