#23 - wip
This commit is contained in:
40
app/Http/Controllers/VacationDaysController.php
Normal file
40
app/Http/Controllers/VacationDaysController.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Inertia\Response;
|
||||
use Toby\Http\Resources\VacationLimitResource;
|
||||
use Toby\Http\Resources\YearPeriodResource;
|
||||
use Toby\Models\YearPeriod;
|
||||
|
||||
class VacationDaysController extends Controller
|
||||
{
|
||||
public function edit(Request $request): Response
|
||||
{
|
||||
$year = $request->query("year", Carbon::now()->year);
|
||||
|
||||
/** @var YearPeriod $yearPeriod */
|
||||
$yearPeriod = YearPeriod::query()->where("year", $year)->firstOrFail();
|
||||
$previousYearPeriod = YearPeriod::query()->where("year", $year - 1)->first();
|
||||
$nextYearPeriod = YearPeriod::query()->where("year", $year + 1)->first();
|
||||
|
||||
|
||||
return inertia("VacationDays", [
|
||||
"vacationLimits" => VacationLimitResource::collection($yearPeriod->vacationLimits()->with("user")->get()),
|
||||
"yearPeriods" => [
|
||||
"prev" => $previousYearPeriod ? new YearPeriodResource($previousYearPeriod) : null,
|
||||
"current" => new YearPeriodResource($yearPeriod),
|
||||
"next" => $nextYearPeriod ? new YearPeriodResource($nextYearPeriod) : null,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
dump($request->get("items"));
|
||||
}
|
||||
}
|
@@ -8,7 +8,7 @@ use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class UserResource extends JsonResource
|
||||
{
|
||||
public static $wrap = false;
|
||||
public static $wrap = null;
|
||||
|
||||
public function toArray($request): array
|
||||
{
|
||||
|
21
app/Http/Resources/VacationLimitResource.php
Normal file
21
app/Http/Resources/VacationLimitResource.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class VacationLimitResource extends JsonResource
|
||||
{
|
||||
public static $wrap = null;
|
||||
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
"user" => new UserResource($this->user),
|
||||
"hasVacation" => $this->has_vacation,
|
||||
"days" => $this->days,
|
||||
];
|
||||
}
|
||||
}
|
20
app/Http/Resources/YearPeriodResource.php
Normal file
20
app/Http/Resources/YearPeriodResource.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class YearPeriodResource extends JsonResource
|
||||
{
|
||||
public static $wrap = false;
|
||||
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
"id" => $this->id,
|
||||
"year" => $this->year,
|
||||
];
|
||||
}
|
||||
}
|
35
app/Models/VacationLimit.php
Normal file
35
app/Models/VacationLimit.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Models;
|
||||
|
||||
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 bool $has_vacation
|
||||
* @property int $days
|
||||
*/
|
||||
class VacationLimit extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $casts = [
|
||||
"has_vacation" => "boolean",
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function yearPeriod(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(YearPeriod::class);
|
||||
}
|
||||
}
|
@@ -7,10 +7,13 @@ namespace Toby\Models;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $year
|
||||
* @property Collection $vacationLimits
|
||||
*/
|
||||
class YearPeriod extends Model
|
||||
{
|
||||
@@ -27,4 +30,9 @@ class YearPeriod extends Model
|
||||
|
||||
return $year;
|
||||
}
|
||||
|
||||
public function vacationLimits(): HasMany
|
||||
{
|
||||
return $this->hasMany(VacationLimit::class);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user