From 2f27c83411c686b6e2995a30cfabb8e13a3000d0 Mon Sep 17 00:00:00 2001 From: EwelinaLasowy Date: Wed, 13 Apr 2022 11:40:44 +0200 Subject: [PATCH] #118 - wip --- app/Eloquent/Models/Key.php | 37 ++++ .../Http/Controllers/KeysController.php | 23 +++ .../Http/Resources/KeyResource.php | 22 +++ database/factories/KeyFactory.php | 22 +++ .../2022_04_12_152528_create_keys_table.php | 25 +++ database/seeders/DatabaseSeeder.php | 8 + resources/js/Pages/Keys/Index.vue | 162 ++++++++++++++++++ resources/js/Shared/MainMenu.vue | 10 +- routes/web.php | 2 + 9 files changed, 310 insertions(+), 1 deletion(-) create mode 100644 app/Eloquent/Models/Key.php create mode 100644 app/Infrastructure/Http/Controllers/KeysController.php create mode 100644 app/Infrastructure/Http/Resources/KeyResource.php create mode 100644 database/factories/KeyFactory.php create mode 100644 database/migrations/2022_04_12_152528_create_keys_table.php create mode 100644 resources/js/Pages/Keys/Index.vue diff --git a/app/Eloquent/Models/Key.php b/app/Eloquent/Models/Key.php new file mode 100644 index 0000000..5488f19 --- /dev/null +++ b/app/Eloquent/Models/Key.php @@ -0,0 +1,37 @@ +belongsTo(User::class, "owner_id"); + } + + public function previousOwner(): BelongsTo + { + return $this->belongsTo(User::class, "previous_owner_id"); + } + + protected static function newFactory(): KeyFactory + { + return KeyFactory::new(); + } +} diff --git a/app/Infrastructure/Http/Controllers/KeysController.php b/app/Infrastructure/Http/Controllers/KeysController.php new file mode 100644 index 0000000..c7711d0 --- /dev/null +++ b/app/Infrastructure/Http/Controllers/KeysController.php @@ -0,0 +1,23 @@ +get(); + + return inertia("Keys/Index", [ + "keys" => KeyResource::collection($keys), + ]); + } +} diff --git a/app/Infrastructure/Http/Resources/KeyResource.php b/app/Infrastructure/Http/Resources/KeyResource.php new file mode 100644 index 0000000..0b5da33 --- /dev/null +++ b/app/Infrastructure/Http/Resources/KeyResource.php @@ -0,0 +1,22 @@ + $this->id, + "owner" => new UserResource($this->owner), + "previousOwner" => new UserResource($this->previousOwner), + "updatedAt" => $this->updated_at->toDatetimeString(), + ]; + } +} diff --git a/database/factories/KeyFactory.php b/database/factories/KeyFactory.php new file mode 100644 index 0000000..4a3007b --- /dev/null +++ b/database/factories/KeyFactory.php @@ -0,0 +1,22 @@ + User::factory(), + "previous_owner_id" => User::factory(), + ]; + } +} diff --git a/database/migrations/2022_04_12_152528_create_keys_table.php b/database/migrations/2022_04_12_152528_create_keys_table.php new file mode 100644 index 0000000..de8b97f --- /dev/null +++ b/database/migrations/2022_04_12_152528_create_keys_table.php @@ -0,0 +1,25 @@ +id(); + $table->foreignIdFor(User::class, "owner_id")->constrained("users")->cascadeOnDelete(); + $table->foreignIdFor(User::class, "previous_owner_id")->constrained("users")->cascadeOnDelete(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists("keys"); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 581ecfd..5225924 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -8,6 +8,7 @@ use Illuminate\Database\Seeder; use Illuminate\Support\Carbon; use Toby\Domain\PolishHolidaysRetriever; use Toby\Domain\VacationDaysCalculator; +use Toby\Eloquent\Models\Key; use Toby\Eloquent\Models\User; use Toby\Eloquent\Models\VacationLimit; use Toby\Eloquent\Models\VacationRequest; @@ -85,5 +86,12 @@ class DatabaseSeeder extends Seeder }) ->create(); } + + foreach ($users as $user) { + Key::factory() + ->for($user, "owner") + ->for($user, "previousOwner") + ->create(); + } } } diff --git a/resources/js/Pages/Keys/Index.vue b/resources/js/Pages/Keys/Index.vue new file mode 100644 index 0000000..607f5ad --- /dev/null +++ b/resources/js/Pages/Keys/Index.vue @@ -0,0 +1,162 @@ + + +s diff --git a/resources/js/Shared/MainMenu.vue b/resources/js/Shared/MainMenu.vue index 799caec..48e3f33 100644 --- a/resources/js/Shared/MainMenu.vue +++ b/resources/js/Shared/MainMenu.vue @@ -282,6 +282,7 @@ import { CalendarIcon, DocumentTextIcon, AdjustmentsIcon, + KeyIcon, } from '@heroicons/vue/outline' import { CheckIcon, ChevronDownIcon } from '@heroicons/vue/solid' @@ -337,7 +338,6 @@ const navigation = computed(() => can: props.auth.can.manageVacationLimits, }, { - name: 'Podsumowanie roczne', href: '/vacation/annual-summary', component: 'AnnualSummary', @@ -351,5 +351,13 @@ const navigation = computed(() => icon: UserGroupIcon, can: props.auth.can.manageUsers, }, + { + name: 'Klucze', + href: '/keys', + component: 'Keys/Index', + icon: KeyIcon, + can: true, + }, + ].filter(item => item.can)) diff --git a/routes/web.php b/routes/web.php index 7b103b0..a641d59 100644 --- a/routes/web.php +++ b/routes/web.php @@ -7,6 +7,7 @@ use Toby\Infrastructure\Http\Controllers\AnnualSummaryController; use Toby\Infrastructure\Http\Controllers\DashboardController; use Toby\Infrastructure\Http\Controllers\GoogleController; use Toby\Infrastructure\Http\Controllers\HolidayController; +use Toby\Infrastructure\Http\Controllers\KeysController; use Toby\Infrastructure\Http\Controllers\LogoutController; use Toby\Infrastructure\Http\Controllers\MonthlyUsageController; use Toby\Infrastructure\Http\Controllers\SelectYearPeriodController; @@ -28,6 +29,7 @@ Route::middleware("auth")->group(function (): void { Route::resource("holidays", HolidayController::class); Route::post("year-periods/{yearPeriod}/select", SelectYearPeriodController::class) ->name("year-periods.select"); + Route::resource("keys", KeysController::class); Route::prefix("/vacation")->as("vacation.")->group(function (): void { Route::get("/limits", [VacationLimitController::class, "edit"])