Skip to content

Commit 33449e2

Browse files
committed
feat: add api for add, delete and list apps
1 parent 2fb57c1 commit 33449e2

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

Model/InformationModel.php

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class InformationModel implements InformationInterface
2727
protected $startup;
2828
protected $collectionFactory;
2929
protected $appsFactory;
30+
protected $date;
3031

3132
public function __construct(
3233
Context $context,
@@ -36,7 +37,6 @@ public function __construct(
3637
\Magento\Framework\Webapi\Rest\Request $request,
3738
\Magento\Framework\Filesystem\Driver\File $driver,
3839
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productFactory,
39-
// \Vuefront\Vuefront\Model\ResourceModel\Apps\Collection $appsFactory,
4040
\Vuefront\Vuefront\Model\Api\System\Startup $startup,
4141
\Magento\Store\Model\StoreManagerInterface $storeManager,
4242
\Magento\Framework\Module\Manager $moduleManager,
@@ -48,7 +48,8 @@ public function __construct(
4848
\Zend\Validator\File\Exists $zendFileExists,
4949
\Magento\Framework\Filesystem\Io\File $file,
5050
\Magento\Framework\Archive\Tar $arhiveTar,
51-
\Vuefront\Vuefront\Model\AppsFactory $appsFactory
51+
\Vuefront\Vuefront\Model\AppsFactory $appsFactory,
52+
\Magento\Framework\Stdlib\DateTime\DateTime $date
5253
) {
5354
$this->scopeConfig = $scopeConfig;
5455
$this->context = $context;
@@ -70,6 +71,7 @@ public function __construct(
7071
$this->file = $file;
7172
$this->zendHttp = $zendHttp;
7273
$this->arhiveTar = $arhiveTar;
74+
$this->date = $date;
7375
}
7476

7577
public function checkCors()
@@ -342,14 +344,43 @@ public function vfApps() {
342344
$apps = $this->appsFactory->create();
343345
$collection = $apps->getCollection();
344346

347+
$result = [];
348+
345349
foreach ($collection as $key => $value) {
346-
var_dump($value->getData());
350+
$data = $value->getData();
351+
$result[] = [
352+
'codename' => $data['codename'],
353+
'jwt' => $data['jwt'],
354+
'date_added' => $data['date_added']
355+
];
347356
}
348357

358+
return $result;
359+
}
360+
361+
public function vfAppsCreate($post) {
362+
$app = $this->appsFactory->create();
363+
$app->setCodename($post['codename']);
364+
$app->setJwt($post['jwt']);
365+
$app->setDateAdded($this->date->gmtDate());
366+
$app->save();
349367
return [];
350368
}
351369

352-
public function vfAppsCreate() {
370+
public function vfAppsRemove($post) {
371+
$app = $this->appsFactory->create()->getCollection();
372+
$app->addFieldToSelect('*');
373+
$app->setCurPage($post['key'] + 1);
374+
$app->setPageSize(1);
375+
376+
$result = $app->load();
377+
378+
foreach ($result->getItems() as $key => $value) {
379+
var_dump($value->getAppId());
380+
$model = $this->appsFactory->create();
381+
$model->load($value->getAppId());
382+
$model->delete();
383+
}
353384
return [];
354385
}
355386

@@ -363,7 +394,10 @@ public function info()
363394
$result = $this->vfApps();
364395
break;
365396
case 'vf_apps_create':
366-
$result = $this->vfAppsCreate();
397+
$result = $this->vfAppsCreate($this->request->getBodyParams());
398+
break;
399+
case 'vf_apps_remove':
400+
$result = $this->vfAppsRemove($this->request->getBodyParams());
367401
break;
368402
case 'vf_information':
369403
$result = $this->vfInformation();

Setup/InstallSchema.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
3737
'64k',
3838
['nullable' => true],
3939
'APP Jwt'
40+
)->addColumn(
41+
'date_added',
42+
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
43+
255,
44+
['nullable' => true],
45+
'App Date Added'
4046
)->setComment(
4147
'Vuefront APP Table'
4248
);

0 commit comments

Comments
 (0)