mirror of https://github.com/kcal-app/kcal.git
Add initial "Journal entry" model
This commit is contained in:
parent
2dd92c8d3a
commit
1ec4439d8e
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\JournalEntry;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class JournalEntryController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\JournalEntry $journalEntry
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(JournalEntry $journalEntry)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\JournalEntry $journalEntry
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(JournalEntry $journalEntry)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\JournalEntry $journalEntry
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, JournalEntry $journalEntry)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\JournalEntry $journalEntry
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(JournalEntry $journalEntry)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class JournalEntry extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected $fillable = [
|
||||
'date',
|
||||
'servings',
|
||||
'amount',
|
||||
'unit',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*/
|
||||
protected $casts = [
|
||||
'date' => 'datetime:Y-m-d',
|
||||
'amount' => 'float',
|
||||
];
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected $with = ['recipe', 'food', 'user'];
|
||||
|
||||
/**
|
||||
* Get the Recipe this entry belongs to.
|
||||
*/
|
||||
public function recipe(): BelongsTo {
|
||||
return $this->belongsTo(Recipe::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Food this entry belongs to.
|
||||
*/
|
||||
public function food(): BelongsTo {
|
||||
return $this->belongsTo(Food::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the User this entry belongs to.
|
||||
*/
|
||||
public function user(): BelongsTo {
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
}
|
|
@ -7,6 +7,11 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
/**
|
||||
* @property int id
|
||||
* @property string name
|
||||
* @property string email
|
||||
*/
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasFactory, Notifiable;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "prndb/prndb",
|
||||
"name": "pfnj/pfnj",
|
||||
"type": "project",
|
||||
"description": "Personal Recipe Nutrition Database.",
|
||||
"description": "Personal Food Nutrition Journal",
|
||||
"license": "MPL-2.0",
|
||||
"require": {
|
||||
"php": "^8.0",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "575e9ac06a56887ec419fd5e0ab117f0",
|
||||
"content-hash": "a07b94622d4341202658fd3193b35210",
|
||||
"packages": [
|
||||
{
|
||||
"name": "asm89/stack-cors",
|
||||
|
@ -484,16 +484,16 @@
|
|||
},
|
||||
{
|
||||
"name": "egulias/email-validator",
|
||||
"version": "2.1.24",
|
||||
"version": "2.1.25",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/egulias/EmailValidator.git",
|
||||
"reference": "ca90a3291eee1538cd48ff25163240695bd95448"
|
||||
"reference": "0dbf5d78455d4d6a41d186da50adc1122ec066f4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/egulias/EmailValidator/zipball/ca90a3291eee1538cd48ff25163240695bd95448",
|
||||
"reference": "ca90a3291eee1538cd48ff25163240695bd95448",
|
||||
"url": "https://api.github.com/repos/egulias/EmailValidator/zipball/0dbf5d78455d4d6a41d186da50adc1122ec066f4",
|
||||
"reference": "0dbf5d78455d4d6a41d186da50adc1122ec066f4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -540,7 +540,7 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/egulias/EmailValidator/issues",
|
||||
"source": "https://github.com/egulias/EmailValidator/tree/2.1.24"
|
||||
"source": "https://github.com/egulias/EmailValidator/tree/2.1.25"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -548,7 +548,7 @@
|
|||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2020-11-14T15:56:27+00:00"
|
||||
"time": "2020-12-29T14:50:06+00:00"
|
||||
},
|
||||
{
|
||||
"name": "fideloper/proxy",
|
||||
|
@ -5411,16 +5411,16 @@
|
|||
},
|
||||
{
|
||||
"name": "facade/ignition",
|
||||
"version": "2.5.3",
|
||||
"version": "2.5.8",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/facade/ignition.git",
|
||||
"reference": "d8dc4f90ed469f9f9313b976fb078c20585d5c99"
|
||||
"reference": "8e907d81244649c5ea746e2ec30c32c5f59df472"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/facade/ignition/zipball/d8dc4f90ed469f9f9313b976fb078c20585d5c99",
|
||||
"reference": "d8dc4f90ed469f9f9313b976fb078c20585d5c99",
|
||||
"url": "https://api.github.com/repos/facade/ignition/zipball/8e907d81244649c5ea746e2ec30c32c5f59df472",
|
||||
"reference": "8e907d81244649c5ea746e2ec30c32c5f59df472",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -5484,7 +5484,7 @@
|
|||
"issues": "https://github.com/facade/ignition/issues",
|
||||
"source": "https://github.com/facade/ignition"
|
||||
},
|
||||
"time": "2020-12-09T20:25:45+00:00"
|
||||
"time": "2020-12-29T09:12:55+00:00"
|
||||
},
|
||||
{
|
||||
"name": "facade/ignition-contracts",
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\JournalEntry;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class JournalEntryFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = JournalEntry::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Food;
|
||||
use App\Models\Recipe;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateJournalEntriesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('journal_entries', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignIdFor(User::class);
|
||||
$table->foreignIdFor(Food::class)->nullable();
|
||||
$table->foreignIdFor(Recipe::class)->nullable();
|
||||
$table->date('date')->useCurrent();
|
||||
$table->unsignedFloat('amount');
|
||||
$table->enum('unit', ['tsp', 'tbsp', 'cup', 'grams', 'serving'])->nullable();
|
||||
$table->enum('meal', ['breakfast', 'lunch', 'dinner', 'snacks']);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('journal_entries');
|
||||
}
|
||||
}
|
|
@ -11,7 +11,9 @@ class DatabaseSeeder extends Seeder
|
|||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->call(UserSeeder::class);
|
||||
$this->call(FoodSeeder::class);
|
||||
$this->call(RecipeSeeder::class);
|
||||
$this->call(JournalEntrySeeder::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,6 +74,16 @@ class FoodSeeder extends Seeder
|
|||
'fat' => 100,
|
||||
'cup_weight' => 224,
|
||||
],
|
||||
[
|
||||
'name' => 'peanut butter',
|
||||
'detail' => 'Kirkland organic creamy',
|
||||
'calories' => 562.5,
|
||||
'fat' => 46.875,
|
||||
'sodium' => 0.203125,
|
||||
'carbohydrates' => 21.875,
|
||||
'protein' => 25,
|
||||
'cup_weight' => 256,
|
||||
],
|
||||
];
|
||||
Food::factory()->createMany($default_foods);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Food;
|
||||
use App\Models\JournalEntry;
|
||||
use App\Models\Recipe;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class JournalEntrySeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::all()->first;
|
||||
$default_entries = [
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'food_id' => Food::where('name', 'milk')->first()->id,
|
||||
'date' => Carbon::now()->toDateString(),
|
||||
'amount' => 2,
|
||||
'unit' => 'cup',
|
||||
'meal' => 'breakfast',
|
||||
],
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'food_id' => Food::where('name', 'egg')->first()->id,
|
||||
'date' => Carbon::now()->toDateString(),
|
||||
'amount' => 3,
|
||||
'meal' => 'breakfast',
|
||||
],
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'recipe_id' => Recipe::all()->first(),
|
||||
'date' => Carbon::now()->toDateString(),
|
||||
'amount' => 1,
|
||||
'unit' => 'serving',
|
||||
'meal' => 'lunch',
|
||||
],
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'recipe_id' => Recipe::all()->first(),
|
||||
'date' => Carbon::now()->toDateString(),
|
||||
'amount' => 1.5,
|
||||
'unit' => 'serving',
|
||||
'meal' => 'dinner',
|
||||
],
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'food_id' => Food::where('name', 'peanut butter')->first()->id,
|
||||
'date' => Carbon::now()->toDateString(),
|
||||
'amount' => 2,
|
||||
'unit' => 'tbsp',
|
||||
'meal' => 'snacks',
|
||||
],
|
||||
];
|
||||
JournalEntry::factory()->createMany($default_entries);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class UserSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
User::factory()->create([
|
||||
'name' => 'Admin',
|
||||
'email' => 'admin@admin.admin',
|
||||
'email_verified_at' => now(),
|
||||
'password' => '$2y$10$Y6AOmxZHpL3ZVCvwhcG1ZOctibIPgOYZyzIuaEqvmaJuZ4Xs.odxu', // Same as email.
|
||||
'remember_token' => Str::random(10),
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue