Add date type and context columns to meal
This commit is contained in:
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
* API for registering and login
|
* API for registering and login
|
||||||
* API for fetching meals, summary, and posting meal
|
* API for fetching meals, summary, and posting meal
|
||||||
* JWT tokens for API requests
|
* JWT tokens for API requests
|
||||||
|
* Date, type, and context as columns to the meal
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ use yii\web\UnauthorizedHttpException;
|
|||||||
*
|
*
|
||||||
* @property int $id
|
* @property int $id
|
||||||
* @property string $file_name
|
* @property string $file_name
|
||||||
|
* @property string $context
|
||||||
* @property string $food_name
|
* @property string $food_name
|
||||||
|
* @property string $type
|
||||||
* @property int $calories
|
* @property int $calories
|
||||||
* @property int $protein
|
* @property int $protein
|
||||||
* @property int $fat
|
* @property int $fat
|
||||||
@@ -26,6 +28,10 @@ class Meal extends ActiveRecord
|
|||||||
{
|
{
|
||||||
|
|
||||||
public $base64File;
|
public $base64File;
|
||||||
|
public const BREAKFAST = 'breakfast';
|
||||||
|
public const LUNCH = 'lunch';
|
||||||
|
public const DINNER = 'dinner';
|
||||||
|
public const OTHER = 'other';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -55,8 +61,11 @@ class Meal extends ActiveRecord
|
|||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[['food_name', 'calories', 'protein', 'fat', 'carbohydrates', 'fiber'], 'required'],
|
[['date', 'food_name', 'calories', 'protein', 'fat', 'carbohydrates', 'fiber', 'type'], 'required'],
|
||||||
[['user_id', 'calories', 'protein', 'fat', 'carbohydrates', 'fiber', 'created_at', 'updated_at'], 'integer'],
|
[['user_id', 'calories', 'protein', 'fat', 'carbohydrates', 'fiber', 'created_at', 'updated_at'], 'integer'],
|
||||||
|
[['date'], 'date'],
|
||||||
|
[['type', 'context'], 'string'],
|
||||||
|
[['type'], 'in', 'range' => [self::BREAKFAST, self::LUNCH, self::DINNER, self::OTHER]],
|
||||||
[['file_name'], 'string', 'max' => 255],
|
[['file_name'], 'string', 'max' => 255],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\db\Migration;
|
||||||
|
|
||||||
|
class m250223_111753_add_type_date_context_columns_to_meal extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function safeUp()
|
||||||
|
{
|
||||||
|
$this->addColumn('{{%meal}}', 'type', $this->string()->null()); // nullable because existing user data
|
||||||
|
$this->addColumn('{{%meal}}', 'date', $this->date()->null()); // nullable because existing user data
|
||||||
|
$this->addColumn('{{%meal}}', 'context', $this->string(100)->null());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function safeDown()
|
||||||
|
{
|
||||||
|
$this->dropColumn('{{%meal}}', 'type');
|
||||||
|
$this->dropColumn('{{%meal}}', 'date');
|
||||||
|
$this->dropColumn('{{%meal}}', 'context');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user