Merge branch 'main' into directory-refactor

# Conflicts:
#	app/Architecture/Providers/AppServiceProvider.php
#	app/Eloquent/Observers/YearPeriodObserver.php
This commit is contained in:
Adrian Hopek
2022-01-26 08:58:57 +01:00
33 changed files with 979 additions and 55 deletions

View File

@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Toby\Eloquent\Models\Holiday;
use Toby\Eloquent\Models\YearPeriod;
class HolidayFactory extends Factory
{
protected $model = Holiday::class;
public function definition(): array
{
return [
"name" => $this->faker->word,
"date" => $this->faker->unique->date,
"year_period_id" => YearPeriod::current()->id,
];
}
}

View File

@@ -5,11 +5,15 @@ declare(strict_types=1);
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use Toby\Enums\EmploymentForm;
use Toby\Domain\EmploymentForm;
use Toby\Eloquent\Models\User;
class UserFactory extends Factory
{
protected $model = User::class;
public function definition(): array
{
return [
@@ -17,7 +21,7 @@ class UserFactory extends Factory
"last_name" => $this->faker->lastName(),
"email" => $this->faker->unique()->safeEmail(),
"employment_form" => $this->faker->randomElement(EmploymentForm::cases()),
"employment_date" => $this->faker->dateTimeBetween("2020-10-27"),
"employment_date" => Carbon::createFromInterface($this->faker->dateTimeBetween("2020-10-27"))->toDateString(),
"remember_token" => Str::random(10),
];
}

View File

@@ -5,11 +5,14 @@ declare(strict_types=1);
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Toby\Models\User;
use Toby\Models\YearPeriod;
use Toby\Eloquent\Models\User;
use Toby\Eloquent\Models\VacationLimit;
use Toby\Eloquent\Models\YearPeriod;
class VacationLimitFactory extends Factory
{
protected $model = VacationLimit::class;
public function definition(): array
{
$hasVacation = $this->faker->boolean(75);

View File

@@ -5,13 +5,16 @@ declare(strict_types=1);
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Toby\Eloquent\Models\YearPeriod;
class YearPeriodFactory extends Factory
{
protected $model = YearPeriod::class;
public function definition(): array
{
return [
"year" => $this->faker->unique()->year,
"year" => (int)$this->faker->unique()->year,
];
}
}

View File

@@ -16,7 +16,7 @@ return new class() extends Migration {
$table->string("email")->unique();
$table->string("avatar")->nullable();
$table->string("employment_form");
$table->dateTime("employment_date");
$table->date("employment_date");
$table->rememberToken();
$table->softDeletes();
$table->timestamps();

View File

@@ -5,8 +5,8 @@ declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Toby\Models\User;
use Toby\Models\YearPeriod;
use Toby\Eloquent\Models\User;
use Toby\Eloquent\Models\YearPeriod;
return new class() extends Migration {
public function up(): void

View File

@@ -5,23 +5,22 @@ declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Toby\Eloquent\Models\YearPeriod;
return new class() extends Migration {
public function up(): void
{
Schema::create("personal_access_tokens", function (Blueprint $table): void {
Schema::create("holidays", function (Blueprint $table): void {
$table->id();
$table->morphs("tokenable");
$table->foreignIdFor(YearPeriod::class)->constrained()->cascadeOnDelete();
$table->string("name");
$table->string("token", 64)->unique();
$table->text("abilities")->nullable();
$table->timestamp("last_used_at")->nullable();
$table->date("date")->unique();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists("personal_access_tokens");
Schema::dropIfExists("holidays");
}
};

View File

@@ -7,10 +7,11 @@ namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Toby\Helpers\UserAvatarGenerator;
use Toby\Models\User;
use Toby\Models\VacationLimit;
use Toby\Models\YearPeriod;
use Toby\Domain\PolishHolidaysRetriever;
use Toby\Eloquent\Helpers\UserAvatarGenerator;
use Toby\Eloquent\Models\User;
use Toby\Eloquent\Models\VacationLimit;
use Toby\Eloquent\Models\YearPeriod;
class DatabaseSeeder extends Seeder
{
@@ -54,6 +55,16 @@ class DatabaseSeeder extends Seeder
->create();
}
})
->afterCreating(function (YearPeriod $yearPeriod): void {
$polishHolidaysRetriever = new PolishHolidaysRetriever();
foreach ($polishHolidaysRetriever->getForYearPeriod($yearPeriod) as $holiday) {
$yearPeriod->holidays()->create([
"name" => $holiday["name"],
"date" => $holiday["date"],
]);
}
})
->create();
}