From 492f27084fef0204bc6b1a814a7c238a47005253 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 7 Jan 2023 19:00:32 +0100 Subject: [PATCH] l11n, unit/app and simplification fixes --- Admin/Install/db.json | 6 ++++ Controller/ApiController.php | 70 +++++++++++++++++++++++++++++++++++- Models/App.php | 9 +++++ Models/AppMapper.php | 1 + 4 files changed, 85 insertions(+), 1 deletion(-) diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 9c79b23..ceb61b2 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -520,6 +520,7 @@ "app_name": { "name": "app_name", "type": "VARCHAR(50)", + "unique": true, "null": false }, "app_theme": { @@ -531,6 +532,11 @@ "name": "app_status", "type": "TINYINT", "null": false + }, + "app_type": { + "name": "app_type", + "type": "TINYINT", + "null": false } } }, diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 32b95a0..4d2591d 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -33,6 +33,9 @@ use Modules\Admin\Models\SettingsEnum; use Modules\Media\Models\Collection; use Modules\Media\Models\CollectionMapper; use Modules\Media\Models\UploadFile; +use Modules\Admin\Models\App; +use phpOMS\Application\ApplicationType; +use Modules\Admin\Models\AppMapper; use phpOMS\Account\AccountStatus; use phpOMS\Account\AccountType; use phpOMS\Account\GroupStatus; @@ -677,6 +680,71 @@ final class ApiController extends Controller $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Design', 'Design successfully updated', []); } + /** + * Api method to install a application + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiApplicationCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void + { + if (!empty($val = $this->validateApplicationCreate($request))) { + $response->set('application_create', new FormValidation($val)); + $response->header->status = RequestStatusCode::R_400; + + return; + } + + $app = $this->createApplicationFromRequest($request); + + $this->createModel($request->header->account, $app, AppMapper::class, 'application', $request->getOrigin()); + $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Application', 'Application successfully created', $app); + } + + /** + * Validate app create request + * + * @param RequestAbstract $request Request + * + * @return array + * + * @since 1.0.0 + */ + private function validateApplicationCreate(RequestAbstract $request) : array + { + $val = []; + if (($val['name'] = empty($request->getData('name')))) { + return $val; + } + + return []; + } + + /** + * Method to create task from request. + * + * @param RequestAbstract $request Request + * + * @return App Returns the created application from the request + * + * @since 1.0.0 + */ + private function createApplicationFromRequest(RequestAbstract $request) : App + { + $app = new App(); + $app->name = (string) ($request->getData('name') ?? ''); + $app->type = (int) ($request->getData('type') ?? ApplicationType::WEB); + + return $app; + } + /** * Api method to install a application * @@ -1339,8 +1407,8 @@ final class ApiController extends Controller $iRequest = new HttpRequest(new HttpUri('')); $iRequest->header->account = 1; $iRequest->setData('status', ModuleStatusUpdateType::INSTALL); - $iRequest->setData('module', $key); + $this->apiModuleStatusUpdate($iRequest, $iResponse); } diff --git a/Models/App.php b/Models/App.php index 9f4fab4..ca094ba 100755 --- a/Models/App.php +++ b/Models/App.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Modules\Admin\Models; use phpOMS\Application\ApplicationStatus; +use phpOMS\Application\ApplicationType; /** * App model. @@ -58,6 +59,14 @@ class App */ public int $status = ApplicationStatus::NORMAL; + /** + * Status + * + * @var int + * @since 1.0.0 + */ + public int $type = ApplicationType::WEB; + /** * Get id * diff --git a/Models/AppMapper.php b/Models/AppMapper.php index 434e4a8..80c2bb1 100755 --- a/Models/AppMapper.php +++ b/Models/AppMapper.php @@ -37,6 +37,7 @@ final class AppMapper extends DataMapperFactory 'app_name' => ['name' => 'app_name', 'type' => 'string', 'internal' => 'name'], 'app_theme' => ['name' => 'app_theme', 'type' => 'string', 'internal' => 'theme'], 'app_status' => ['name' => 'app_status', 'type' => 'int', 'internal' => 'status'], + 'app_type' => ['name' => 'app_type', 'type' => 'int', 'internal' => 'type'], ]; /**