Basic functionality
This commit is contained in:
32
app/domain/Api/MyApi/v1/Handlers/TermsHandler.php
Executable file
32
app/domain/Api/MyApi/v1/Handlers/TermsHandler.php
Executable file
@@ -0,0 +1,32 @@
|
||||
<?php //declare(strict_types = 1);
|
||||
|
||||
namespace App\MyApi\v1\Handlers;
|
||||
|
||||
use App\Model\Database\EntityManager;
|
||||
use Tomaj\NetteApi\Handlers\BaseHandler;
|
||||
use Tomaj\NetteApi\Response\JsonApiResponse;
|
||||
use Tomaj\NetteApi\Response\ResponseInterface;
|
||||
use App\Model\Database\Facade\TermFacade;
|
||||
|
||||
class TermsHandler extends Basehandler
|
||||
{
|
||||
private $em;
|
||||
private $termFacade;
|
||||
|
||||
public function __construct(EntityManager $em, TermFacade $tf)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->em = $em;
|
||||
$this->termFacade = $tf;
|
||||
}
|
||||
|
||||
public function handle(array $params): ResponseInterface
|
||||
{
|
||||
$translation = $this->em->getTranslationRepository()->findOneBy(['id' => $_GET['translation']]);
|
||||
$this->termFacade->setDirection($translation->direction);
|
||||
$q = $this->termFacade->findByStringFull($_GET['string'], $translation->dictionary, '');
|
||||
$terms = $q->getArrayResult();
|
||||
|
||||
return new JsonApiResponse(200, ['status' => 'ok', 'terms' => $terms]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user