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]);
|
||||
}
|
||||
}
|
||||
39
app/domain/Api/MyApi/v1/Handlers/TranslationsHandler.php
Normal file
39
app/domain/Api/MyApi/v1/Handlers/TranslationsHandler.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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;
|
||||
use Nette\Utils\Strings;
|
||||
|
||||
class TranslationsHandler extends Basehandler
|
||||
{
|
||||
private $em;
|
||||
|
||||
public function __construct(EntityManager $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function handle(array $params): ResponseInterface
|
||||
{
|
||||
$trs = $this->em->getTranslationRepository()->findBy([], ['id' => 'ASC', 'direction' => 'ASC']);
|
||||
$translations = [];
|
||||
foreach ($trs as $t) {
|
||||
$lang1 = $t->getLangName1();
|
||||
$lang2 = $t->getLangName2();
|
||||
|
||||
$lang = mb_substr($lang1, 0, -1);
|
||||
$lang .= "o-" . $lang2;
|
||||
$slug = Strings::webalize($lang);
|
||||
$translations[$t->id]["slug"] = $slug;
|
||||
$translations[$t->id]["lang"] = $lang;
|
||||
}
|
||||
|
||||
return new JsonApiResponse(200, ['status' => 'ok', 'translations' => $translations]);
|
||||
}
|
||||
}
|
||||
29
app/domain/Api/MyApi/v1/Handlers/UsersListingHandler.php
Executable file
29
app/domain/Api/MyApi/v1/Handlers/UsersListingHandler.php
Executable file
@@ -0,0 +1,29 @@
|
||||
<?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;
|
||||
|
||||
class UsersListingHandler extends Basehandler
|
||||
{
|
||||
private $em;
|
||||
|
||||
public function __construct(EntityManager $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function handle(array $params): ResponseInterface
|
||||
{
|
||||
//$users = [];
|
||||
//foreach ($this->userRepository->all() as $user) {
|
||||
// $users[] = $user->toArray();
|
||||
//}
|
||||
$users = [ 'name' => 'test'];
|
||||
return new JsonApiResponse(200, ['status' => 'ok', 'users' => $users]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user