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:
38
app/Eloquent/Models/Holiday.php
Normal file
38
app/Eloquent/Models/Holiday.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Eloquent\Models;
|
||||
|
||||
use Database\Factories\HolidayFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property Carbon $date
|
||||
* @property YearPeriod $yearPeriod
|
||||
*/
|
||||
class Holiday extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
"date" => "date",
|
||||
];
|
||||
|
||||
public function yearPeriod(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(YearPeriod::class);
|
||||
}
|
||||
|
||||
protected static function newFactory(): HolidayFactory
|
||||
{
|
||||
return HolidayFactory::new();
|
||||
}
|
||||
}
|
92
app/Eloquent/Models/User.php
Normal file
92
app/Eloquent/Models/User.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Eloquent\Models;
|
||||
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Toby\Domain\Enums\EmploymentForm;
|
||||
use Toby\Domain\Enums\Role;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $first_name
|
||||
* @property string $last_name
|
||||
* @property string $email
|
||||
* @property string $avatar
|
||||
* @property Role $role
|
||||
* @property EmploymentForm $employment_form
|
||||
* @property Carbon $employment_date
|
||||
* @property Collection $vacationLimits
|
||||
* @property Collection $vacationRequests
|
||||
*/
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasFactory;
|
||||
use Notifiable;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
"role" => Role::class,
|
||||
"employment_form" => EmploymentForm::class,
|
||||
"employment_date" => "date",
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
"remember_token",
|
||||
];
|
||||
|
||||
public function vacationLimits(): HasMany
|
||||
{
|
||||
return $this->hasMany(VacationLimit::class);
|
||||
}
|
||||
|
||||
public function vacationRequests(): HasMany
|
||||
{
|
||||
return $this->hasMany(VacationRequest::class);
|
||||
}
|
||||
|
||||
public function scopeSearch(Builder $query, ?string $text): Builder
|
||||
{
|
||||
if ($text === null) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
return $query
|
||||
->where("first_name", "LIKE", "%{$text}%")
|
||||
->orWhere("last_name", "LIKE", "%{$text}%")
|
||||
->orWhere("email", "LIKE", "%{$text}%");
|
||||
}
|
||||
|
||||
public function saveAvatar(string $path): void
|
||||
{
|
||||
$this->avatar = $path;
|
||||
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function getFullNameAttribute(): string
|
||||
{
|
||||
return "{$this->first_name} {$this->last_name}";
|
||||
}
|
||||
|
||||
public function hasRole(Role $role): bool
|
||||
{
|
||||
return $this->role === $role;
|
||||
}
|
||||
|
||||
protected static function newFactory(): UserFactory
|
||||
{
|
||||
return UserFactory::new();
|
||||
}
|
||||
}
|
51
app/Eloquent/Models/VacationLimit.php
Normal file
51
app/Eloquent/Models/VacationLimit.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Eloquent\Models;
|
||||
|
||||
use Database\Factories\VacationLimitFactory;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property User $user
|
||||
* @property YearPeriod $yearPeriod
|
||||
* @property int $days
|
||||
*/
|
||||
class VacationLimit extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public function hasVacation(): bool
|
||||
{
|
||||
return $this->days !== null;
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function yearPeriod(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(YearPeriod::class);
|
||||
}
|
||||
|
||||
public function scopeOrderByUserField(Builder $query, string $field): Builder
|
||||
{
|
||||
$userQuery = User::query()->select($field)->whereColumn("vacation_limits.user_id", "users.id");
|
||||
|
||||
return $query->orderBy($userQuery);
|
||||
}
|
||||
|
||||
protected static function newFactory(): VacationLimitFactory
|
||||
{
|
||||
return VacationLimitFactory::new();
|
||||
}
|
||||
}
|
61
app/Eloquent/Models/VacationRequest.php
Normal file
61
app/Eloquent/Models/VacationRequest.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Eloquent\Models;
|
||||
|
||||
use Database\Factories\VacationRequestFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Toby\Domain\Enums\VacationRequestState;
|
||||
use Toby\Domain\Enums\VacationType;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property VacationType $type
|
||||
* @property VacationRequestState $state
|
||||
* @property Carbon $from
|
||||
* @property Carbon $to
|
||||
* @property string $comment
|
||||
* @property User $user
|
||||
* @property Collection $activities
|
||||
*/
|
||||
class VacationRequest extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
"type" => VacationType::class,
|
||||
"state" => VacationRequestState::class,
|
||||
"from" => "date",
|
||||
"to" => "date",
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function activities(): HasMany
|
||||
{
|
||||
return $this->hasMany(VacationRequestActivity::class);
|
||||
}
|
||||
|
||||
public function changeStateTo(VacationRequestState $state): void
|
||||
{
|
||||
$this->state = $state;
|
||||
|
||||
$this->save();
|
||||
}
|
||||
|
||||
protected static function newFactory(): VacationRequestFactory
|
||||
{
|
||||
return VacationRequestFactory::new();
|
||||
}
|
||||
}
|
36
app/Eloquent/Models/VacationRequestActivity.php
Normal file
36
app/Eloquent/Models/VacationRequestActivity.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Eloquent\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Toby\Domain\Enums\VacationRequestState;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property VacationRequest $vacationRequest
|
||||
* @property ?User $user
|
||||
* @property ?VacationRequestState $from
|
||||
* @property VacationRequestState $to
|
||||
*/
|
||||
class VacationRequestActivity extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
"from" => VacationRequestState::class,
|
||||
"to" => VacationRequestState::class,
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function vacationRequest(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(VacationRequest::class);
|
||||
}
|
||||
}
|
53
app/Eloquent/Models/YearPeriod.php
Normal file
53
app/Eloquent/Models/YearPeriod.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Eloquent\Models;
|
||||
|
||||
use Database\Factories\YearPeriodFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $year
|
||||
* @property Collection $vacationLimits
|
||||
* @property Collection $holidays
|
||||
*/
|
||||
class YearPeriod extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public static function current(): ?static
|
||||
{
|
||||
return static::findByYear(Carbon::now()->year);
|
||||
}
|
||||
|
||||
public static function findByYear(int $year): ?static
|
||||
{
|
||||
/** @var YearPeriod $year */
|
||||
$year = static::query()->where("year", $year)->first();
|
||||
|
||||
return $year;
|
||||
}
|
||||
|
||||
public function vacationLimits(): HasMany
|
||||
{
|
||||
return $this->hasMany(VacationLimit::class);
|
||||
}
|
||||
|
||||
public function holidays(): HasMany
|
||||
{
|
||||
return $this->hasMany(Holiday::class);
|
||||
}
|
||||
|
||||
protected static function newFactory(): YearPeriodFactory
|
||||
{
|
||||
return YearPeriodFactory::new();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user