Управление проектами
Добавил возможность удаления, создание и редактирование проектов.
This commit is contained in:
@@ -5,6 +5,7 @@ $method = $_SERVER['REQUEST_METHOD'];
|
||||
if ($method === 'POST') {
|
||||
$data = RestApi::getInput();
|
||||
$action = $data['action'] ?? null;
|
||||
$user_id = RestApi::getCurrentUserId();
|
||||
|
||||
// Получение данных проекта (проект + колонки + отделы)
|
||||
if ($action === 'get_project_data') {
|
||||
@@ -17,6 +18,117 @@ if ($method === 'POST') {
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== CRUD ПРОЕКТОВ ====================
|
||||
|
||||
// Создание проекта
|
||||
if ($action === 'create') {
|
||||
$name = trim($data['name'] ?? '');
|
||||
if (!$name) {
|
||||
RestApi::response(['success' => false, 'errors' => ['name' => 'Укажите название проекта']], 400);
|
||||
}
|
||||
$result = Project::create($name, $user_id);
|
||||
RestApi::response($result, $result['success'] ? 200 : 400);
|
||||
}
|
||||
|
||||
// Обновление проекта
|
||||
if ($action === 'update') {
|
||||
$id = $data['id'] ?? null;
|
||||
$name = trim($data['name'] ?? '');
|
||||
if (!$id || !$name) {
|
||||
RestApi::response(['success' => false, 'errors' => ['data' => 'Укажите ID и название']], 400);
|
||||
}
|
||||
$result = Project::update($id, $name, $user_id);
|
||||
RestApi::response($result, $result['success'] ? 200 : 403);
|
||||
}
|
||||
|
||||
// Удаление проекта
|
||||
if ($action === 'delete') {
|
||||
$id = $data['id'] ?? null;
|
||||
if (!$id) {
|
||||
RestApi::response(['success' => false, 'errors' => ['id' => 'Укажите ID проекта']], 400);
|
||||
}
|
||||
$result = Project::delete($id, $user_id);
|
||||
RestApi::response($result, $result['success'] ? 200 : 403);
|
||||
}
|
||||
|
||||
// Обновление порядка проектов
|
||||
if ($action === 'update_order') {
|
||||
$ids = $data['ids'] ?? [];
|
||||
if (empty($ids)) {
|
||||
RestApi::response(['success' => false, 'errors' => ['ids' => 'Укажите массив ID']], 400);
|
||||
}
|
||||
$result = Project::updateOrder($ids, $user_id);
|
||||
RestApi::response($result);
|
||||
}
|
||||
|
||||
// ==================== CRUD КОЛОНОК ====================
|
||||
|
||||
// Добавление колонки
|
||||
if ($action === 'add_column') {
|
||||
$project_id = $data['project_id'] ?? null;
|
||||
$name = trim($data['name'] ?? '');
|
||||
$color = $data['color'] ?? '#6366f1';
|
||||
if (!$project_id || !$name) {
|
||||
RestApi::response(['success' => false, 'errors' => ['data' => 'Укажите project_id и name']], 400);
|
||||
}
|
||||
$result = Project::addColumn($project_id, $name, $color, $user_id);
|
||||
RestApi::response($result, $result['success'] ? 200 : 403);
|
||||
}
|
||||
|
||||
// Обновление колонки
|
||||
if ($action === 'update_column') {
|
||||
$id = $data['id'] ?? null;
|
||||
$name = isset($data['name']) ? trim($data['name']) : null;
|
||||
$color = $data['color'] ?? null;
|
||||
if (!$id) {
|
||||
RestApi::response(['success' => false, 'errors' => ['id' => 'Укажите ID колонки']], 400);
|
||||
}
|
||||
$result = Project::updateColumn($id, $name, $color, $user_id);
|
||||
RestApi::response($result, $result['success'] ? 200 : 403);
|
||||
}
|
||||
|
||||
// Получение количества задач в колонке (для подтверждения удаления)
|
||||
if ($action === 'get_column_tasks_count') {
|
||||
$id = $data['id'] ?? null;
|
||||
if (!$id) {
|
||||
RestApi::response(['success' => false, 'errors' => ['id' => 'Укажите ID колонки']], 400);
|
||||
}
|
||||
$count = Project::getColumnTasksCount($id);
|
||||
RestApi::response(['success' => true, 'count' => $count]);
|
||||
}
|
||||
|
||||
// Удаление колонки
|
||||
if ($action === 'delete_column') {
|
||||
$id = $data['id'] ?? null;
|
||||
if (!$id) {
|
||||
RestApi::response(['success' => false, 'errors' => ['id' => 'Укажите ID колонки']], 400);
|
||||
}
|
||||
$result = Project::deleteColumn($id, $user_id);
|
||||
RestApi::response($result, $result['success'] ? 200 : 403);
|
||||
}
|
||||
|
||||
// Обновление порядка колонок
|
||||
if ($action === 'update_columns_order') {
|
||||
$project_id = $data['project_id'] ?? null;
|
||||
$ids = $data['ids'] ?? [];
|
||||
if (!$project_id || empty($ids)) {
|
||||
RestApi::response(['success' => false, 'errors' => ['data' => 'Укажите project_id и ids']], 400);
|
||||
}
|
||||
$result = Project::updateColumnsOrder($project_id, $ids, $user_id);
|
||||
RestApi::response($result, $result['success'] ? 200 : 403);
|
||||
}
|
||||
|
||||
// Установка финальной колонки
|
||||
if ($action === 'set_ready_column') {
|
||||
$project_id = $data['project_id'] ?? null;
|
||||
$column_id = $data['column_id'] ?? null;
|
||||
if (!$project_id || !$column_id) {
|
||||
RestApi::response(['success' => false, 'errors' => ['data' => 'Укажите project_id и column_id']], 400);
|
||||
}
|
||||
$result = Project::setReadyColumn($project_id, $column_id, $user_id);
|
||||
RestApi::response($result, $result['success'] ? 200 : 403);
|
||||
}
|
||||
|
||||
// Метод не указан
|
||||
if (!$action) {
|
||||
RestApi::response(['success' => false, 'error' => 'Укажите метод'], 400);
|
||||
|
||||
Reference in New Issue
Block a user