Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions server/controllers/system/add-project.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
use Respect\Validation\Validator as DataValidator;

DataValidator::with('CustomValidations', true);
/**
* @api {post} /system/add-project Add project
* @apiVersion 4.11.0
*
* @apiName Add project
*
* @apiGroup System
*
* @apiDescription This path create a new project.
*
* @apiPermission staff3
*
* @apiParam {String} name Name of the new project.
*
* @apiUse NO_PERMISSION
*
* @apiSuccess {Object} data Empty object
*
*/

class AddProjectController extends Controller {
const PATH = '/add-project';
const METHOD = 'POST';

public function validations() {
return [
'permission' => '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();

}
}
4 changes: 4 additions & 0 deletions server/controllers/ticket/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class CreateController extends Controller {
private $title;
private $content;
private $departmentId;
private $projectId;
private $language;
private $ticketNumber;
private $email;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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();
Expand All @@ -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,
Expand Down
57 changes: 57 additions & 0 deletions server/controllers/user/add-project.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
use Respect\Validation\Validator as DataValidator;


/**
* @api {post} /ticket/add-tag Add tag
* @apiVersion 4.11.0
*
* @apiName Add tag
*
* @apiGroup Ticket
*
* @apiDescription This path attaches a new tag to a ticket.
*
* @apiPermission staff1
*
* @apiParam {String} userId The number of the ticket which the tag is going to be attached.
* @apiParam {String} projectId The id of the tag to attach.
*
* @apiUse NO_PERMISSION
* @apiUse INVALID_TICKET
* @apiUse INVALID_TAG
* @apiUse TAG_EXISTS
*
* @apiSuccess {Object} data Empty object
*
*/

class AddTagController extends Controller {
const PATH = '/add-project';
const METHOD = 'POST';

public function validations() {
return [
'permission' => '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();
}
}
39 changes: 39 additions & 0 deletions server/data/db_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,43 @@ 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,
`name` varchar(191) COLLATE utf8mb4_unicode_ci 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`
--
Expand Down Expand Up @@ -424,6 +461,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,
Expand All @@ -445,6 +483,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 */;
Expand Down
47 changes: 47 additions & 0 deletions server/models/Project.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
use RedBeanPHP\Facade as RedBean;

/**
* @api {OBJECT} Project Project
* @apiVersion 4.11.0
* @apiGroup Data Structures
* @apiParam {Number} id Id of the project.
* @apiParam {String} name Name of the project.
*/

class Project extends DataStore {
const TABLE = 'project';

public static function getProps() {
return [
'name',
'sharedTicketList',
];
}

public function getDefaultProps() {
return [
];
}

public static function getAllProjectNames() {
$projectsList = RedBean::findAll(Project::TABLE);
$projectsNameList = [];

foreach($projectsList as $project) {
$projectsNameList[] = [
'id' => $project->id,
'name' => $project->name
];
}

return $projectsNameList;
}

public function toArray() {
return [
'id' => $this->id,
'name' => $this->name,
];
}
}
5 changes: 5 additions & 0 deletions server/models/Ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static function getProps() {
'content',
'language',
'department',
'project',
'file',
'date',
'unread',
Expand Down Expand Up @@ -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,
Expand Down
Loading