Commit ca5ff1b7 authored by Адлан Шамавов's avatar Адлан Шамавов
Browse files

Merge branch 'PTPS_Controller_1' into PTPS_Controller_2

parents b02ed450 498dda71
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -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
    {
+7 −4
Original line number Diff line number Diff line
@@ -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();
+1 −1

File changed.

Contains only whitespace changes.