From 567ab203612303ac3bf26c08820ba1d447465c71 Mon Sep 17 00:00:00 2001 From: Kavalar Date: Fri, 30 Jun 2023 18:13:40 +0300 Subject: [PATCH] files, dead line --- common/models/FileEntity.php | 28 ++++ common/models/ProjectTask.php | 5 +- ...dead_line_column_at_project_task_table.php | 40 +++++ .../api/controllers/FileController.php | 140 +++++++++++++++++- .../api/controllers/TaskController.php | 10 ++ frontend/modules/api/models/FileEntity.php | 7 +- frontend/modules/api/models/ProjectTask.php | 6 + 7 files changed, 232 insertions(+), 4 deletions(-) create mode 100644 console/migrations/m230629_100431_add_dead_line_column_at_project_task_table.php diff --git a/common/models/FileEntity.php b/common/models/FileEntity.php index a94ed82..9138e28 100644 --- a/common/models/FileEntity.php +++ b/common/models/FileEntity.php @@ -21,6 +21,9 @@ use yii\db\Expression; */ class FileEntity extends \yii\db\ActiveRecord { + const STATUS_ACTIVE = 1; + const STATUS_DISABLE = 0; + public function behaviors() { return [ @@ -33,6 +36,20 @@ class FileEntity extends \yii\db\ActiveRecord ]; } + public function fields(): array + { + return [ + 'id', + 'file_id', + 'file', + 'entity_type', + 'entity_id', + 'created_at', + 'updated_at', + 'status', + ]; + } + /** * {@inheritdoc} */ @@ -76,4 +93,15 @@ class FileEntity extends \yii\db\ActiveRecord { return $this->hasOne(File::className(), ['id' => 'file_id']); } + + /** + * @return string[] + */ + public static function getStatusList(): array + { + return [ + self::STATUS_ACTIVE => "Активен", + self::STATUS_DISABLE => "Не активен", + ]; + } } diff --git a/common/models/ProjectTask.php b/common/models/ProjectTask.php index 2366ecb..e38b0ea 100644 --- a/common/models/ProjectTask.php +++ b/common/models/ProjectTask.php @@ -22,6 +22,7 @@ use yii\helpers\ArrayHelper; * @property int $executor_id * @property int $priority * @property string $description + * @property string $dead_line * * @property Project $project * @property UserCard $card @@ -61,7 +62,7 @@ class ProjectTask extends ActiveRecord return [ [['project_id', 'status', 'title', 'description',], 'required'], [['project_id', 'status', 'column_id', 'user_id', 'executor_id', 'priority'], 'integer'], - [['created_at', 'updated_at'], 'safe'], + [['created_at', 'updated_at', 'dead_line'], 'safe'], ['title', 'unique', 'targetAttribute' => ['title', 'project_id'], 'message' => 'Такая задача уже создана'], [['title'], 'string', 'max' => 255], [['description'], 'string', 'max' => 1500], @@ -89,6 +90,7 @@ class ProjectTask extends ActiveRecord 'column_id' => 'Колонка', 'executor_id' => 'Исполнитель', 'priority' => 'Приоритет', + 'dead_line' => 'Срок выполнения задачи', ]; } @@ -103,6 +105,7 @@ class ProjectTask extends ActiveRecord 'title', 'created_at', 'updated_at', + 'dead_line', 'description', 'status', 'column_id', diff --git a/console/migrations/m230629_100431_add_dead_line_column_at_project_task_table.php b/console/migrations/m230629_100431_add_dead_line_column_at_project_task_table.php new file mode 100644 index 0000000..d985bb0 --- /dev/null +++ b/console/migrations/m230629_100431_add_dead_line_column_at_project_task_table.php @@ -0,0 +1,40 @@ +addColumn('project_task', 'dead_line', $this->dateTime()); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropColumn('project_task', 'dead_line'); + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m230629_100431_add_dead_line_column_at_project_task_table cannot be reverted.\n"; + + return false; + } + */ +} diff --git a/frontend/modules/api/controllers/FileController.php b/frontend/modules/api/controllers/FileController.php index c8f79a5..01051e0 100644 --- a/frontend/modules/api/controllers/FileController.php +++ b/frontend/modules/api/controllers/FileController.php @@ -5,6 +5,7 @@ namespace frontend\modules\api\controllers; use common\classes\Debug; use common\models\File; use frontend\modules\api\models\FileEntity; +use frontend\modules\api\models\Timer; use yii\helpers\FileHelper; use yii\web\NotFoundHttpException; use yii\web\ServerErrorHttpException; @@ -17,6 +18,8 @@ class FileController extends ApiController return [ 'upload' => ['post'], 'attach' => ['post'], + 'detach' => ['delete'], + 'get-by-entity' => ['get'], ]; } @@ -151,7 +154,7 @@ class FileController extends ApiController * @throws NotFoundHttpException * @throws ServerErrorHttpException */ - public function actionAttach() + public function actionAttach(): FileEntity { $request = \Yii::$app->request->post(); $file = File::findOne($request['file_id']); @@ -162,7 +165,7 @@ class FileController extends ApiController $fileEntity = new FileEntity(); $fileEntity->load($request, ''); - if(!$fileEntity->validate()){ + if (!$fileEntity->validate()) { throw new ServerErrorHttpException(json_encode($fileEntity->errors)); } @@ -171,4 +174,137 @@ class FileController extends ApiController return $fileEntity; } + /** + * + * @OA\Delete (path="/file/detach", + * summary="Открепить файл", + * description="Метод для открепления файлов", + * security={ + * {"bearerAuth": {}} + * }, + * tags={"File"}, + * + * @OA\RequestBody( + * @OA\MediaType( + * mediaType="multipart/form-data", + * @OA\Schema( + * required={"file_id", "entity_type", "entity_id"}, + * @OA\Property( + * property="file_id", + * type="intager", + * example=232, + * description="Идентификатор файла", + * ), + * @OA\Property( + * property="entity_type", + * type="intager", + * example=2, + * description="Идентификатор типа сущности", + * ), + * @OA\Property( + * property="entity_id", + * type="intager", + * example=234, + * description="Идентификатор сущности", + * ), + * @OA\Property( + * property="status", + * type="intager", + * example=1, + * description="Статус", + * ), + * ), + * ), + * ), + * @OA\Response( + * response=200, + * description="Возвращает объект прикрепления", + * @OA\MediaType( + * mediaType="application/json", + * @OA\Schema(ref="#/components/schemas/FileEntity"), + * ), + * ), + * ) + * + * @return FileEntity + * @throws NotFoundHttpException + * @throws ServerErrorHttpException + */ + public function actionDetach(): FileEntity + { + $request = \Yii::$app->request->post(); + $file = File::findOne($request['file_id']); + if (!$file) { + throw new NotFoundHttpException('File bot found'); + } + + $fileEntity = new FileEntity(); + $fileEntity->load($request, ''); + $fileEntity->status = FileEntity::STATUS_DISABLE; + + if (!$fileEntity->validate()) { + throw new ServerErrorHttpException(json_encode($fileEntity->errors)); + } + + $fileEntity->save(); + + return $fileEntity; + } + + + /** + * + * @OA\Get(path="/file/get-by-entity", + * summary="Получить файл по идентификатору сущности", + * description="Метод для получения файла по идентификатору сущности.", + * security={ + * {"bearerAuth": {}} + * }, + * tags={"File"}, + * @OA\Parameter( + * name="entity_id", + * in="query", + * required=true, + * @OA\Schema( + * type="integer", + * default=null + * ) + * ), + * + * @OA\Parameter( + * name="entity_type", + * in="query", + * required=true, + * @OA\Schema( + * type="integer", + * default=null + * ) + * ), + * + * @OA\Response( + * response=200, + * description="Возвращает массив объектов Файлов", + * @OA\MediaType( + * mediaType="application/json", + * @OA\Schema(ref="#/components/schemas/FileEntity"), + * ), + * ), + * ) + * + * @param int $entity_type + * @param int $entity_id + * @return array + * @throws NotFoundHttpException + */ + public function actionGetByEntity(int $entity_type, int $entity_id): array + { + $model = FileEntity::find()->where(['entity_type' => $entity_type, 'entity_id' => $entity_id, 'status' => FileEntity::STATUS_ACTIVE])->all(); + + if (!$model) { + throw new NotFoundHttpException('The file not found'); + } + + return $model; + } + } \ No newline at end of file diff --git a/frontend/modules/api/controllers/TaskController.php b/frontend/modules/api/controllers/TaskController.php index 4a74b61..8147870 100644 --- a/frontend/modules/api/controllers/TaskController.php +++ b/frontend/modules/api/controllers/TaskController.php @@ -65,6 +65,11 @@ class TaskController extends ApiController * description="статус", * ), * @OA\Property( + * property="dead_line", + * type="string", + * description="Срок выполнения задачи", + * ), + * @OA\Property( * property="priority", * type="integer", * description="Приоритет задачи", @@ -306,6 +311,11 @@ class TaskController extends ApiController * description="Статус задачи", * ), * @OA\Property( + * property="dead_line", + * type="string", + * description="Срок выполнения задачи", + * ), + * @OA\Property( * property="description", * type="string", * description="Описание запроса", diff --git a/frontend/modules/api/models/FileEntity.php b/frontend/modules/api/models/FileEntity.php index 64a2a05..65b9176 100644 --- a/frontend/modules/api/models/FileEntity.php +++ b/frontend/modules/api/models/FileEntity.php @@ -15,10 +15,15 @@ namespace frontend\modules\api\models; * @OA\Property( * property="file_id", * type="integer", - * example=232, + * example=1, * description="Идентификатор файла" * ), * @OA\Property( + * property="file", + * ref="#/components/schemas/FileExample", + * description="Файл" + * ), + * @OA\Property( * property="entity_type", * type="integer", * example=2, diff --git a/frontend/modules/api/models/ProjectTask.php b/frontend/modules/api/models/ProjectTask.php index 84caf11..78d6de0 100644 --- a/frontend/modules/api/models/ProjectTask.php +++ b/frontend/modules/api/models/ProjectTask.php @@ -42,6 +42,12 @@ namespace frontend\modules\api\models; * description="Пользователь создавший задачу" * ), * @OA\Property( + * property="dead_line", + * type="string", + * example="2023-04-21 00:44:53", + * description="Срок выполнения задачи" + * ), + * @OA\Property( * property="executor_id", * type="int", * example="2",