Add task and project API formatters

This commit is contained in:
Frederic Guillot
2017-05-22 15:33:16 -04:00
parent f16ac8cd66
commit 54a751820f
14 changed files with 186 additions and 57 deletions

View File

@@ -21,51 +21,6 @@ abstract class BaseProcedure extends Base
UserAuthorization::getInstance($this->container)->check($this->getClassName(), $procedure);
}
protected function formatTask($task)
{
if (! empty($task)) {
$task['url'] = $this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), '', true);
$task['color'] = $this->colorModel->getColorProperties($task['color_id']);
}
return $task;
}
protected function formatTasks($tasks)
{
if (! empty($tasks)) {
foreach ($tasks as &$task) {
$task = $this->formatTask($task);
}
}
return $tasks;
}
protected function formatProject($project)
{
if (! empty($project)) {
$project['url'] = array(
'board' => $this->helper->url->to('BoardViewController', 'show', array('project_id' => $project['id']), '', true),
'calendar' => $this->helper->url->to('CalendarController', 'show', array('project_id' => $project['id']), '', true),
'list' => $this->helper->url->to('TaskListController', 'show', array('project_id' => $project['id']), '', true),
);
}
return $project;
}
protected function formatProjects($projects)
{
if (! empty($projects)) {
foreach ($projects as &$project) {
$project = $this->formatProject($project);
}
}
return $projects;
}
protected function filterValues(array $values)
{
foreach ($values as $key => $value) {

View File

@@ -62,6 +62,6 @@ class MeProcedure extends BaseProcedure
$project_ids = $this->projectPermissionModel->getActiveProjectIds($this->userSession->getId());
$projects = $this->projectModel->getAllByIds($project_ids);
return $this->formatProjects($projects);
return $this->projectsApiFormatter->withProjects($projects)->format();
}
}

View File

@@ -15,33 +15,34 @@ class ProjectProcedure extends BaseProcedure
public function getProjectById($project_id)
{
ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getProjectById', $project_id);
return $this->formatProject($this->projectModel->getById($project_id));
$project = $this->projectModel->getById($project_id);
return $this->projectApiFormatter->withProject($project)->format();
}
public function getProjectByName($name)
{
$project = $this->projectModel->getByName($name);
ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getProjectByName', $project['id']);
return $this->formatProject($project);
return $this->projectApiFormatter->withProject($project)->format();
}
public function getProjectByIdentifier($identifier)
{
$project = $this->formatProject($this->projectModel->getByIdentifier($identifier));
$project = $this->projectModel->getByIdentifier($identifier);
ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getProjectByIdentifier', $project['id']);
return $this->formatProject($project);
return $this->projectApiFormatter->withProject($project)->format();
}
public function getProjectByEmail($email)
{
$project = $this->formatProject($this->projectModel->getByEmail($email));
$project = $this->projectModel->getByEmail($email);
ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getProjectByEmail', $project['id']);
return $this->formatProject($project);
return $this->projectApiFormatter->withProject($project)->format();
}
public function getAllProjects()
{
return $this->formatProjects($this->projectModel->getAll());
return $this->projectsApiFormatter->withProjects($this->projectModel->getAll())->format();
}
public function removeProject($project_id)

View File

@@ -24,19 +24,22 @@ class TaskProcedure extends BaseProcedure
public function getTask($task_id)
{
TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getTask', $task_id);
return $this->formatTask($this->taskFinderModel->getById($task_id));
$task = $this->taskFinderModel->getById($task_id);
return $this->taskApiFormatter->withTask($task)->format();
}
public function getTaskByReference($project_id, $reference)
{
ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getTaskByReference', $project_id);
return $this->formatTask($this->taskFinderModel->getByReference($project_id, $reference));
$task = $this->taskFinderModel->getByReference($project_id, $reference);
return $this->taskApiFormatter->withTask($task)->format();
}
public function getAllTasks($project_id, $status_id = TaskModel::STATUS_OPEN)
{
ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getAllTasks', $project_id);
return $this->formatTasks($this->taskFinderModel->getAll($project_id, $status_id));
$tasks = $this->taskFinderModel->getAll($project_id, $status_id);
return $this->tasksApiFormatter->withTasks($tasks)->format();
}
public function getOverdueTasks()