From f7b4941b5cf4458a5c575c6068255e774cde586f Mon Sep 17 00:00:00 2001 From: Denis Gukov Date: Thu, 12 Dec 2024 14:16:32 +0500 Subject: [PATCH 1/5] feat: add project table --- server/data/db_schema.sql | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/server/data/db_schema.sql b/server/data/db_schema.sql index cae4b7a8..acd0f11d 100644 --- a/server/data/db_schema.sql +++ b/server/data/db_schema.sql @@ -141,6 +141,45 @@ CREATE TABLE `customresponse` ( ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; + + +-- +-- Table structure for table `project` +-- + +DROP TABLE IF EXISTS `project`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `project` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `owners` int(11) unsigned DEFAULT NULL, + `name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `private` int(11) unsigned DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `project_user` +-- + +DROP TABLE IF EXISTS `project_user`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `project_user` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `project_id` int(11) unsigned DEFAULT NULL, + `user_id` int(11) unsigned DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `UQ_npfgplw1pmx11q8ysjh8t8i5i2r7qk0vdl80wgbq` (`project_id`,`user_id`), + KEY `index_foreignkey_project_user_project` (`project_id`), + KEY `index_foreignkey_project_user_user` (`user_id`), + CONSTRAINT `c_fk_project_user_project_id` FOREIGN KEY (`project_id`) REFERENCES `project` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `c_fk_project_user_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + + -- -- Table structure for table `department` -- From 2e9bf27b429753ebf457db71b57ee51dd1241175 Mon Sep 17 00:00:00 2001 From: Denis Gukov Date: Thu, 12 Dec 2024 14:18:32 +0500 Subject: [PATCH 2/5] feat(db): tiket -> project relation --- server/data/db_schema.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/data/db_schema.sql b/server/data/db_schema.sql index acd0f11d..421e17c4 100644 --- a/server/data/db_schema.sql +++ b/server/data/db_schema.sql @@ -463,6 +463,7 @@ CREATE TABLE `ticket` ( `author_email` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `author_name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `department_id` int(11) unsigned DEFAULT NULL, + `project_id` int(11) unsigned DEFAULT NULL, `author` tinyint(1) unsigned DEFAULT NULL, `author_id` int(11) unsigned DEFAULT NULL, `author_staff` tinyint(1) unsigned DEFAULT NULL, @@ -484,6 +485,7 @@ CREATE TABLE `ticket` ( CONSTRAINT `c_fk_ticket_author_id` FOREIGN KEY (`author_id`) REFERENCES `user` (`id`) ON DELETE SET NULL ON UPDATE SET NULL, CONSTRAINT `c_fk_ticket_author_staff_id` FOREIGN KEY (`author_staff_id`) REFERENCES `staff` (`id`) ON DELETE SET NULL ON UPDATE SET NULL, CONSTRAINT `c_fk_ticket_department_id` FOREIGN KEY (`department_id`) REFERENCES `department` (`id`) ON DELETE SET NULL ON UPDATE SET NULL, + CONSTRAINT `c_fk_ticket_project_id` FOREIGN KEY (`project_id`) REFERENCES `project` (`id`) ON DELETE SET NULL ON UPDATE SET NULL, CONSTRAINT `c_fk_ticket_owner_id` FOREIGN KEY (`owner_id`) REFERENCES `staff` (`id`) ON DELETE SET NULL ON UPDATE SET NULL ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; From bbf5bab8532ff2d4eeae9fae64563d1728f47947 Mon Sep 17 00:00:00 2001 From: Denis Gukov Date: Thu, 12 Dec 2024 14:24:43 +0500 Subject: [PATCH 3/5] feat(project): store project id for tiket --- server/controllers/ticket/create.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/controllers/ticket/create.php b/server/controllers/ticket/create.php index ebe751ac..69d17e7d 100755 --- a/server/controllers/ticket/create.php +++ b/server/controllers/ticket/create.php @@ -46,6 +46,7 @@ class CreateController extends Controller { private $title; private $content; private $departmentId; + private $projectId; private $language; private $ticketNumber; private $email; @@ -102,6 +103,7 @@ public function handler() { $this->title = Controller::request('title', true); $this->content = Controller::request('content', true); $this->departmentId = Controller::request('departmentId'); + $this->projectId = Controller::request('projectId'); $this->language = Controller::request('language'); $this->email = Controller::request('email'); $this->name = Controller::request('name'); @@ -173,6 +175,7 @@ private function createNewUser() { } private function storeTicket() { + $project = Department::getDataStore($this->projectId); $department = Department::getDataStore($this->getCorrectDepartmentId()); $author = $this->getAuthor(); $this->language = $this->getCorrectLanguage(); @@ -190,6 +193,7 @@ private function storeTicket() { 'content' => $this->replaceWithImagePaths($imagePaths, $this->content), 'language' => $this->language, 'department' => $department, + 'project' => $project, 'file' => ($fileUploader instanceof FileUploader) ? $fileUploader->getFileName() : null, 'date' => Date::getCurrentDate(), 'unread' => false, From c57eb89e60a964f91770e2a0fe6d6ff359de7ba2 Mon Sep 17 00:00:00 2001 From: Denis Gukov Date: Thu, 12 Dec 2024 14:53:41 +0500 Subject: [PATCH 4/5] feat(project): add controller --- server/controllers/system/add-project.php | 59 +++++++++++++++++++++++ server/controllers/user/add-project.php | 57 ++++++++++++++++++++++ server/data/db_schema.sql | 2 - server/models/Project.php | 47 ++++++++++++++++++ 4 files changed, 163 insertions(+), 2 deletions(-) create mode 100644 server/controllers/system/add-project.php create mode 100644 server/controllers/user/add-project.php create mode 100644 server/models/Project.php diff --git a/server/controllers/system/add-project.php b/server/controllers/system/add-project.php new file mode 100644 index 00000000..86a3c491 --- /dev/null +++ b/server/controllers/system/add-project.php @@ -0,0 +1,59 @@ + 'staff_3', + 'requestData' => [ + 'name' => [ + 'validation' => DataValidator::AllOf( + DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), + DataValidator::ValidProjectName() + ), + 'error' => ERRORS::INVALID_NAME + ] + ] + ]; + } + + public function handler() { + $name = Controller::request('name', true); + + $projectInstance = new Project(); + + $projectInstance->setProperties([ + 'name' => $name , + ]); + $projectInstance->store(); + + Log::createLog('ADD_PROJECT', $name); + + Response::respondSuccess(); + + } +} diff --git a/server/controllers/user/add-project.php b/server/controllers/user/add-project.php new file mode 100644 index 00000000..7aacbc14 --- /dev/null +++ b/server/controllers/user/add-project.php @@ -0,0 +1,57 @@ + 'staff_1', + 'requestData' => [ + 'userId' => [ + 'validation' => DataValidator::dataStoreId('user'), + 'error' => ERRORS::INVALID_USER + ], + 'projectId' => [ + 'validation' => DataValidator::dataStoreId('project'), + 'error' => ERRORS::INVALID_USER + ] + ] + ]; + } + + public function handler() { + + $user = User::getDataStore(Controller::request('userId')); + + $project = Project::getDataStore(Controller::request('projectId')); + + Response::respondSuccess(); + } +} diff --git a/server/data/db_schema.sql b/server/data/db_schema.sql index 421e17c4..861c1d95 100644 --- a/server/data/db_schema.sql +++ b/server/data/db_schema.sql @@ -152,9 +152,7 @@ DROP TABLE IF EXISTS `project`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `project` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `owners` int(11) unsigned DEFAULT NULL, `name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `private` int(11) unsigned DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/server/models/Project.php b/server/models/Project.php new file mode 100644 index 00000000..2f2abe54 --- /dev/null +++ b/server/models/Project.php @@ -0,0 +1,47 @@ + $project->id, + 'name' => $project->name + ]; + } + + return $projectsNameList; + } + + public function toArray() { + return [ + 'id' => $this->id, + 'name' => $this->name, + ]; + } +} From f919e9fdbc7f5a33cd5835a0079ac78519dec175 Mon Sep 17 00:00:00 2001 From: Denis Gukov Date: Thu, 12 Dec 2024 15:20:51 +0500 Subject: [PATCH 5/5] feat(project): project info in tiket --- server/models/Ticket.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/models/Ticket.php b/server/models/Ticket.php index 479f6ba0..2f8a72b5 100755 --- a/server/models/Ticket.php +++ b/server/models/Ticket.php @@ -36,6 +36,7 @@ public static function getProps() { 'content', 'language', 'department', + 'project', 'file', 'date', 'unread', @@ -132,6 +133,10 @@ public function toArray($minimized = false) { 'id' => $this->department->id, 'name' => $this->department->name ], + 'project' => $this->project ? [ + 'id' => $this->project->id, + 'name' => $this->project->name + ] : null, 'date' => $this->date, 'file' => $this->file, 'language' => $this->language,