diff --git a/community_server/skeema/gradido_community/blockchain_types.sql b/community_server/skeema/gradido_community/blockchain_types.sql new file mode 100644 index 000000000..bd6a12604 --- /dev/null +++ b/community_server/skeema/gradido_community/blockchain_types.sql @@ -0,0 +1,17 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +/** + * Author: einhornimmond + * Created: 06.04.2021 + */ + +CREATE TABLE `blockchain_types` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(45) NOT NULL, + `text` varchar(255) NULL, + `symbol` varchar(10) NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/skeema/gradido_community/insert/insert_blockchain_types.sql b/community_server/skeema/gradido_community/insert/insert_blockchain_types.sql new file mode 100644 index 000000000..0a58e4392 --- /dev/null +++ b/community_server/skeema/gradido_community/insert/insert_blockchain_types.sql @@ -0,0 +1,5 @@ +INSERT INTO `blockchain_types` (`id`, `name`, `text`, `symbol`) VALUES +(1, 'mysql', 'use mysql db as blockchain, work only with single community-server', NULL), +(2, 'hedera', 'use hedera for transactions', 'HBAR'); + + diff --git a/community_server/skeema/gradido_community/transactions.sql b/community_server/skeema/gradido_community/transactions.sql index 566cfc048..8641f0057 100644 --- a/community_server/skeema/gradido_community/transactions.sql +++ b/community_server/skeema/gradido_community/transactions.sql @@ -5,5 +5,6 @@ CREATE TABLE `transactions` ( `tx_hash` binary(48) DEFAULT NULL, `memo` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `received` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `blockchain_type_id` bigint(20) unsigned NOT NULL DEFAULT 1, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/src/Controller/BlockchainTypesController.php b/community_server/src/Controller/BlockchainTypesController.php new file mode 100644 index 000000000..2a94037df --- /dev/null +++ b/community_server/src/Controller/BlockchainTypesController.php @@ -0,0 +1,106 @@ +paginate($this->BlockchainTypes); + + $this->set(compact('blockchainTypes')); + } + + /** + * View method + * + * @param string|null $id Blockchain Type id. + * @return \Cake\Http\Response|null + * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + */ + public function view($id = null) + { + $blockchainType = $this->BlockchainTypes->get($id, [ + 'contain' => [], + ]); + + $this->set('blockchainType', $blockchainType); + } + + /** + * Add method + * + * @return \Cake\Http\Response|null Redirects on successful add, renders view otherwise. + */ + public function add() + { + $blockchainType = $this->BlockchainTypes->newEntity(); + if ($this->request->is('post')) { + $blockchainType = $this->BlockchainTypes->patchEntity($blockchainType, $this->request->getData()); + if ($this->BlockchainTypes->save($blockchainType)) { + $this->Flash->success(__('The blockchain type has been saved.')); + + return $this->redirect(['action' => 'index']); + } + $this->Flash->error(__('The blockchain type could not be saved. Please, try again.')); + } + $this->set(compact('blockchainType')); + } + + /** + * Edit method + * + * @param string|null $id Blockchain Type id. + * @return \Cake\Http\Response|null Redirects on successful edit, renders view otherwise. + * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + */ + public function edit($id = null) + { + $blockchainType = $this->BlockchainTypes->get($id, [ + 'contain' => [], + ]); + if ($this->request->is(['patch', 'post', 'put'])) { + $blockchainType = $this->BlockchainTypes->patchEntity($blockchainType, $this->request->getData()); + if ($this->BlockchainTypes->save($blockchainType)) { + $this->Flash->success(__('The blockchain type has been saved.')); + + return $this->redirect(['action' => 'index']); + } + $this->Flash->error(__('The blockchain type could not be saved. Please, try again.')); + } + $this->set(compact('blockchainType')); + } + + /** + * Delete method + * + * @param string|null $id Blockchain Type id. + * @return \Cake\Http\Response|null Redirects to index. + * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + */ + public function delete($id = null) + { + $this->request->allowMethod(['post', 'delete']); + $blockchainType = $this->BlockchainTypes->get($id); + if ($this->BlockchainTypes->delete($blockchainType)) { + $this->Flash->success(__('The blockchain type has been deleted.')); + } else { + $this->Flash->error(__('The blockchain type could not be deleted. Please, try again.')); + } + + return $this->redirect(['action' => 'index']); + } +} diff --git a/community_server/src/Model/Entity/BlockchainType.php b/community_server/src/Model/Entity/BlockchainType.php new file mode 100644 index 000000000..c2e21402c --- /dev/null +++ b/community_server/src/Model/Entity/BlockchainType.php @@ -0,0 +1,30 @@ + true, + 'text' => true, + 'symbol' => true, + ]; +} diff --git a/community_server/src/Model/Entity/Transaction.php b/community_server/src/Model/Entity/Transaction.php index d4ebf68c4..209b8997e 100644 --- a/community_server/src/Model/Entity/Transaction.php +++ b/community_server/src/Model/Entity/Transaction.php @@ -39,6 +39,7 @@ class Transaction extends Entity 'tx_hash' => true, 'memo' => true, 'received' => true, + 'blockchain_type_id' => true, 'state_group' => true, 'transaction_type' => true, 'state_created' => true, diff --git a/community_server/src/Model/Table/BlockchainTypesTable.php b/community_server/src/Model/Table/BlockchainTypesTable.php new file mode 100644 index 000000000..90213ac9f --- /dev/null +++ b/community_server/src/Model/Table/BlockchainTypesTable.php @@ -0,0 +1,68 @@ +setTable('blockchain_types'); + $this->setDisplayField('name'); + $this->setPrimaryKey('id'); + } + + /** + * Default validation rules. + * + * @param \Cake\Validation\Validator $validator Validator instance. + * @return \Cake\Validation\Validator + */ + public function validationDefault(Validator $validator) + { + $validator + ->nonNegativeInteger('id') + ->allowEmptyString('id', null, 'create'); + + $validator + ->scalar('name') + ->maxLength('name', 45) + ->requirePresence('name', 'create') + ->notEmptyString('name'); + + $validator + ->scalar('text') + ->maxLength('text', 255) + ->allowEmptyString('text'); + + $validator + ->scalar('symbol') + ->maxLength('symbol', 10) + ->allowEmptyString('symbol'); + + return $validator; + } +} diff --git a/community_server/src/Model/Table/TransactionsTable.php b/community_server/src/Model/Table/TransactionsTable.php index 6777070fe..198feda73 100644 --- a/community_server/src/Model/Table/TransactionsTable.php +++ b/community_server/src/Model/Table/TransactionsTable.php @@ -52,6 +52,10 @@ class TransactionsTable extends Table 'foreignKey' => 'transaction_type_id', 'joinType' => 'INNER' ]); + $this->belongsTo('BlockchainTypes', [ + 'foreignKey' => 'blockchain_type_id', + 'joinType' => 'INNER' + ]); $this->hasMany('StateCreated', [ 'foreignKey' => 'transaction_id' ]); @@ -114,6 +118,7 @@ class TransactionsTable extends Table { $rules->add($rules->existsIn(['state_group_id'], 'StateGroups')); $rules->add($rules->existsIn(['transaction_type_id'], 'TransactionTypes')); + $rules->add($rules->existsIn(['blockchain_type_id'], 'BlockchainTypes')); return $rules; } diff --git a/community_server/src/Template/BlockchainTypes/add.ctp b/community_server/src/Template/BlockchainTypes/add.ctp new file mode 100644 index 000000000..bef6b70c5 --- /dev/null +++ b/community_server/src/Template/BlockchainTypes/add.ctp @@ -0,0 +1,25 @@ + + +
| = $this->Paginator->sort('id') ?> | += $this->Paginator->sort('name') ?> | += $this->Paginator->sort('text') ?> | += $this->Paginator->sort('symbol') ?> | += __('Actions') ?> | +
|---|---|---|---|---|
| = $this->Number->format($blockchainType->id) ?> | += h($blockchainType->name) ?> | += h($blockchainType->text) ?> | += h($blockchainType->symbol) ?> | ++ = $this->Html->link(__('View'), ['action' => 'view', $blockchainType->id]) ?> + = $this->Html->link(__('Edit'), ['action' => 'edit', $blockchainType->id]) ?> + = $this->Form->postLink(__('Delete'), ['action' => 'delete', $blockchainType->id], ['confirm' => __('Are you sure you want to delete # {0}?', $blockchainType->id)]) ?> + | +
= $this->Paginator->counter(['format' => __('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total')]) ?>
+| = __('Name') ?> | += h($blockchainType->name) ?> | +
|---|---|
| = __('Text') ?> | += h($blockchainType->text) ?> | +
| = __('Symbol') ?> | += h($blockchainType->symbol) ?> | +
| = __('Id') ?> | += $this->Number->format($blockchainType->id) ?> | +