diff --git a/app/Http/Controllers/JournalEntryController.php b/app/Http/Controllers/JournalEntryController.php new file mode 100644 index 0000000..d300131 --- /dev/null +++ b/app/Http/Controllers/JournalEntryController.php @@ -0,0 +1,85 @@ + '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); + } + +} diff --git a/app/Models/User.php b/app/Models/User.php index 3368ec1..a3d6e46 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -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; diff --git a/composer.json b/composer.json index 31565bf..4d1e629 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/composer.lock b/composer.lock index cac44ca..ecaa97d 100644 --- a/composer.lock +++ b/composer.lock @@ -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", diff --git a/database/factories/JournalEntryFactory.php b/database/factories/JournalEntryFactory.php new file mode 100644 index 0000000..8780f26 --- /dev/null +++ b/database/factories/JournalEntryFactory.php @@ -0,0 +1,28 @@ +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'); + } +} diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index e3d088a..8c378cc 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -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); } } diff --git a/database/seeders/FoodSeeder.php b/database/seeders/FoodSeeder.php index b2574d8..cb18705 100644 --- a/database/seeders/FoodSeeder.php +++ b/database/seeders/FoodSeeder.php @@ -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); } diff --git a/database/seeders/JournalEntrySeeder.php b/database/seeders/JournalEntrySeeder.php new file mode 100644 index 0000000..52b76dc --- /dev/null +++ b/database/seeders/JournalEntrySeeder.php @@ -0,0 +1,66 @@ +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); + } +} diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php new file mode 100644 index 0000000..32368f8 --- /dev/null +++ b/database/seeders/UserSeeder.php @@ -0,0 +1,24 @@ +create([ + 'name' => 'Admin', + 'email' => 'admin@admin.admin', + 'email_verified_at' => now(), + 'password' => '$2y$10$Y6AOmxZHpL3ZVCvwhcG1ZOctibIPgOYZyzIuaEqvmaJuZ4Xs.odxu', // Same as email. + 'remember_token' => Str::random(10), + ]); + } +}