add api/company/get-personal

This commit is contained in:
iIronside
2023-11-24 16:07:12 +03:00
parent cd9f828f60
commit 932ea915de
11 changed files with 331 additions and 6 deletions

View File

@ -1,6 +1,6 @@
<?php
namespace frontend\modules\api\models;
namespace frontend\modules\api\models\company;
/**
*

View File

@ -0,0 +1,106 @@
<?php
namespace frontend\modules\api\models\company\dto;
/**
*
* @OA\Schema(
* schema="CompanyPersonnelDto",
* @OA\Property(
* property="userId",
* type="int",
* example=95,
* description="Идентификатор пользователя"
* ),
* @OA\Property(
* property="fio",
* type="string",
* example="Кочетков Валерий Александрович",
* description="ФИО пользователя"
* ),
* @OA\Property(
* property="position",
* type="string",
* example="Back end разработчик",
* description="Должность пользователя"
* ),
* @OA\Property(
* property="level",
* type="int",
* example="Middle",
* description="Уровень компетенций"
* ),
* @OA\Property(
* property="projectName",
* type="string",
* example="Проект 1",
* description="Название проекта на котором работает"
* ),
* @OA\Property(
* property="openTaskCount",
* type="int",
* example="5",
* description="Количество открытых задач на проекте"
* ),
* @OA\Property(
* property="hoursWorkedForCurrentMonth",
* type="int",
* example="5",
* description="Количество часов отработанных в текущем месяце"
* ),
*)
*
* @OA\Schema(
* schema="CompanyPersonnelDtoExampleArr",
* type="array",
* example={
* {"userId": 23, "fio": "Кочетков Валерий Александрович", "position": "Back end разработчик", "level": 2, "projectName": "Проект 1", "openTaskCount": 4, "hoursWorkedForCurrentMonth": 30},
* {"userId": 16, "fio": "Шишкина Милана Андреевна", "position": "Back end разработчик", "level": 1, "projectName": "Проект 2", "openTaskCount": 8, "hoursWorkedForCurrentMonth": 15},
* },
* @OA\Items(
* type="object",
* @OA\Property(
* property="userId",
* type="integer",
* ),
* @OA\Property(
* property="fio",
* type="string",
* ),
* @OA\Property(
* property="position",
* type="string",
* ),
* @OA\Property(
* property="level",
* type="integer",
* ),
* @OA\Property(
* property="projectName",
* type="string",
* ),
* @OA\Property(
* property="openTaskCount",
* type="integer",
* ),
* @OA\Property(
* property="hoursWorkedForCurrentMonth",
* type="integer",
* ),
* ),
*)
*
*
*
*/
class CompanyPersonnelDto
{
public $userId;
public $fio;
public $position;
public $level;
public $projectName;
public $openTaskCount;
public $hoursWorkedForCurrentMonth;
}

View File

@ -0,0 +1,30 @@
<?php
namespace frontend\modules\api\models\company\form;
use frontend\modules\api\models\company\Company;
use yii\base\Model;
class CompanyIdForm extends Model
{
public $company_id;
/**
* @return array
*/
public function rules()
{
return [
[['company_id'], 'required'],
[['company_id'], 'exist', 'skipOnError' => false, 'targetClass' => Company::class, 'targetAttribute' => ['company_id' => 'id']],
];
}
/**
* @return string
*/
public function formName(): string
{
return '';
}
}

View File

@ -0,0 +1,41 @@
<?php
namespace frontend\modules\api\models\company\mappers;
use frontend\modules\api\models\company\dto\CompanyPersonnelDto;
use frontend\modules\api\models\project\ProjectUser;
use frontend\modules\api\services\TaskService;
class CompanyPersonnelMapper
{
/**
* @param ProjectUser $projectUser
* @return CompanyPersonnelDto
*/
public static function map(ProjectUser $projectUser): CompanyPersonnelDto
{
$dto = new CompanyPersonnelDto();
$dto->userId = $projectUser->user_id;
$dto->fio = $projectUser->card->fio ?? null;
$dto->position = $projectUser->card->position->name ?? null;
$dto->level = $projectUser->card->level ?? null;
$dto->projectName = $projectUser->project->name;
$dto->openTaskCount = TaskService::getOpenTaskCount($projectUser->user_id, $projectUser->project_id);
$dto->hoursWorkedForCurrentMonth = TaskService::getHoursWorkedForCurrentMonth($projectUser->user_id, $projectUser->project_id);
return $dto;
}
/**
* @param array $projectUsers
* @return array
*/
public static function mapAll(array $projectUsers): array
{
return array_map(function (ProjectUser $projectUser) {
return self::map($projectUser);
}, array_values($projectUsers));
}
}

View File

@ -2,11 +2,10 @@
namespace frontend\modules\api\models\project;
use frontend\modules\api\models\Company;
use frontend\modules\api\models\company\Company;
use yii\db\ActiveQuery;
use yii\helpers\Url;
use yii\web\Link;
use yii\web\Linkable;
/**
*

View File

@ -2,7 +2,7 @@
namespace frontend\modules\api\models\project;
use frontend\modules\api\models\Company;
use frontend\modules\api\models\company\Company;
use yii\db\ActiveQuery;
use yii\helpers\Url;
use yii\web\Link;