-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #354 - wip * #354 - wip * #354 - wip * #354 - fix * #354 - fix * #354 - fix * #354 - fix * #354 - cr fixes * #354 - fix * #354 - fix
- Loading branch information
1 parent
e3dcec1
commit 8019143
Showing
13 changed files
with
510 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Toby\Domain; | ||
|
||
use Illuminate\Support\Carbon; | ||
use Illuminate\Support\Collection; | ||
use Toby\Eloquent\Models\User; | ||
|
||
class EmployeesMilestonesRetriever | ||
{ | ||
public function __construct( | ||
protected VacationTypeConfigRetriever $configRetriever, | ||
) {} | ||
|
||
public function getResults(?string $searchText, ?string $sort): Collection | ||
{ | ||
return match ($sort) { | ||
"birthday-asc" => $this->getUpcomingBirthdays($searchText), | ||
"birthday-desc" => $this->getUpcomingBirthdays($searchText, "desc"), | ||
"seniority-asc" => $this->getSeniority($searchText), | ||
"seniority-desc" => $this->getSeniority($searchText, "desc"), | ||
default => User::query() | ||
->search($searchText) | ||
->orderByProfileField("last_name") | ||
->orderByProfileField("first_name") | ||
->get(), | ||
}; | ||
} | ||
|
||
public function getUpcomingBirthdays(?string $searchText, string $direction = "asc"): Collection | ||
{ | ||
$users = User::query() | ||
->search($searchText) | ||
->get(); | ||
|
||
return $users->sortBy(fn(User $user): int => $user->upcomingBirthday()->diffInDays(Carbon::today()), descending: $direction !== "asc"); | ||
} | ||
|
||
public function getSeniority(?string $searchText, string $direction = "asc"): Collection | ||
{ | ||
return User::query() | ||
->search($searchText) | ||
->orderByProfileField("employment_date", $direction) | ||
->get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
app/Infrastructure/Http/Controllers/EmployeesMilestonesController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Toby\Infrastructure\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use Inertia\Response; | ||
use Toby\Domain\EmployeesMilestonesRetriever; | ||
use Toby\Infrastructure\Http\Resources\EmployeeMilestoneResource; | ||
|
||
class EmployeesMilestonesController extends Controller | ||
{ | ||
public function index(Request $request, EmployeesMilestonesRetriever $employeesMilestoneRetriever): Response | ||
{ | ||
$searchText = $request->query("search"); | ||
$sort = $request->query("sort"); | ||
|
||
$users = $employeesMilestoneRetriever->getResults($searchText, $sort); | ||
|
||
return inertia("EmployeesMilestones", [ | ||
"users" => EmployeeMilestoneResource::collection($users), | ||
"filters" => [ | ||
"search" => $searchText, | ||
"sort" => $sort, | ||
], | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
app/Infrastructure/Http/Resources/EmployeeMilestoneResource.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Toby\Infrastructure\Http\Resources; | ||
|
||
use Carbon\CarbonInterface; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
use Illuminate\Support\Carbon; | ||
|
||
class EmployeeMilestoneResource extends JsonResource | ||
{ | ||
public static $wrap = null; | ||
|
||
public function toArray($request): array | ||
{ | ||
$upcomingBirthday = $this->upcomingBirthday(); | ||
$seniority = $this->seniority(); | ||
$isSeniorityAnniversaryToday = $this->isWorkAnniversaryToday(); | ||
|
||
return [ | ||
"user" => new SimpleUserResource($this->resource), | ||
"birthdayDisplayDate" => $upcomingBirthday?->toDisplayString(), | ||
"birthdayRelativeDate" => $upcomingBirthday?->isToday() | ||
? __("today") | ||
: $upcomingBirthday?->diffForHumans( | ||
Carbon::today(), | ||
["options" => CarbonInterface::ONE_DAY_WORDS, "syntax" => CarbonInterface::DIFF_RELATIVE_TO_NOW], | ||
), | ||
"isBirthdayToday" => (bool)$upcomingBirthday?->isToday(), | ||
"seniorityDisplayDate" => $seniority, | ||
"isWorkAnniversaryToday" => $isSeniorityAnniversaryToday, | ||
"employmentDate" => $this->profile->employment_date->toDisplayString(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.