add project_id and company_id to reports

update doc
This commit is contained in:
iIronside 2023-11-03 12:01:29 +03:00
parent 52f8cb312f
commit ae44789200
7 changed files with 589 additions and 12 deletions

View File

@ -1,9 +1,8 @@
<?php <?php
use kartik\date\DatePicker; use kartik\date\DatePicker;
use kartik\datetime\DateTimePicker;
use Symfony\Component\Console\Input\Input;
use unclead\multipleinput\MultipleInput; use unclead\multipleinput\MultipleInput;
use yii\helpers\ArrayHelper;
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
@ -70,7 +69,17 @@ $this->registerCss('.list-cell__task{width:73%}')
<?= $form->field($model, 'tomorrow')->textarea(['maxlength' => true]) ?> <?= $form->field($model, 'tomorrow')->textarea(['maxlength' => true]) ?>
<?= $form->field($model, 'user_card_id')->dropDownList( <?= $form->field($model, 'user_card_id')->dropDownList(
\yii\helpers\ArrayHelper::map(common\models\UserCard::find()->all(), 'id', 'fio'), ArrayHelper::map(common\models\UserCard::find()->all(), 'id', 'fio'),
['prompt' => '...']
) ?>
<?= $form->field($model, 'project_id')->dropDownList(
ArrayHelper::map(common\models\Project::find()->all(), 'id', 'name'),
['prompt' => '...']
) ?>
<?= $form->field($model, 'company_id')->dropDownList(
ArrayHelper::map(common\models\Company::find()->all(), 'id', 'name'),
['prompt' => '...'] ['prompt' => '...']
) ?> ) ?>

View File

@ -14,6 +14,8 @@ use Yii;
* @property string $difficulties * @property string $difficulties
* @property string $tomorrow * @property string $tomorrow
* @property int $user_card_id * @property int $user_card_id
* @property int $project_id
* @property int $company_id
* @property int $status * @property int $status
* *
* @property UserCard $userCard * @property UserCard $userCard
@ -36,11 +38,13 @@ class Reports extends \yii\db\ActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['user_card_id', 'status'], 'integer'], [['user_card_id', 'status', 'company_id', 'project_id'], 'integer'],
[['_task'], 'checkIsArray'], [['_task'], 'checkIsArray'],
[['user_card_id', 'created_at'], 'required'], [['user_card_id', 'created_at'], 'required'],
[['today', 'difficulties', 'tomorrow', 'created_at'], 'string', 'max' => 255], [['today', 'difficulties', 'tomorrow', 'created_at'], 'string', 'max' => 255],
[['user_card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['user_card_id' => 'id']], [['user_card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::class, 'targetAttribute' => ['user_card_id' => 'id']],
[['project_id'], 'exist', 'skipOnEmpty' => true, 'targetClass' => Project::class, 'targetAttribute' => ['project_id' => 'id']],
[['company_id'], 'exist', 'skipOnEmpty' => true, 'targetClass' => Company::class, 'targetAttribute' => ['company_id' => 'id']],
]; ];
} }
@ -56,7 +60,9 @@ class Reports extends \yii\db\ActiveRecord
'difficulties' => 'Какие сложности возникли?', 'difficulties' => 'Какие сложности возникли?',
'tomorrow' => 'Что планируется сделать завтра?', 'tomorrow' => 'Что планируется сделать завтра?',
'user_card_id' => 'Пользователь', 'user_card_id' => 'Пользователь',
'status' => 'Статус' 'status' => 'Статус',
'project_id' => 'ID проекта',
'company_id' => 'ID компании'
]; ];
} }

View File

@ -0,0 +1,34 @@
<?php
use yii\db\Migration;
/**
* Class m231102_113213_add_column_project_id_reports_table
*/
class m231102_113213_add_column_project_id_reports_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('reports', 'project_id', $this->integer()->defaultValue(null));
$this->addForeignKey(
'reports_project_id',
'reports',
'project_id',
'project',
'id'
);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropForeignKey('reports_project_id', 'reports');
$this->dropColumn('reports', 'project_id');
}
}

View File

@ -0,0 +1,34 @@
<?php
use yii\db\Migration;
/**
* Class m231102_113324_add_column_company_id_reports_table
*/
class m231102_113324_add_column_company_id_reports_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('reports', 'company_id', $this->integer()->defaultValue(null));
$this->addForeignKey(
'reports_company_id',
'reports',
'company_id',
'project',
'id'
);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropForeignKey('reports_company_id', 'reports');
$this->dropColumn('reports', 'company_id');
}
}

View File

@ -14,7 +14,57 @@ use yii\web\NotFoundHttpException;
class ReportsController extends ApiController class ReportsController extends ApiController
{ {
public function actionIndex($user_card_id) /**
* @OA\Get(path="/user-response/index",
* summary="Поиск отчётов по промежутку дат",
* description="Осуществляет поиск отчётов пользователя по промежутку дат",
* security={
* {"bearerAuth": {}}
* },
* tags={"Reports"},
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="application/x-www-form-urlencoded",
* @OA\Schema(
* required={"user_card_id"},
* @OA\Property(
* property="user_card_id",
* type="integer",
* description="Идентификатор карты(профиля) пользователя",
* nullable=false,
* ),
* @OA\Property(
* property="fromDate",
* type="DateTime",
* description="Дата начала поиска",
* nullable=false,
* ),
* @OA\Property(
* property="toDate",
* type="DateTime",
* description="Дата конца периода поиска",
* nullable=false,
* ),
* ),
* ),
* ),
*
* @OA\Response(
* response=200,
* description="Возвращает объект Запроса",
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(ref="#/components/schemas/ReportsResponseExample"),
* ),
* ),
*
*
* )
*
* @param $user_card_id
* @return array
*/
public function actionIndex($user_card_id): array
{ {
$reportsModel = new ReportSearchForm(); $reportsModel = new ReportSearchForm();
@ -32,9 +82,51 @@ class ReportsController extends ApiController
} }
/** /**
* @OA\Get(path="/user-response/find-by-date",
* summary="Поиск отчётов по дате",
* description="Осуществляет поиск отчётов пользователя по дате",
* security={
* {"bearerAuth": {}}
* },
* tags={"Reports"},
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="application/x-www-form-urlencoded",
* @OA\Schema(
* required={"user_card_id"},
* @OA\Property(
* property="user_card_id",
* type="integer",
* description="Идентификатор карты(профиля) пользователя",
* nullable=false,
* ),
* @OA\Property(
* property="date",
* type="DateTime",
* description="Дата поиска",
* nullable=false,
* ),
* ),
* ),
* ),
*
* @OA\Response(
* response=200,
* description="Возвращает объект Запроса",
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(ref="#/components/schemas/ReportsResponseExample"),
* ),
* ),
*
*
* )
*
* @return array
* @throws BadRequestHttpException
* @throws NotFoundHttpException * @throws NotFoundHttpException
*/ */
public function actionFindByDate()//: array public function actionFindByDate(): array
{ {
$reportsModel = new ReportSearchForm(); $reportsModel = new ReportSearchForm();
@ -57,7 +149,118 @@ class ReportsController extends ApiController
return $reportsModel->findByDate(); return $reportsModel->findByDate();
} }
public function actionCreate() /**
* @OA\Post(path="/reports/create",
* summary="Создание отчёта",
* description="Метод для создания нового отчёта",
* security={
* {"bearerAuth": {}}
* },
* tags={"Reports"},
* @OA\Parameter(
* name="difficulties",
* in="query",
* required=false,
* description="Описание сложностей возникших при выполнении задач",
* @OA\Schema(
* type="string",
* )
* ),
* @OA\Parameter(
* name="tomorrow",
* in="query",
* required=false,
* description="Описание планов на завтра",
* @OA\Schema(
* type="string",
* )
* ),
* @OA\Parameter(
* name="created_at",
* in="query",
* required=false,
* description="Дата создания",
* @OA\Schema(
* type="string",
* )
* ),
* @OA\Parameter(
* name="status",
* in="query",
* required=false,
* description="Статус",
* @OA\Schema(
* type="integer",
* )
* ),
* @OA\Parameter(
* name="user_card_id",
* in="query",
* required=false,
* description="ID карты(профиля) пользователя",
* @OA\Schema(
* type="integer",
* )
* ),
* @OA\Parameter(
* name="project_id",
* in="query",
* required=false,
* description="ID проекта",
* @OA\Schema(
* type="integer",
* )
* ),
* @OA\Parameter(
* name="company_id",
* in="query",
* required=false,
* description="ID компании",
* @OA\Schema(
* type="integer",
* )
* ),
* @OA\Parameter(
* name="tasks[]",
* in="query",
* required=false,
* description="Масив задач. ",
* @OA\Schema(
* type="array",
* @OA\Items(
* type="object",
* @OA\Property(
* property="task",
* description="Название задачи",
* type="string",
* ),
* @OA\Property(
* property="hours_spent",
* description="Затраченное количество часов",
* type="string",
* ),
* @OA\Property(
* property="minutes_spent",
* description="Затраченное количество минут",
* type="string",
* )
* )
* )
* ),
* @OA\Response(
* response=200,
* description="Возвращает объект Запроса",
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(ref="#/components/schemas/ReportsResponseCreateExample"),
* ),
* ),
* )
*
* @return array
* @throws BadRequestHttpException
*/
public function actionCreate(): array
{ {
$params = Yii::$app->request->post(); $params = Yii::$app->request->post();
if (!isset($params['tasks'])){ if (!isset($params['tasks'])){
@ -93,6 +296,41 @@ class ReportsController extends ApiController
return array_merge($reportsModel->toArray()); return array_merge($reportsModel->toArray());
} }
/**
* @OA\Get(path="/user-response/delete",
* summary="Удаление отчёта",
* description="Осуществляет удаление отчёта",
* security={
* {"bearerAuth": {}}
* },
* tags={"Reports"},
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="application/x-www-form-urlencoded",
* @OA\Schema(
* required={"id"},
* @OA\Property(
* property="id",
* type="integer",
* description="Идентификатор отчётая",
* nullable=false,
* ),
* ),
* ),
* ),
*
* @OA\Response(
* response=200,
* description="Возвращает true в случае успеха",
* ),
* )
*
* @return bool
* @throws NotFoundHttpException
* @throws \Throwable
* @throws \yii\db\StaleObjectException
*/
public function actionDelete() public function actionDelete()
{ {
$id = Yii::$app->request->get('id'); $id = Yii::$app->request->get('id');
@ -110,6 +348,82 @@ class ReportsController extends ApiController
return true; return true;
} }
/**
* @OA\Get(path="/reports/update",
* summary="Обновление отчёта",
* description="Метод для Обновления отчёта",
* security={
* {"bearerAuth": {}}
* },
* tags={"Reports"},
* @OA\Parameter(
* name="id",
* in="query",
* required=true,
* description="ID отчёта",
* @OA\Schema(
* type="integer",
* )
* ),
* @OA\Parameter(
* name="created_at",
* in="query",
* required=false,
* description="Дата создания (yyyy-mm-dd)",
* @OA\Schema(
* type="DateTime",
* )
* ),
* @OA\Parameter(
* name="today",
* in="query",
* required=false,
* description="Сделанное сегодня",
* @OA\Schema(
* type="string",
* )
* ),
* @OA\Parameter(
* name="difficulties",
* in="query",
* required=false,
* description="Описание сложностей возникших при выполнении задач",
* @OA\Schema(
* type="string",
* )
* ),
* @OA\Parameter(
* name="tomorrow",
* in="query",
* required=false,
* description="Описание планов на завтра",
* @OA\Schema(
* type="string",
* )
* ),
* @OA\Parameter(
* name="status",
* in="query",
* required=false,
* description="Статус",
* @OA\Schema(
* type="integer",
* )
* ),
* @OA\Response(
* response=200,
* description="Возвращает объект Запроса",
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(ref="#/components/schemas/ReportsResponseCreateExample"),
* ),
* ),
* )
*
* @return array
* @throws BadRequestHttpException
* @throws NotFoundHttpException
*/
public function actionUpdate(): array public function actionUpdate(): array
{ {
$params = Yii::$app->request->get(); $params = Yii::$app->request->get();
@ -135,9 +449,13 @@ class ReportsController extends ApiController
} }
/** /**
* @throws NotFoundHttpException * @param $fromDate
* @param $toDate
* @param $user_card_id
* @return array|array[]|object|object[]|string[]
* @throws BadRequestHttpException
*/ */
public function actionReportsByDate($fromDate, $toDate, $user_card_id) public function actionCheckReportsByDate($fromDate, $toDate, $user_card_id)
{ {
if (!$this->checkDate($fromDate) || !$this->checkDate($toDate)) { if (!$this->checkDate($fromDate) || !$this->checkDate($toDate)) {
throw new BadRequestHttpException('Wrong date format'); throw new BadRequestHttpException('Wrong date format');
@ -170,5 +488,4 @@ class ReportsController extends ApiController
} }
return true; return true;
} }
} }

View File

@ -153,6 +153,51 @@ namespace frontend\modules\api\models;
* type="string", * type="string",
* example="/profileava/m8.png" * example="/profileava/m8.png"
* ), * ),
*)
*
* @OA\Schema(
* schema="ProjectTaskReportsExample",
* type="array",
* @OA\Items(
* @OA\Property(
* property="id",
* type="integer",
* example=1
* ),
* @OA\Property(
* property="report_id",
* type="integer",
* example=12
* ),
* @OA\Property(
* property="task",
* type="string",
* example="Задача"
* ),
* @OA\Property(
* property="hours_spent",
* type="integer",
* example=2
* ),
* @OA\Property(
* property="created_at",
* type="integer",
* example=1671148800
* ),
* @OA\Property(
* property="status",
* type="integer",
* example=1
* ),
* @OA\Property(
* property="minutes_spent",
* type="integer",
* example=0
* ),
* )
*
*
*) *)
* *
*/ */

View File

@ -0,0 +1,132 @@
<?php
namespace frontend\modules\api\models;
/**
* @OA\Schema(
* schema="Reports",
* @OA\Property(
* property="difficulties",
* type="string",
* description="Описание сложностей возникших при выполнении задач"
* ),
* @OA\Property(
* property="tomorrow",
* type="string",
* description="Описание планов на завтра"
* ),
*
* @OA\Property(
* property="created_at",
* type="datetime",
* example="2023-04-07 02:09:42",
* description="Дата создания"
* ),
* @OA\Property(
* property="status",
* type="integer",
* example="1",
* description="Статус"
* ),
* @OA\Property(
* property="user_card_id",
* type="integer",
* example=19,
* description="ID карты(профиля) пользователя"
* ),
* @OA\Property(
* property="project_id",
* type="integer",
* example=1,
* description="ID проекта"
* ),
* @OA\Property(
* property="company_id",
* type="integer",
* example=1,
* description="ID компании",
* ),
*)
*
*
* @OA\Schema(
* schema="ReportsResponseCreateExample",
* type="array",
* @OA\Items(
* type="object",
* @OA\Property(
* property="difficulties",
* type="string",
* ),
* @OA\Property(
* property="tomorrow",
* type="string",
* ),
* @OA\Property(
* property="created_at",
* type="datetime",
* ),
* @OA\Property(
* property="status",
* type="integer",
* ),
* @OA\Property(
* property="user_card_id",
* type="integer",
* ),
* @OA\Property(
* property="project_id",
* type="integer",
* ),
* @OA\Property(
* property="company_id",
* type="integer",
* ),
* ),
*)
*
* @OA\Schema(
* schema="ReportsResponseExample",
* type="array",
* @OA\Items(
* type="object",
* @OA\Property(
* property="difficulties",
* type="string",
* ),
* @OA\Property(
* property="tomorrow",
* type="string",
* ),
* @OA\Property(
* property="created_at",
* type="datetime",
* ),
* @OA\Property(
* property="status",
* type="integer",
* ),
* @OA\Property(
* property="user_card_id",
* type="integer",
* ),
* @OA\Property(
* property="project_id",
* type="integer",
* ),
* @OA\Property(
* property="company_id",
* type="integer",
* ),
* @OA\Property(
* property="task",
* ref="#/components/schemas/ProjectTaskReportsExample",
* ),
* ),
*)
*
*/
class Reports extends \common\models\Reports
{
}