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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat(project): add controller
  • Loading branch information
fiftin committed Dec 12, 2024
commit c57eb89e60a964f91770e2a0fe6d6ff359de7ba2
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
@@ -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 */;
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,
];
}
}
Loading
Oops, something went wrong.