Skip to content

Commit

Permalink
feat(project): add controller
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftin committed Dec 12, 2024
1 parent bbf5bab commit c57eb89
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 2 deletions.
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();

}
}
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();
}
}
2 changes: 0 additions & 2 deletions server/data/db_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 */;
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,
];
}
}

0 comments on commit c57eb89

Please sign in to comment.