diff --git a/src/Api/MailTemplateListApiHandler.php b/src/Api/MailTemplateListApiHandler.php index 0497a7a..ef4e262 100644 --- a/src/Api/MailTemplateListApiHandler.php +++ b/src/Api/MailTemplateListApiHandler.php @@ -6,17 +6,23 @@ use Crm\ApiModule\Api\JsonResponse; use Crm\ApiModule\Authorization\ApiAuthorizationInterface; use Crm\RempMailerModule\Repositories\MailTemplatesRepository; +use Nette\Application\LinkGenerator; use Nette\Http\Response; class MailTemplateListApiHandler extends ApiHandler { private $mailTemplatesRepository; + private $linkGenerator; + private $allowedMailTypeCodes = []; - public function __construct(MailTemplatesRepository $mailTemplatesRepository) - { + public function __construct( + MailTemplatesRepository $mailTemplatesRepository, + LinkGenerator $linkGenerator + ) { $this->mailTemplatesRepository = $mailTemplatesRepository; + $this->linkGenerator = $linkGenerator; } public function params() @@ -40,6 +46,12 @@ public function handle(ApiAuthorizationInterface $authorization) $results[] = [ 'code' => $mailTemplate->code, 'name' => $mailTemplate->name, + 'link' => $this->linkGenerator->link( + 'RempMailer:MailTemplatesAdmin:show', + [ + 'code' => $mailTemplate->code, + ] + ), 'description' => $mailTemplate->description ?? "", 'mail_type' => [ 'code' => $mailTemplate->mail_type->code, diff --git a/src/Components/MailLogs/mail_logs.latte b/src/Components/MailLogs/mail_logs.latte index ed83b19..5c3b650 100644 --- a/src/Components/MailLogs/mail_logs.latte +++ b/src/Components/MailLogs/mail_logs.latte @@ -72,12 +72,12 @@ {$email->sent_at|userDate} - {$email->subject} + {$email->subject} {$email->attachment_size|bytes} attachment {$email->email} - {$email->mail_template->name} + {$email->mail_template->name} {$email->mail_template->code} diff --git a/src/Presenters/MailTemplatesAdminPresenter.php b/src/Presenters/MailTemplatesAdminPresenter.php index 4aa82e3..f60b22a 100644 --- a/src/Presenters/MailTemplatesAdminPresenter.php +++ b/src/Presenters/MailTemplatesAdminPresenter.php @@ -15,8 +15,8 @@ public function __construct(Config $config) $this->config = $config; } - public function actionShow($id) + public function actionShow($code) { - $this->redirectUrl("{$this->config->getHost()}/template/show/{$id}"); + $this->redirectUrl("{$this->config->getHost()}/template/show-by-code/{$code}"); } } diff --git a/src/Tests/MailTemplateListApiHandlerTest.php b/src/Tests/MailTemplateListApiHandlerTest.php index 8af705f..647ad9c 100644 --- a/src/Tests/MailTemplateListApiHandlerTest.php +++ b/src/Tests/MailTemplateListApiHandlerTest.php @@ -3,14 +3,35 @@ namespace Crm\RempMailerModule\Tests; use Crm\ApiModule\Authorization\NoAuthorization; +use Crm\ApplicationModule\Tests\DatabaseTestCase; use Crm\RempMailerModule\Api\MailTemplateListApiHandler; use Crm\RempMailerModule\Models\Api\Client; use Crm\RempMailerModule\Repositories\MailTemplatesRepository; +use Nette\Application\LinkGenerator; use Nette\Http\Response; -use PHPUnit\Framework\TestCase; -class MailTemplateListApiHandlerTest extends TestCase +class MailTemplateListApiHandlerTest extends DatabaseTestCase { + /** @var LinkGenerator */ + private $linkGenerator; + + protected function requiredRepositories(): array + { + return []; + } + + protected function requiredSeeders(): array + { + return []; + } + + public function setUp(): void + { + parent::setUp(); + + $this->linkGenerator = $this->inject(LinkGenerator::class); + } + public function testListing() { $mailTemplate = (object)[ @@ -30,7 +51,10 @@ public function testListing() ->andReturn([$mailTemplate]) ->getMock(); - $mailTemplateListApiHandler = new MailTemplateListApiHandler(new MailTemplatesRepository($client)); + $mailTemplateListApiHandler = new MailTemplateListApiHandler( + new MailTemplatesRepository($client), + $this->linkGenerator + ); $mailTemplateListApiHandler->addAllowedMailTypeCodes('test_templates'); $response = $mailTemplateListApiHandler->handle(new NoAuthorization()); $this->assertEquals(Response::S200_OK, $response->getHttpCode());