files, dead line
This commit is contained in:
parent
f861f3eea9
commit
567ab20361
@ -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 => "Не активен",
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -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',
|
||||
|
@ -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;
|
||||
}
|
||||
*/
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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="Описание запроса",
|
||||
|
@ -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,
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user