Skip to content

Commit

Permalink
[ui-module][general] Move widgets data sources into bridges (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Aug 5, 2024
1 parent 72478bb commit 9de929a
Show file tree
Hide file tree
Showing 69 changed files with 648 additions and 671 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"fastybird/application-library": "dev-main",
"fastybird/datetime-factory": "^0.6",
"fastybird/exchange-library": "dev-main",
"fastybird/json-api": "^0.17",
"fastybird/json-api": "^0.18",
"fastybird/metadata-library": "dev-main",
"fastybird/simple-auth": "^0.14",
"fastybird/tools-library": "dev-main",
Expand Down
4 changes: 0 additions & 4 deletions resources/schemas/document.widget.dataSource.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
"type": "string",
"description": "Data source source"
},
"params": {
"type": "object"
},
"widget": {
"type": "string",
"format": "uuid",
Expand Down Expand Up @@ -60,7 +57,6 @@
},
"required": [
"id",
"params",
"widget",
"owner"
]
Expand Down
30 changes: 17 additions & 13 deletions src/Controllers/BaseV1.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ abstract class BaseV1

protected Router\Validator $routesValidator;

/** @var JsonApiHydrators\Container<DoctrineCrud\Entities\IEntity> */
protected JsonApiHydrators\Container $hydratorsContainer;

protected Ui\Logger $logger;
Expand Down Expand Up @@ -93,6 +94,9 @@ public function injectRoutesValidator(Router\Validator $validator): void
$this->routesValidator = $validator;
}

/**
* @param JsonApiHydrators\Container<DoctrineCrud\Entities\IEntity> $hydratorsContainer
*/
public function injectHydratorsContainer(JsonApiHydrators\Container $hydratorsContainer): void
{
$this->hydratorsContainer = $hydratorsContainer;
Expand All @@ -112,18 +116,18 @@ public function readRelationship(
if ($relationEntity !== '') {
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_NOT_FOUND,
$this->translator->translate('//ui-module.base.messages.relationNotFound.heading'),
$this->translator->translate(
strval($this->translator->translate('//ui-module.base.messages.relationNotFound.heading')),
strval($this->translator->translate(
'//ui-module.base.messages.relationNotFound.message',
['relation' => $relationEntity],
),
)),
);
}

throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_NOT_FOUND,
$this->translator->translate('//ui-module.base.messages.unknownRelation.heading'),
$this->translator->translate('//ui-module.base.messages.unknownRelation.message'),
strval($this->translator->translate('//ui-module.base.messages.unknownRelation.heading')),
strval($this->translator->translate('//ui-module.base.messages.unknownRelation.message')),
);
}

Expand All @@ -139,8 +143,8 @@ protected function createDocument(Message\ServerRequestInterface $request): Json
if (!$content instanceof stdClass) {
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_BAD_REQUEST,
$this->translator->translate('//ui-module.base.messages.notValidJsonApi.heading'),
$this->translator->translate('//ui-module.base.messages.notValidJsonApi.message'),
strval($this->translator->translate('//ui-module.base.messages.notValidJsonApi.heading')),
strval($this->translator->translate('//ui-module.base.messages.notValidJsonApi.message')),
);
}

Expand All @@ -149,14 +153,14 @@ protected function createDocument(Message\ServerRequestInterface $request): Json
} catch (Utils\JsonException) {
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_BAD_REQUEST,
$this->translator->translate('//ui-module.base.messages.notValidJson.heading'),
$this->translator->translate('//ui-module.base.messages.notValidJson.message'),
strval($this->translator->translate('//ui-module.base.messages.notValidJson.heading')),
strval($this->translator->translate('//ui-module.base.messages.notValidJson.message')),
);
} catch (JsonAPIDocument\Exceptions\RuntimeException) {
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_BAD_REQUEST,
$this->translator->translate('//ui-module.base.messages.notValidJsonApi.heading'),
$this->translator->translate('//ui-module.base.messages.notValidJsonApi.message'),
strval($this->translator->translate('//ui-module.base.messages.notValidJsonApi.heading')),
strval($this->translator->translate('//ui-module.base.messages.notValidJsonApi.message')),
);
}

Expand All @@ -181,8 +185,8 @@ protected function validateIdentifier(
) {
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_BAD_REQUEST,
$this->translator->translate('//ui-module.base.messages.invalidIdentifier.heading'),
$this->translator->translate('//ui-module.base.messages.invalidIdentifier.message'),
strval($this->translator->translate('//ui-module.base.messages.invalidIdentifier.heading')),
strval($this->translator->translate('//ui-module.base.messages.invalidIdentifier.message')),
);
}

Expand Down
52 changes: 26 additions & 26 deletions src/Controllers/DashboardsV1.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,20 @@ public function create(

} catch (JsonApiExceptions\JsonApi $ex) {
throw $ex;
} catch (DoctrineCrudExceptions\MissingRequiredFieldException $ex) {
} catch (DoctrineCrudExceptions\MissingRequiredField $ex) {
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY,
$this->translator->translate('//ui-module.base.messages.missingAttribute.heading'),
$this->translator->translate('//ui-module.base.messages.missingAttribute.message'),
strval($this->translator->translate('//ui-module.base.messages.missingAttribute.heading')),
strval($this->translator->translate('//ui-module.base.messages.missingAttribute.message')),
[
'pointer' => '/data/attributes/' . Utilities\Api::fieldToJsonApi($ex->getField()),
],
);
} catch (DoctrineCrudExceptions\EntityCreationException $ex) {
} catch (DoctrineCrudExceptions\EntityCreation $ex) {
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY,
$this->translator->translate('//ui-module.base.messages.missingAttribute.heading'),
$this->translator->translate('//ui-module.base.messages.missingAttribute.message'),
strval($this->translator->translate('//ui-module.base.messages.missingAttribute.heading')),
strval($this->translator->translate('//ui-module.base.messages.missingAttribute.message')),
[
'pointer' => '/data/attributes/' . Utilities\Api::fieldToJsonApi($ex->getField()),
],
Expand All @@ -145,8 +145,8 @@ public function create(
if (preg_match("%PRIMARY'%", $ex->getMessage(), $match) === 1) {
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY,
$this->translator->translate('//ui-module.base.messages.uniqueIdentifier.heading'),
$this->translator->translate('//ui-module.base.messages.uniqueIdentifier.message'),
strval($this->translator->translate('//ui-module.base.messages.uniqueIdentifier.heading')),
strval($this->translator->translate('//ui-module.base.messages.uniqueIdentifier.message')),
[
'pointer' => '/data/id',
],
Expand All @@ -158,8 +158,8 @@ public function create(
if (str_starts_with($columnKey, 'dashboard_')) {
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY,
$this->translator->translate('//ui-module.base.messages.uniqueAttribute.heading'),
$this->translator->translate('//ui-module.base.messages.uniqueAttribute.message'),
strval($this->translator->translate('//ui-module.base.messages.uniqueAttribute.heading')),
strval($this->translator->translate('//ui-module.base.messages.uniqueAttribute.message')),
[
'pointer' => '/data/attributes/' . Utilities\Api::fieldToJsonApi(
Utils\Strings::substring($columnKey, 7),
Expand All @@ -171,8 +171,8 @@ public function create(

throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY,
$this->translator->translate('//ui-module.base.messages.uniqueAttribute.heading'),
$this->translator->translate('//ui-module.base.messages.uniqueAttribute.message'),
strval($this->translator->translate('//ui-module.base.messages.uniqueAttribute.heading')),
strval($this->translator->translate('//ui-module.base.messages.uniqueAttribute.message')),
);
} catch (Throwable $ex) {
// Log caught exception
Expand All @@ -187,8 +187,8 @@ public function create(

throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY,
$this->translator->translate('//ui-module.base.messages.notCreated.heading'),
$this->translator->translate('//ui-module.base.messages.notCreated.message'),
strval($this->translator->translate('//ui-module.base.messages.notCreated.heading')),
strval($this->translator->translate('//ui-module.base.messages.notCreated.message')),
);
} finally {
// Revert all changes when error occur
Expand All @@ -204,8 +204,8 @@ public function create(

throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY,
$this->translator->translate('//ui-module.base.messages.invalidType.heading'),
$this->translator->translate('//ui-module.base.messages.invalidType.message'),
strval($this->translator->translate('//ui-module.base.messages.invalidType.heading')),
strval($this->translator->translate('//ui-module.base.messages.invalidType.message')),
[
'pointer' => '/data/type',
],
Expand Down Expand Up @@ -253,8 +253,8 @@ public function update(
if (str_starts_with($columnKey, 'dashboard_')) {
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY,
$this->translator->translate('//ui-module.base.messages.uniqueAttribute.heading'),
$this->translator->translate('//ui-module.base.messages.uniqueAttribute.message'),
strval($this->translator->translate('//ui-module.base.messages.uniqueAttribute.heading')),
strval($this->translator->translate('//ui-module.base.messages.uniqueAttribute.message')),
[
'pointer' => '/data/attributes/' . Utilities\Api::fieldToJsonApi(
Utils\Strings::substring($columnKey, 7),
Expand All @@ -266,8 +266,8 @@ public function update(

throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY,
$this->translator->translate('//ui-module.base.messages.uniqueAttribute.heading'),
$this->translator->translate('//ui-module.base.messages.uniqueAttribute.message'),
strval($this->translator->translate('//ui-module.base.messages.uniqueAttribute.heading')),
strval($this->translator->translate('//ui-module.base.messages.uniqueAttribute.message')),
);
} catch (Throwable $ex) {
// Log caught exception
Expand All @@ -282,8 +282,8 @@ public function update(

throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY,
$this->translator->translate('//ui-module.base.messages.notUpdated.heading'),
$this->translator->translate('//ui-module.base.messages.notUpdated.message'),
strval($this->translator->translate('//ui-module.base.messages.notUpdated.heading')),
strval($this->translator->translate('//ui-module.base.messages.notUpdated.message')),
);
} finally {
// Revert all changes when error occur
Expand All @@ -297,8 +297,8 @@ public function update(

throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY,
$this->translator->translate('//ui-module.base.messages.invalidType.heading'),
$this->translator->translate('//ui-module.base.messages.invalidType.message'),
strval($this->translator->translate('//ui-module.base.messages.invalidType.heading')),
strval($this->translator->translate('//ui-module.base.messages.invalidType.message')),
[
'pointer' => '/data/type',
],
Expand Down Expand Up @@ -348,8 +348,8 @@ public function delete(

throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY,
$this->translator->translate('//ui-module.base.messages.notDeleted.heading'),
$this->translator->translate('//ui-module.base.messages.notDeleted.message'),
strval($this->translator->translate('//ui-module.base.messages.notDeleted.heading')),
strval($this->translator->translate('//ui-module.base.messages.notDeleted.message')),
);
} finally {
// Revert all changes when error occur
Expand Down
52 changes: 26 additions & 26 deletions src/Controllers/DataSourcesV1.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,20 @@ public function create(

} catch (JsonApiExceptions\JsonApi $ex) {
throw $ex;
} catch (DoctrineCrudExceptions\MissingRequiredFieldException $ex) {
} catch (DoctrineCrudExceptions\MissingRequiredField $ex) {
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY,
$this->translator->translate('//ui-module.base.messages.missingAttribute.heading'),
$this->translator->translate('//ui-module.base.messages.missingAttribute.message'),
strval($this->translator->translate('//ui-module.base.messages.missingAttribute.heading')),
strval($this->translator->translate('//ui-module.base.messages.missingAttribute.message')),
[
'pointer' => '/data/attributes/' . Utilities\Api::fieldToJsonApi($ex->getField()),
],
);
} catch (DoctrineCrudExceptions\EntityCreationException $ex) {
} catch (DoctrineCrudExceptions\EntityCreation $ex) {
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY,
$this->translator->translate('//ui-module.base.messages.missingAttribute.heading'),
$this->translator->translate('//ui-module.base.messages.missingAttribute.message'),
strval($this->translator->translate('//ui-module.base.messages.missingAttribute.heading')),
strval($this->translator->translate('//ui-module.base.messages.missingAttribute.message')),
[
'pointer' => '/data/attributes/' . Utilities\Api::fieldToJsonApi($ex->getField()),
],
Expand All @@ -158,8 +158,8 @@ public function create(
if (preg_match("%PRIMARY'%", $ex->getMessage(), $match) === 1) {
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY,
$this->translator->translate('//ui-module.base.messages.uniqueIdentifier.heading'),
$this->translator->translate('//ui-module.base.messages.uniqueIdentifier.message'),
strval($this->translator->translate('//ui-module.base.messages.uniqueIdentifier.heading')),
strval($this->translator->translate('//ui-module.base.messages.uniqueIdentifier.message')),
[
'pointer' => '/data/id',
],
Expand All @@ -171,8 +171,8 @@ public function create(
if (str_starts_with($columnKey, 'dataSource_')) {
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY,
$this->translator->translate('//ui-module.base.messages.uniqueAttribute.heading'),
$this->translator->translate('//ui-module.base.messages.uniqueAttribute.message'),
strval($this->translator->translate('//ui-module.base.messages.uniqueAttribute.heading')),
strval($this->translator->translate('//ui-module.base.messages.uniqueAttribute.message')),
[
'pointer' => '/data/attributes/' . Utilities\Api::fieldToJsonApi(
Utils\Strings::substring($columnKey, 7),
Expand All @@ -184,8 +184,8 @@ public function create(

throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY,
$this->translator->translate('//ui-module.base.messages.uniqueAttribute.heading'),
$this->translator->translate('//ui-module.base.messages.uniqueAttribute.message'),
strval($this->translator->translate('//ui-module.base.messages.uniqueAttribute.heading')),
strval($this->translator->translate('//ui-module.base.messages.uniqueAttribute.message')),
);
} catch (Throwable $ex) {
// Log caught exception
Expand All @@ -200,8 +200,8 @@ public function create(

throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY,
$this->translator->translate('//ui-module.base.messages.notCreated.heading'),
$this->translator->translate('//ui-module.base.messages.notCreated.message'),
strval($this->translator->translate('//ui-module.base.messages.notCreated.heading')),
strval($this->translator->translate('//ui-module.base.messages.notCreated.message')),
);
} finally {
// Revert all changes when error occur
Expand All @@ -217,8 +217,8 @@ public function create(

throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY,
$this->translator->translate('//ui-module.base.messages.invalidType.heading'),
$this->translator->translate('//ui-module.base.messages.invalidType.message'),
strval($this->translator->translate('//ui-module.base.messages.invalidType.heading')),
strval($this->translator->translate('//ui-module.base.messages.invalidType.message')),
[
'pointer' => '/data/type',
],
Expand Down Expand Up @@ -277,8 +277,8 @@ public function update(

throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY,
$this->translator->translate('//ui-module.base.messages.notUpdated.heading'),
$this->translator->translate('//ui-module.base.messages.notUpdated.message'),
strval($this->translator->translate('//ui-module.base.messages.notUpdated.heading')),
strval($this->translator->translate('//ui-module.base.messages.notUpdated.message')),
);
} finally {
// Revert all changes when error occur
Expand All @@ -292,8 +292,8 @@ public function update(

throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY,
$this->translator->translate('//ui-module.base.messages.invalidType.heading'),
$this->translator->translate('//ui-module.base.messages.invalidType.message'),
strval($this->translator->translate('//ui-module.base.messages.invalidType.heading')),
strval($this->translator->translate('//ui-module.base.messages.invalidType.message')),
[
'pointer' => '/data/type',
],
Expand Down Expand Up @@ -346,8 +346,8 @@ public function delete(

throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY,
$this->translator->translate('//ui-module.base.messages.notDeleted.heading'),
$this->translator->translate('//ui-module.base.messages.notDeleted.message'),
strval($this->translator->translate('//ui-module.base.messages.notDeleted.heading')),
strval($this->translator->translate('//ui-module.base.messages.notDeleted.message')),
);
} finally {
// Revert all changes when error occur
Expand Down Expand Up @@ -401,15 +401,15 @@ protected function findDataSource(
if ($dataSource === null) {
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_NOT_FOUND,
$this->translator->translate('//ui-module.base.messages.notFound.heading'),
$this->translator->translate('//ui-module.base.messages.notFound.message'),
strval($this->translator->translate('//ui-module.base.messages.notFound.heading')),
strval($this->translator->translate('//ui-module.base.messages.notFound.message')),
);
}
} catch (Uuid\Exception\InvalidUuidStringException) {
throw new JsonApiExceptions\JsonApiError(
StatusCodeInterface::STATUS_NOT_FOUND,
$this->translator->translate('//ui-module.base.messages.notFound.heading'),
$this->translator->translate('//ui-module.base.messages.notFound.message'),
strval($this->translator->translate('//ui-module.base.messages.notFound.heading')),
strval($this->translator->translate('//ui-module.base.messages.notFound.message')),
);
}

Expand Down
Loading

0 comments on commit 9de929a

Please sign in to comment.