diff --git a/src/Actions/IdSearchAction.php b/src/Actions/IdSearchAction.php new file mode 100644 index 0000000000000000000000000000000000000000..695329150f8356cafbe37813f6c032ff44fd337b --- /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 0000000000000000000000000000000000000000..3dd1716b17df2919d4f5fc5ca78d4930393cd9b2 --- /dev/null +++ b/src/Controller/IdSearchController.php @@ -0,0 +1,24 @@ +act($request->serialise())); + } +} \ No newline at end of file diff --git a/src/Controller/SortPriceController.php b/src/Controller/SortPriceController.php index 313d3dc8c22d4304111a09bcec01e3a5b1bab5da..0f1d250b6c31ea3f0dee3f4581c722d10adb2cdf 100644 --- a/src/Controller/SortPriceController.php +++ b/src/Controller/SortPriceController.php @@ -3,28 +3,22 @@ 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 { /** * Контроллер волняет сортировку массива по убыванию цены используя 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())); } } diff --git a/src/Requests/UsersRequest.php b/src/Requests/UsersRequest.php new file mode 100644 index 0000000000000000000000000000000000000000..1d5bd95f0d2b5f3840e001e6247e272c555a8d82 --- /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 diff --git a/templates/id_search/index.html.twig b/templates/id_search/index.html.twig deleted file mode 100644 index 69a280e448c95e97964807ec52c04cf17bff3994..0000000000000000000000000000000000000000 --- 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: - -
-{% endblock %}