add to interview url

This commit is contained in:
andrey 2021-07-03 15:15:54 +03:00
parent 88503fd075
commit d3b75d04ad
4 changed files with 136 additions and 1 deletions

View File

@ -0,0 +1,56 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "interview_request".
*
* @property int $id
* @property string $email
* @property string $phone
* @property int $profile_id
* @property int $user_id
* @property int $created_at
* @property string $comment
*/
class InterviewRequest extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'interview_request';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['email'], 'required'],
[['profile_id', 'user_id', 'created_at'], 'integer'],
[['email', 'phone'], 'string', 'max' => 255],
[['comment'], 'string'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'email' => 'Email',
'phone' => 'Phone',
'profile_id' => 'Profile ID',
'user_id' => 'User ID',
'created_at' => 'Created At',
'comment' => 'Комментарий',
];
}
}

View File

@ -0,0 +1,33 @@
<?php
use yii\db\Migration;
/**
* Handles the creation of table `{{%interview_request}}`.
*/
class m210703_114553_create_interview_request_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->createTable('{{%interview_request}}', [
'id' => $this->primaryKey(),
'email' => $this->string(255)->notNull(),
'phone' => $this->string(255),
'profile_id' => $this->integer(11),
'user_id' => $this->integer(11),
'comment' => $this->text(),
'created_at' => $this->integer(11),
]);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropTable('{{%interview_request}}');
}
}

View File

@ -4,6 +4,7 @@ namespace frontend\modules\api\controllers;
use common\behaviors\GsCors;
use common\classes\Debug;
use common\models\InterviewRequest;
use frontend\modules\api\models\ProfileSearchForm;
class ProfileController extends \yii\rest\Controller
@ -39,11 +40,25 @@ class ProfileController extends \yii\rest\Controller
$searchModel = new ProfileSearchForm();
$searchModel->attributes = \Yii::$app->request->get();
if ($id){
if ($id) {
return $searchModel->byId();
}
return $searchModel->byParams();
}
public function actionAddToInterview()
{
if (\Yii::$app->request->isPost) {
$model = new InterviewRequest();
$model->attributes = \Yii::$app->request->post();
$model->created_at = time();
if ($model->save()){
return ['status' => 'success'];
}
return ['status' => 'error'];
}
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace frontend\modules\api\models;
use yii\base\Model;
/**
* Class AddToInterviewForm
* @property string $email;
* @property string $phone;
* @property integer $profile_id;
* @package frontend\modules\api\models
*/
class AddToInterviewForm extends Model
{
public $email;
public $phone;
public $profile_id;
public function rules()
{
return [
[['email', 'phone'], 'string'],
[['profile_id'], 'integer'],
[['skills'], 'checkIsArray'],
];
}
}