Merge branch 'main' into #20-vacation-requests
# Conflicts: # app/Architecture/Providers/ObserverServiceProvider.php # app/Domain/Role.php # app/Domain/Rules/ApprovedVacationDaysInSameRange.php # app/Domain/Rules/DoesNotExceedLimitRule.php # app/Domain/Rules/MinimumOneVacationDayRule.php # app/Domain/Rules/PendingVacationRequestInSameRange.php # app/Domain/Rules/UsedVacationDaysInSameRange.php # app/Domain/Rules/VacationRequestRule.php # app/Domain/VacationRequestState.php # app/Domain/VacationRequestStateManager.php # app/Domain/VacationRequestValidator.php # app/Domain/VacationType.php # app/Domain/VacationTypeConfigRetriever.php # app/Eloquent/Models/User.php # app/Infrastructure/Http/Controllers/UserController.php # app/Infrastructure/Http/Kernel.php # app/Infrastructure/Http/Requests/UserRequest.php # database/factories/UserFactory.php # database/seeders/DatabaseSeeder.php # routes/web.php # tests/Feature/UserTest.php
This commit is contained in:
37
app/Infrastructure/Http/Requests/HolidayRequest.php
Normal file
37
app/Infrastructure/Http/Requests/HolidayRequest.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
use Toby\Infrastructure\Http\Rules\YearPeriodExists;
|
||||
|
||||
class HolidayRequest extends FormRequest
|
||||
{
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
"name" => ["required", "min:3", "max:150"],
|
||||
"date" => ["required",
|
||||
"date_format:Y-m-d",
|
||||
Rule::unique("holidays", "date")->ignore($this->holiday),
|
||||
new YearPeriodExists(),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function data(): array
|
||||
{
|
||||
$date = $this->get("date");
|
||||
|
||||
return [
|
||||
"name" => $this->get("name"),
|
||||
"date" => $date,
|
||||
"year_period_id" => YearPeriod::findByYear(Carbon::create($date)->year)->id,
|
||||
];
|
||||
}
|
||||
}
|
38
app/Infrastructure/Http/Requests/UserRequest.php
Normal file
38
app/Infrastructure/Http/Requests/UserRequest.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
use Toby\Domain\Enums\EmploymentForm;
|
||||
use Toby\Domain\Enums\Role;
|
||||
|
||||
class UserRequest extends FormRequest
|
||||
{
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
"firstName" => ["required", "min:3", "max:80"],
|
||||
"lastName" => ["required", "min:3", "max:80"],
|
||||
"email" => ["required", "email", Rule::unique("users", "email")->ignore($this->user)],
|
||||
"role" => ["required", new Enum(Role::class)],
|
||||
"employmentForm" => ["required", new Enum(EmploymentForm::class)],
|
||||
"employmentDate" => ["required", "date_format:Y-m-d"],
|
||||
];
|
||||
}
|
||||
|
||||
public function data(): array
|
||||
{
|
||||
return [
|
||||
"first_name" => $this->get("firstName"),
|
||||
"last_name" => $this->get("lastName"),
|
||||
"email" => $this->get("email"),
|
||||
"role" => $this->get("role"),
|
||||
"employment_form" => $this->get("employmentForm"),
|
||||
"employment_date" => $this->get("employmentDate"),
|
||||
];
|
||||
}
|
||||
}
|
33
app/Infrastructure/Http/Requests/VacationLimitRequest.php
Normal file
33
app/Infrastructure/Http/Requests/VacationLimitRequest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Collection;
|
||||
use Toby\Eloquent\Models\VacationLimit;
|
||||
|
||||
class VacationLimitRequest extends FormRequest
|
||||
{
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
"items" => ["required", "array"],
|
||||
"items.*.id" => ["required", "exists:vacation_limits,id"],
|
||||
"items.*.days" => ["nullable", "integer", "min:0"],
|
||||
];
|
||||
}
|
||||
|
||||
public function vacationLimits(): Collection
|
||||
{
|
||||
return VacationLimit::query()->find($this->collect("items")->pluck("id"));
|
||||
}
|
||||
|
||||
public function data(): array
|
||||
{
|
||||
return $this->collect("items")
|
||||
->keyBy("id")
|
||||
->toArray();
|
||||
}
|
||||
}
|
33
app/Infrastructure/Http/Requests/VacationRequestRequest.php
Normal file
33
app/Infrastructure/Http/Requests/VacationRequestRequest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
use Toby\Domain\Enums\VacationType;
|
||||
use Toby\Infrastructure\Http\Rules\YearPeriodExists;
|
||||
|
||||
class VacationRequestRequest extends FormRequest
|
||||
{
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
"type" => ["required", new Enum(VacationType::class)],
|
||||
"from" => ["required", "date_format:Y-m-d", new YearPeriodExists()],
|
||||
"to" => ["required", "date_format:Y-m-d", new YearPeriodExists()],
|
||||
"comment" => ["nullable"],
|
||||
];
|
||||
}
|
||||
|
||||
public function data(): array
|
||||
{
|
||||
return [
|
||||
"type" => $this->get("type"),
|
||||
"from" => $this->get("from"),
|
||||
"to" => $this->get("to"),
|
||||
"comment" => $this->get("comment"),
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user