files, dead line

This commit is contained in:
Kavalar 2023-06-30 18:13:40 +03:00
parent f861f3eea9
commit 567ab20361
7 changed files with 232 additions and 4 deletions

View File

@ -21,6 +21,9 @@ use yii\db\Expression;
*/ */
class FileEntity extends \yii\db\ActiveRecord class FileEntity extends \yii\db\ActiveRecord
{ {
const STATUS_ACTIVE = 1;
const STATUS_DISABLE = 0;
public function behaviors() public function behaviors()
{ {
return [ 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} * {@inheritdoc}
*/ */
@ -76,4 +93,15 @@ class FileEntity extends \yii\db\ActiveRecord
{ {
return $this->hasOne(File::className(), ['id' => 'file_id']); return $this->hasOne(File::className(), ['id' => 'file_id']);
} }
/**
* @return string[]
*/
public static function getStatusList(): array
{
return [
self::STATUS_ACTIVE => "Активен",
self::STATUS_DISABLE => "Не активен",
];
}
} }

View File

@ -22,6 +22,7 @@ use yii\helpers\ArrayHelper;
* @property int $executor_id * @property int $executor_id
* @property int $priority * @property int $priority
* @property string $description * @property string $description
* @property string $dead_line
* *
* @property Project $project * @property Project $project
* @property UserCard $card * @property UserCard $card
@ -61,7 +62,7 @@ class ProjectTask extends ActiveRecord
return [ return [
[['project_id', 'status', 'title', 'description',], 'required'], [['project_id', 'status', 'title', 'description',], 'required'],
[['project_id', 'status', 'column_id', 'user_id', 'executor_id', 'priority'], 'integer'], [['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', 'unique', 'targetAttribute' => ['title', 'project_id'], 'message' => 'Такая задача уже создана'],
[['title'], 'string', 'max' => 255], [['title'], 'string', 'max' => 255],
[['description'], 'string', 'max' => 1500], [['description'], 'string', 'max' => 1500],
@ -89,6 +90,7 @@ class ProjectTask extends ActiveRecord
'column_id' => 'Колонка', 'column_id' => 'Колонка',
'executor_id' => 'Исполнитель', 'executor_id' => 'Исполнитель',
'priority' => 'Приоритет', 'priority' => 'Приоритет',
'dead_line' => 'Срок выполнения задачи',
]; ];
} }
@ -103,6 +105,7 @@ class ProjectTask extends ActiveRecord
'title', 'title',
'created_at', 'created_at',
'updated_at', 'updated_at',
'dead_line',
'description', 'description',
'status', 'status',
'column_id', 'column_id',

View File

@ -0,0 +1,40 @@
<?php
use yii\db\Migration;
/**
* Class m230629_100431_add_dead_line_column_at_project_task_table
*/
class m230629_100431_add_dead_line_column_at_project_task_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->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;
}
*/
}

View File

@ -5,6 +5,7 @@ namespace frontend\modules\api\controllers;
use common\classes\Debug; use common\classes\Debug;
use common\models\File; use common\models\File;
use frontend\modules\api\models\FileEntity; use frontend\modules\api\models\FileEntity;
use frontend\modules\api\models\Timer;
use yii\helpers\FileHelper; use yii\helpers\FileHelper;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\web\ServerErrorHttpException; use yii\web\ServerErrorHttpException;
@ -17,6 +18,8 @@ class FileController extends ApiController
return [ return [
'upload' => ['post'], 'upload' => ['post'],
'attach' => ['post'], 'attach' => ['post'],
'detach' => ['delete'],
'get-by-entity' => ['get'],
]; ];
} }
@ -151,7 +154,7 @@ class FileController extends ApiController
* @throws NotFoundHttpException * @throws NotFoundHttpException
* @throws ServerErrorHttpException * @throws ServerErrorHttpException
*/ */
public function actionAttach() public function actionAttach(): FileEntity
{ {
$request = \Yii::$app->request->post(); $request = \Yii::$app->request->post();
$file = File::findOne($request['file_id']); $file = File::findOne($request['file_id']);
@ -171,4 +174,137 @@ class FileController extends ApiController
return $fileEntity; 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;
}
} }

View File

@ -65,6 +65,11 @@ class TaskController extends ApiController
* description="статус", * description="статус",
* ), * ),
* @OA\Property( * @OA\Property(
* property="dead_line",
* type="string",
* description="Срок выполнения задачи",
* ),
* @OA\Property(
* property="priority", * property="priority",
* type="integer", * type="integer",
* description="Приоритет задачи", * description="Приоритет задачи",
@ -306,6 +311,11 @@ class TaskController extends ApiController
* description="Статус задачи", * description="Статус задачи",
* ), * ),
* @OA\Property( * @OA\Property(
* property="dead_line",
* type="string",
* description="Срок выполнения задачи",
* ),
* @OA\Property(
* property="description", * property="description",
* type="string", * type="string",
* description="Описание запроса", * description="Описание запроса",

View File

@ -15,10 +15,15 @@ namespace frontend\modules\api\models;
* @OA\Property( * @OA\Property(
* property="file_id", * property="file_id",
* type="integer", * type="integer",
* example=232, * example=1,
* description="Идентификатор файла" * description="Идентификатор файла"
* ), * ),
* @OA\Property( * @OA\Property(
* property="file",
* ref="#/components/schemas/FileExample",
* description="Файл"
* ),
* @OA\Property(
* property="entity_type", * property="entity_type",
* type="integer", * type="integer",
* example=2, * example=2,

View File

@ -42,6 +42,12 @@ namespace frontend\modules\api\models;
* description="Пользователь создавший задачу" * description="Пользователь создавший задачу"
* ), * ),
* @OA\Property( * @OA\Property(
* property="dead_line",
* type="string",
* example="2023-04-21 00:44:53",
* description="Срок выполнения задачи"
* ),
* @OA\Property(
* property="executor_id", * property="executor_id",
* type="int", * type="int",
* example="2", * example="2",