refactor: refactor controllers, services, validation and introduce DTOs, FormRequests and domain exceptions

This commit is contained in:
antv
2026-07-09 10:27:47 +07:00
parent 54048bb4ff
commit 326e1f1028
15 changed files with 501 additions and 150 deletions
+41
View File
@@ -0,0 +1,41 @@
<?php
namespace App\DTOs;
use App\Models\User;
use Illuminate\Pagination\LengthAwarePaginator;
class DashboardDataDto
{
public function __construct(
public readonly LengthAwarePaginator $administrations,
public readonly string $selectedMonth,
public readonly User $user,
public readonly array $receivedRankers,
public readonly ?object $receivedCurrentUserRankItem,
public readonly array $sentRankers,
public readonly ?object $sentCurrentUserRankItem,
public readonly int $receivedCount,
public readonly int $sentCount,
public readonly int $currentRank
) {}
/**
* Convert the DTO to an associative array for view rendering.
*/
public function toArray(): array
{
return [
'administrations' => $this->administrations,
'selectedMonth' => $this->selectedMonth,
'user' => $this->user,
'receivedRankers' => $this->receivedRankers,
'receivedCurrentUserRankItem' => $this->receivedCurrentUserRankItem,
'sentRankers' => $this->sentRankers,
'sentCurrentUserRankItem' => $this->sentCurrentUserRankItem,
'receivedCount' => $this->receivedCount,
'sentCount' => $this->sentCount,
'currentRank' => $this->currentRank,
];
}
}
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace App\DTOs;
use Carbon\Carbon;
use Illuminate\Http\Request;
class UserFilterDto
{
public function __construct(
public readonly string $selectedMonth,
public readonly ?string $search = null,
public readonly ?string $status = '1',
public readonly ?string $role = null,
public readonly ?string $department = null,
public readonly ?string $flagSend = null
) {}
/**
* Create a DTO instance from an HTTP Request.
*/
public static function fromRequest(Request $request): self
{
return new self(
selectedMonth: (string) $request->input('month', Carbon::now()->format('Y-m')),
search: $request->input('search'),
status: $request->has('status') ? (string) $request->input('status') : '1',
role: $request->input('role'),
department: $request->input('department'),
flagSend: $request->input('flag_send')
);
}
}