Skip to content

Commit

Permalink
[modules] Prepare for front end - next stage (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Dec 22, 2023
1 parent 11eaa28 commit 1c63f1b
Show file tree
Hide file tree
Showing 68 changed files with 759 additions and 763 deletions.
2 changes: 1 addition & 1 deletion docs/Home.md
Expand Up @@ -64,7 +64,7 @@ Example configuration could be found [here](https://github.com/FastyBird/devices
This module is using database, and need some initial data to be inserted into it.

```sh
your-console-entrypoint fb:devices-module:initialize
your-console-entrypoint fb:devices-module:install
```

This console command is interactive and will ask for all required information.
4 changes: 2 additions & 2 deletions src/Commands/Exchange.php
Expand Up @@ -127,7 +127,7 @@ protected function execute(
// Log caught exception
$this->logger->error('An unhandled error occurred', [
'source' => MetadataTypes\ModuleSource::SOURCE_MODULE_DEVICES,
'type' => 'command',
'type' => 'exchange-cmd',
'exception' => BootstrapHelpers\Logger::buildException($ex),
]);

Expand All @@ -145,7 +145,7 @@ private function terminate(): void
{
$this->logger->info('Stopping exchange...', [
'source' => MetadataTypes\ModuleSource::SOURCE_MODULE_DEVICES,
'type' => 'command',
'type' => 'exchange-cmd',
]);

$this->eventLoop->stop();
Expand Down
28 changes: 14 additions & 14 deletions src/Commands/Initialize.php → src/Commands/Install.php
@@ -1,7 +1,7 @@
<?php declare(strict_types = 1);

/**
* Initialize.php
* Install.php
*
* @license More in LICENSE.md
* @copyright https://www.fastybird.com
Expand All @@ -27,17 +27,17 @@
use Throwable;

/**
* Module initialize command
* Module install command
*
* @package FastyBird:DevicesModule!
* @subpackage Commands
*
* @author Adam Kadlec <adam.kadlec@fastybird.com>
*/
class Initialize extends Console\Command\Command
class Install extends Console\Command\Command
{

public const NAME = 'fb:devices-module:initialize';
public const NAME = 'fb:devices-module:install';

public function __construct(
private readonly Models\Configuration\Builder $configurationBuilder,
Expand All @@ -56,7 +56,7 @@ protected function configure(): void
{
$this
->setName(self::NAME)
->setDescription('Devices module initialization');
->setDescription('Devices module installer');
}

/**
Expand All @@ -73,9 +73,9 @@ protected function execute(Input\InputInterface $input, Output\OutputInterface $
$io = new Style\SymfonyStyle($input, $output);

if ($input->getOption('quiet') === false) {
$io->title($this->translator->translate('//devices-module.cmd.initialize.title'));
$io->title($this->translator->translate('//devices-module.cmd.install.title'));

$io->note($this->translator->translate('//devices-module.cmd.initialize.subtitle'));
$io->note($this->translator->translate('//devices-module.cmd.install.subtitle'));
}

if ($input->getOption('no-interaction') === false) {
Expand All @@ -97,20 +97,20 @@ protected function execute(Input\InputInterface $input, Output\OutputInterface $
$this->configurationBuilder->clean();

if ($input->getOption('quiet') === false) {
$io->success($this->translator->translate('//devices-module.cmd.initialize.messages.success'));
$io->success($this->translator->translate('//devices-module.cmd.install.messages.success'));
}

return Console\Command\Command::SUCCESS;
} catch (Throwable $ex) {
// Log caught exception
$this->logger->error('An unhandled error occurred', [
'source' => MetadataTypes\ModuleSource::SOURCE_MODULE_DEVICES,
'type' => 'command',
'type' => 'initialize-cmd',
'exception' => BootstrapHelpers\Logger::buildException($ex),
]);

if ($input->getOption('quiet') === false) {
$io->error($this->translator->translate('//devices-module.cmd.initialize.messages.error'));
$io->error($this->translator->translate('//devices-module.cmd.install.messages.error'));
}

return Console\Command\Command::FAILURE;
Expand All @@ -134,7 +134,7 @@ private function initializeDatabase(
}

if ($input->getOption('quiet') === false) {
$io->section($this->translator->translate('//devices-module.cmd.initialize.info.database'));
$io->section($this->translator->translate('//devices-module.cmd.install.info.database'));
}

$databaseCmd = $symfonyApp->find('orm:schema-tool:update');
Expand All @@ -146,7 +146,7 @@ private function initializeDatabase(
if ($result !== Console\Command\Command::SUCCESS) {
if ($input->getOption('quiet') === false) {
$io->error(
$this->translator->translate('//devices-module.cmd.initialize.messages.initialisationFailed'),
$this->translator->translate('//devices-module.cmd.install.messages.initialisationFailed'),
);
}

Expand All @@ -161,14 +161,14 @@ private function initializeDatabase(

if ($result !== 0) {
if ($input->getOption('quiet') === false) {
$io->error($this->translator->translate('//devices-module.cmd.initialize.messages.databaseFailed'));
$io->error($this->translator->translate('//devices-module.cmd.install.messages.databaseFailed'));
}

return;
}

if ($input->getOption('quiet') === false) {
$io->success($this->translator->translate('//devices-module.cmd.initialize.messages.databaseReady'));
$io->success($this->translator->translate('//devices-module.cmd.install.messages.databaseReady'));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/DI/DevicesExtension.php
Expand Up @@ -592,7 +592,7 @@ public function loadConfiguration(): void
}

$builder->addDefinition($this->prefix('commands.initialize'), new DI\Definitions\ServiceDefinition())
->setType(Commands\Initialize::class)
->setType(Commands\Install::class)
->setArguments([
'logger' => $logger,
]);
Expand Down
22 changes: 13 additions & 9 deletions src/Router/ApiRoutes.php
Expand Up @@ -69,16 +69,20 @@ public function __construct(

public function registerRoutes(Routing\IRouter $router): void
{
if ($this->usePrefix) {
$routes = $router->group('/' . Metadata\Constants::MODULE_DEVICES_PREFIX, function (
Routing\RouteCollector $group,
): void {
$this->buildRoutes($group);
});
$routes = $router->group('/' . Metadata\Constants::ROUTER_API_PREFIX, function (
Routing\RouteCollector $group,
): void {
if ($this->usePrefix) {
$group->group('/' . Metadata\Constants::MODULE_DEVICES_PREFIX, function (
Routing\RouteCollector $group,
): void {
$this->buildRoutes($group);
});

} else {
$routes = $this->buildRoutes($router);
}
} else {
$this->buildRoutes($group);
}
});

$routes->addMiddleware($this->accessControlMiddleware);
$routes->addMiddleware($this->userMiddleware);
Expand Down
94 changes: 43 additions & 51 deletions src/Translations/devices-module.en_US.neon
Expand Up @@ -16,62 +16,62 @@
base:
messages:
notValidJson:
heading : "Not valid content"
message : "Provided request content is not valid JSON content"
heading: "Not valid content"
message: "Provided request content is not valid JSON content"
notValidJsonApi:
heading : "Not valid content"
message : "Provided request content is not valid {JSON:API} content"
heading: "Not valid content"
message: "Provided request content is not valid {JSON:API} content"
failed:
heading : "Request failed"
message : "Provided request failed and can't be finished"
heading: "Request failed"
message: "Provided request failed and can't be finished"
forbidden:
heading : "Not allowed"
message : "You are not allowed to perform this action"
heading: "Not allowed"
message: "You are not allowed to perform this action"
unauthorized:
heading : "Not authorized"
message : "You are not authorized to perform this action"
heading: "Not authorized"
message: "You are not authorized to perform this action"
notFound:
heading : "Not found"
message : "Requested entity was not found"
heading: "Not found"
message: "Requested entity was not found"
notCreated:
heading : "System error"
message : "Something went wrong, entity could not be created"
heading: "System error"
message: "Something went wrong, entity could not be created"
notUpdated:
heading : "System error"
message : "Something went wrong, entity could not be updated"
heading: "System error"
message: "Something went wrong, entity could not be updated"
notDeleted:
heading : "System error"
message : "Something went wrong, entity could not be deleted"
heading: "System error"
message: "Something went wrong, entity could not be deleted"
invalidIdentifier:
heading : "Invalid identifier"
message : "Provided entity identifier is not valid"
heading: "Invalid identifier"
message: "Provided entity identifier is not valid"
invalidType:
heading : "Invalid type"
message : "Provided entity type is not valid"
heading: "Invalid type"
message: "Provided entity type is not valid"
invalidAttribute:
heading : "Invalid attribute"
message : "Provided entity attribute is not valid"
heading: "Invalid attribute"
message: "Provided entity attribute is not valid"
invalidRelation:
heading : "Invalid relation"
message : "Provided relation is not valid"
heading: "Invalid relation"
message: "Provided relation is not valid"
unknownRelation:
heading : "Relation not found"
message : "Requested unknown relation"
heading: "Relation not found"
message: "Requested unknown relation"
relationNotFound:
heading : "Relation not found"
message : "Requested relation %relation% was not found"
heading: "Relation not found"
message: "Requested relation %relation% was not found"
missingAttribute:
heading : "Missing attribute"
message : "Provided request is missing required attribute"
heading: "Missing attribute"
message: "Provided request is missing required attribute"
missingRelation:
heading : "Missing required relation"
message : "Provided request is missing required relation"
heading: "Missing required relation"
message: "Provided request is missing required relation"
uniqueIdentifier:
heading : "Identifier not unique"
message : "Provided identifier is not unique"
heading: "Identifier not unique"
message: "Provided identifier is not unique"
uniqueAttribute:
heading : "Attribute not unique"
message : "Provided attribute is not unique"
heading: "Attribute not unique"
message: "Provided attribute is not unique"

cmd:
base:
Expand All @@ -83,34 +83,26 @@ cmd:
messages:
answerNotValid: "Selected answer: \"%s\" is not valid."

initialize:
title: "Devices module - initialization"
subtitle: "This action will create|update module database structure and build module configuration"
install:
title: "Devices module - installer"
subtitle: "This action will create|update|delete module configuration"

info:
database: "Preparing module database"

messages:
success: "Devices module has been successfully initialized and can be now used."
error: "Something went wrong, initialization could not be finished. Error was logged."
databaseReady: "Devices module database has been successfully initialized."
initialisationFailed: "Something went wrong, initialization could not be finished."
databaseReady: "Devices module database has been successfully initialized."
databaseFailed: "Something went wrong, database initialization could not be finished."

configuration:
title: "Devices module - configuration"
subtitle: "This action will create|update module configuration"

messages:
success: "Devices module configuration has been successfully build."
error: "Something went wrong, configuration initialization could not be finished. Error was logged."

exchange:
title: "Devices module - exchange"
subtitle: "This action will run module exchange service"

messages:
error: "Something went wrong, service could not be finished. Error was logged."
error: "Something went wrong, an unhandled error occur. Error was logged."

connector:
title: "Devices module - connector"
Expand Down

0 comments on commit 1c63f1b

Please sign in to comment.