Skip to content
Snippets Groups Projects
Commit ca5ff1b7 authored by Адлан Шамавов's avatar Адлан Шамавов
Browse files

Merge branch 'PTPS_Controller_1' into PTPS_Controller_2

parents b02ed450 498dda71
No related branches found
No related tags found
1 merge request!3Ptps controller 3
......@@ -52,4 +52,4 @@ class Functions
}
return null;
}
}
}
\ No newline at end of file
......@@ -4,9 +4,9 @@ namespace App\Controller;
use App\Action\Functions;
use App\Validation\ArrayValidation;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;
class HomeController extends AbstractController
......@@ -18,6 +18,17 @@ class HomeController extends AbstractController
$this->functions = $functions;
}
#[Route('/func1', name: 'home', methods: ['POST'])]
public function func1(Request $request): Response
{
$array = $request->get('arr');
if (!ArrayValidation::validateFunc1($array)) {
return new Response("Invalid array");
}
$array = $this->functions->sortPrice($array);
return $this->json($array);
}
#[Route('/', name: 'home', methods: ['POST'])]
public function home(Request $request): Response
{
......
......@@ -2,12 +2,15 @@
namespace App\Validation;
use Symfony\Component\Validator\Validation;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\ConstraintViolationListInterface;
class ArrayValidation
{
public static function validateFunc1(array $array): bool
{
$prices = array_column($array, 'price');
$counts = array_column($array, 'count');
return ctype_digit(implode('',$prices)) && ctype_digit(implode('', $counts));
}
public static function validate(array $array): ConstraintViolationListInterface
{
$validator = Validation::createValidator();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment