- directory refactor (#32)
* - directory refactor * - readme.md update * Update readme.md Co-authored-by: Adrian Hopek <adrian.hopek@blumilk.pl> * Update readme.md Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com> * Update readme.md Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com> * Update readme.md Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com> * Update readme.md Co-authored-by: Adrian Hopek <adrian.hopek@blumilk.pl> Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>
This commit is contained in:
25
app/Infrastructure/Console/Commands/CreateUserCommand.php
Normal file
25
app/Infrastructure/Console/Commands/CreateUserCommand.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Toby\Eloquent\Models\User;
|
||||
|
||||
class CreateUserCommand extends Command
|
||||
{
|
||||
protected $signature = "user:create {email : an email for the user}";
|
||||
protected $description = "Creates a user";
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$email = $this->argument("email");
|
||||
|
||||
User::factory([
|
||||
"email" => $email,
|
||||
])->create();
|
||||
|
||||
$this->info("The user has been created");
|
||||
}
|
||||
}
|
20
app/Infrastructure/Console/Kernel.php
Normal file
20
app/Infrastructure/Console/Kernel.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
protected function schedule(Schedule $schedule): void
|
||||
{
|
||||
}
|
||||
|
||||
protected function commands(): void
|
||||
{
|
||||
$this->load(__DIR__ . "/Commands");
|
||||
}
|
||||
}
|
17
app/Infrastructure/Http/Controllers/Controller.php
Normal file
17
app/Infrastructure/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests;
|
||||
use DispatchesJobs;
|
||||
use ValidatesRequests;
|
||||
}
|
41
app/Infrastructure/Http/Controllers/GoogleController.php
Normal file
41
app/Infrastructure/Http/Controllers/GoogleController.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Controllers;
|
||||
|
||||
use Illuminate\Contracts\Auth\Factory as AuthFactory;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Laravel\Socialite\SocialiteManager;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Toby\Eloquent\Models\User;
|
||||
|
||||
class GoogleController extends Controller
|
||||
{
|
||||
public function redirect(SocialiteManager $socialiteManager): RedirectResponse
|
||||
{
|
||||
return $socialiteManager->driver("google")->redirect();
|
||||
}
|
||||
|
||||
public function callback(AuthFactory $auth, SocialiteManager $socialiteManager): RedirectResponse
|
||||
{
|
||||
$socialUser = $socialiteManager->driver("google")->user();
|
||||
|
||||
try {
|
||||
/** @var User $user */
|
||||
$user = User::query()
|
||||
->where("email", $socialUser->getEmail())
|
||||
->firstOrFail();
|
||||
} catch (ModelNotFoundException) {
|
||||
return redirect()
|
||||
->route("login")
|
||||
->withErrors([
|
||||
"oauth" => __("User does not exist."),
|
||||
]);
|
||||
}
|
||||
|
||||
$auth->guard()->login($user, true);
|
||||
|
||||
return redirect()->route("dashboard");
|
||||
}
|
||||
}
|
65
app/Infrastructure/Http/Controllers/HolidayController.php
Normal file
65
app/Infrastructure/Http/Controllers/HolidayController.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Inertia\Response;
|
||||
use Toby\Eloquent\Models\Holiday;
|
||||
use Toby\Infrastructure\Http\Requests\HolidayRequest;
|
||||
use Toby\Infrastructure\Http\Resources\HolidayFormDataResource;
|
||||
use Toby\Infrastructure\Http\Resources\HolidayResource;
|
||||
|
||||
class HolidayController extends Controller
|
||||
{
|
||||
public function index(): Response
|
||||
{
|
||||
$holidays = Holiday::query()
|
||||
->orderBy("date")
|
||||
->get();
|
||||
|
||||
return inertia("Holidays/Index", [
|
||||
"holidays" => HolidayResource::collection($holidays),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(): Response
|
||||
{
|
||||
return inertia("Holidays/Create");
|
||||
}
|
||||
|
||||
public function store(HolidayRequest $request): RedirectResponse
|
||||
{
|
||||
Holiday::query()->create($request->data());
|
||||
|
||||
return redirect()
|
||||
->route("holidays.index")
|
||||
->with("success", __("Holiday has been created"));
|
||||
}
|
||||
|
||||
public function edit(Holiday $holiday): Response
|
||||
{
|
||||
return inertia("Holidays/Edit", [
|
||||
"holiday" => new HolidayFormDataResource($holiday),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(HolidayRequest $request, Holiday $holiday): RedirectResponse
|
||||
{
|
||||
$holiday->update($request->data());
|
||||
|
||||
return redirect()
|
||||
->route("holidays.index")
|
||||
->with("success", __("Holiday has been updated"));
|
||||
}
|
||||
|
||||
public function destroy(Holiday $holiday): RedirectResponse
|
||||
{
|
||||
$holiday->delete();
|
||||
|
||||
return redirect()
|
||||
->route("holidays.index")
|
||||
->with("success", __("Holiday has been deleted"));
|
||||
}
|
||||
}
|
22
app/Infrastructure/Http/Controllers/LogoutController.php
Normal file
22
app/Infrastructure/Http/Controllers/LogoutController.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
|
||||
class LogoutController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request): RedirectResponse
|
||||
{
|
||||
Auth::logout();
|
||||
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return redirect()->route("login");
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Toby\Eloquent\Helpers\YearPeriodRetriever;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
class SelectYearPeriodController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request, YearPeriod $yearPeriod): RedirectResponse
|
||||
{
|
||||
$request->session()->put(YearPeriodRetriever::SESSION_KEY, $yearPeriod->id);
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with("success", __("Selected year period has been changed"));
|
||||
}
|
||||
}
|
84
app/Infrastructure/Http/Controllers/UserController.php
Normal file
84
app/Infrastructure/Http/Controllers/UserController.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Response;
|
||||
use Toby\Domain\EmploymentForm;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Infrastructure\Http\Requests\UserRequest;
|
||||
use Toby\Infrastructure\Http\Resources\UserFormDataResource;
|
||||
use Toby\Infrastructure\Http\Resources\UserResource;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$users = User::query()
|
||||
->withTrashed()
|
||||
->search($request->query("search"))
|
||||
->orderBy("last_name")
|
||||
->orderBy("first_name")
|
||||
->paginate()
|
||||
->withQueryString();
|
||||
|
||||
return inertia("Users/Index", [
|
||||
"users" => UserResource::collection($users),
|
||||
"filters" => $request->only("search"),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(): Response
|
||||
{
|
||||
return inertia("Users/Create", [
|
||||
"employmentForms" => EmploymentForm::casesToSelect(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(UserRequest $request): RedirectResponse
|
||||
{
|
||||
User::query()->create($request->data());
|
||||
|
||||
return redirect()
|
||||
->route("users.index")
|
||||
->with("success", __("User has been created"));
|
||||
}
|
||||
|
||||
public function edit(User $user): Response
|
||||
{
|
||||
return inertia("Users/Edit", [
|
||||
"user" => new UserFormDataResource($user),
|
||||
"employmentForms" => EmploymentForm::casesToSelect(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(UserRequest $request, User $user): RedirectResponse
|
||||
{
|
||||
$user->update($request->data());
|
||||
|
||||
return redirect()
|
||||
->route("users.index")
|
||||
->with("success", __("User has been updated"));
|
||||
}
|
||||
|
||||
public function destroy(User $user): RedirectResponse
|
||||
{
|
||||
$user->delete();
|
||||
|
||||
return redirect()
|
||||
->route("users.index")
|
||||
->with("success", __("User has been deleted"));
|
||||
}
|
||||
|
||||
public function restore(User $user): RedirectResponse
|
||||
{
|
||||
$user->restore();
|
||||
|
||||
return redirect()
|
||||
->route("users.index")
|
||||
->with("success", __("User has been restored"));
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Inertia\Response;
|
||||
use Toby\Eloquent\Models\VacationLimit;
|
||||
use Toby\Infrastructure\Http\Requests\VacationLimitRequest;
|
||||
use Toby\Infrastructure\Http\Resources\VacationLimitResource;
|
||||
|
||||
class VacationLimitController extends Controller
|
||||
{
|
||||
public function edit(): Response
|
||||
{
|
||||
$limits = VacationLimit::query()
|
||||
->with("user")
|
||||
->orderByUserField("last_name")
|
||||
->orderByUserField("first_name")
|
||||
->get();
|
||||
|
||||
return inertia("VacationLimits", [
|
||||
"limits" => VacationLimitResource::collection($limits),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(VacationLimitRequest $request): RedirectResponse
|
||||
{
|
||||
$data = $request->data();
|
||||
|
||||
foreach ($request->vacationLimits() as $limit) {
|
||||
$limit->update($data[$limit->id]);
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with("success", __("Vacation limits have been updated"));
|
||||
}
|
||||
}
|
71
app/Infrastructure/Http/Kernel.php
Normal file
71
app/Infrastructure/Http/Kernel.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http;
|
||||
|
||||
use Fruitcake\Cors\HandleCors;
|
||||
use Illuminate\Auth\Middleware\AuthenticateWithBasicAuth;
|
||||
use Illuminate\Auth\Middleware\Authorize;
|
||||
use Illuminate\Auth\Middleware\EnsureEmailIsVerified;
|
||||
use Illuminate\Auth\Middleware\RequirePassword;
|
||||
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies;
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
use Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull;
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance;
|
||||
use Illuminate\Foundation\Http\Middleware\ValidatePostSize;
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
|
||||
use Illuminate\Http\Middleware\SetCacheHeaders;
|
||||
use Illuminate\Routing\Middleware\SubstituteBindings;
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
use Illuminate\Routing\Middleware\ValidateSignature;
|
||||
use Illuminate\Session\Middleware\AuthenticateSession;
|
||||
use Illuminate\Session\Middleware\StartSession;
|
||||
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
||||
use Toby\Infrastructure\Http\Middleware\Authenticate;
|
||||
use Toby\Infrastructure\Http\Middleware\HandleInertiaRequests;
|
||||
use Toby\Infrastructure\Http\Middleware\RedirectIfAuthenticated;
|
||||
use Toby\Infrastructure\Http\Middleware\TrimStrings;
|
||||
use Toby\Infrastructure\Http\Middleware\TrustProxies;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
{
|
||||
protected $middleware = [
|
||||
TrustProxies::class,
|
||||
HandleCors::class,
|
||||
PreventRequestsDuringMaintenance::class,
|
||||
ValidatePostSize::class,
|
||||
TrimStrings::class,
|
||||
ConvertEmptyStringsToNull::class,
|
||||
];
|
||||
|
||||
protected $middlewareGroups = [
|
||||
"web" => [
|
||||
EncryptCookies::class,
|
||||
AddQueuedCookiesToResponse::class,
|
||||
StartSession::class,
|
||||
AuthenticateSession::class,
|
||||
ShareErrorsFromSession::class,
|
||||
VerifyCsrfToken::class,
|
||||
SubstituteBindings::class,
|
||||
HandleInertiaRequests::class,
|
||||
],
|
||||
"api" => [
|
||||
"throttle:api",
|
||||
SubstituteBindings::class,
|
||||
],
|
||||
];
|
||||
|
||||
protected $routeMiddleware = [
|
||||
"auth" => Authenticate::class,
|
||||
"auth.basic" => AuthenticateWithBasicAuth::class,
|
||||
"cache.headers" => SetCacheHeaders::class,
|
||||
"can" => Authorize::class,
|
||||
"guest" => RedirectIfAuthenticated::class,
|
||||
"password.confirm" => RequirePassword::class,
|
||||
"signed" => ValidateSignature::class,
|
||||
"throttle" => ThrottleRequests::class,
|
||||
"verified" => EnsureEmailIsVerified::class,
|
||||
];
|
||||
}
|
15
app/Infrastructure/Http/Middleware/Authenticate.php
Normal file
15
app/Infrastructure/Http/Middleware/Authenticate.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
|
||||
class Authenticate extends Middleware
|
||||
{
|
||||
protected function redirectTo($request): string
|
||||
{
|
||||
return route("login");
|
||||
}
|
||||
}
|
34
app/Infrastructure/Http/Middleware/HandleInertiaRequests.php
Normal file
34
app/Infrastructure/Http/Middleware/HandleInertiaRequests.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Middleware;
|
||||
use Toby\Eloquent\Helpers\YearPeriodRetriever;
|
||||
use Toby\Infrastructure\Http\Resources\UserResource;
|
||||
|
||||
class HandleInertiaRequests extends Middleware
|
||||
{
|
||||
public function __construct(
|
||||
protected YearPeriodRetriever $yearPeriodRetriever,
|
||||
) {
|
||||
}
|
||||
|
||||
public function share(Request $request): array
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
return array_merge(parent::share($request), [
|
||||
"auth" => fn() => [
|
||||
"user" => $user ? new UserResource($user) : null,
|
||||
],
|
||||
"flash" => fn() => [
|
||||
"success" => $request->session()->get("success"),
|
||||
"error" => $request->session()->get("error"),
|
||||
],
|
||||
"years" => fn() => $user ? $this->yearPeriodRetriever->links() : [],
|
||||
]);
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
public function handle(Request $request, Closure $next, ...$guards): Response
|
||||
{
|
||||
$guards = empty($guards) ? [null] : $guards;
|
||||
|
||||
foreach ($guards as $guard) {
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect()->route("dashboard");
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
16
app/Infrastructure/Http/Middleware/TrimStrings.php
Normal file
16
app/Infrastructure/Http/Middleware/TrimStrings.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
||||
|
||||
class TrimStrings extends Middleware
|
||||
{
|
||||
protected $except = [
|
||||
"current_password",
|
||||
"password",
|
||||
"password_confirmation",
|
||||
];
|
||||
}
|
20
app/Infrastructure/Http/Middleware/TrustProxies.php
Normal file
20
app/Infrastructure/Http/Middleware/TrustProxies.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class TrustProxies extends Middleware
|
||||
{
|
||||
protected $proxies;
|
||||
|
||||
protected $headers =
|
||||
Request::HEADER_X_FORWARDED_FOR |
|
||||
Request::HEADER_X_FORWARDED_HOST |
|
||||
Request::HEADER_X_FORWARDED_PORT |
|
||||
Request::HEADER_X_FORWARDED_PROTO |
|
||||
Request::HEADER_X_FORWARDED_AWS_ELB;
|
||||
}
|
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,
|
||||
];
|
||||
}
|
||||
}
|
35
app/Infrastructure/Http/Requests/UserRequest.php
Normal file
35
app/Infrastructure/Http/Requests/UserRequest.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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\EmploymentForm;
|
||||
|
||||
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)],
|
||||
"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"),
|
||||
"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();
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class HolidayFormDataResource extends JsonResource
|
||||
{
|
||||
public static $wrap = null;
|
||||
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
"id" => $this->id,
|
||||
"name" => $this->name,
|
||||
"date" => $this->date->toDateString(),
|
||||
];
|
||||
}
|
||||
}
|
22
app/Infrastructure/Http/Resources/HolidayResource.php
Normal file
22
app/Infrastructure/Http/Resources/HolidayResource.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class HolidayResource extends JsonResource
|
||||
{
|
||||
public static $wrap = null;
|
||||
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
"id" => $this->id,
|
||||
"name" => $this->name,
|
||||
"displayDate" => $this->date->toDisplayString(),
|
||||
"dayOfWeek" => $this->date->dayName,
|
||||
];
|
||||
}
|
||||
}
|
24
app/Infrastructure/Http/Resources/UserFormDataResource.php
Normal file
24
app/Infrastructure/Http/Resources/UserFormDataResource.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class UserFormDataResource extends JsonResource
|
||||
{
|
||||
public static $wrap = null;
|
||||
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
"id" => $this->id,
|
||||
"firstName" => $this->first_name,
|
||||
"lastName" => $this->last_name,
|
||||
"email" => $this->email,
|
||||
"employmentForm" => $this->employment_form,
|
||||
"employmentDate" => $this->employment_date,
|
||||
];
|
||||
}
|
||||
}
|
26
app/Infrastructure/Http/Resources/UserResource.php
Normal file
26
app/Infrastructure/Http/Resources/UserResource.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class UserResource extends JsonResource
|
||||
{
|
||||
public static $wrap = null;
|
||||
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
"id" => $this->id,
|
||||
"name" => $this->fullName,
|
||||
"email" => $this->email,
|
||||
"role" => "Human Resources Manager",
|
||||
"avatar" => asset($this->avatar),
|
||||
"deleted" => $this->trashed(),
|
||||
"employmentForm" => $this->employment_form->label(),
|
||||
"employmentDate" => $this->employment_date->toDisplayString(),
|
||||
];
|
||||
}
|
||||
}
|
22
app/Infrastructure/Http/Resources/VacationLimitResource.php
Normal file
22
app/Infrastructure/Http/Resources/VacationLimitResource.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class VacationLimitResource extends JsonResource
|
||||
{
|
||||
public static $wrap = null;
|
||||
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
"id" => $this->id,
|
||||
"user" => new UserResource($this->user),
|
||||
"hasVacation" => $this->hasVacation(),
|
||||
"days" => $this->days,
|
||||
];
|
||||
}
|
||||
}
|
24
app/Infrastructure/Http/Rules/YearPeriodExists.php
Normal file
24
app/Infrastructure/Http/Rules/YearPeriodExists.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Rules;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
class YearPeriodExists implements Rule
|
||||
{
|
||||
public function passes($attribute, $value): bool
|
||||
{
|
||||
$yearPeriod = YearPeriod::findByYear(Carbon::create($value)->year);
|
||||
|
||||
return $yearPeriod !== null;
|
||||
}
|
||||
|
||||
public function message(): string
|
||||
{
|
||||
return "The year period for given year doesn't exist.";
|
||||
}
|
||||
}
|
44
app/Infrastructure/Jobs/CheckYearPeriod.php
Normal file
44
app/Infrastructure/Jobs/CheckYearPeriod.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
class CheckYearPeriod implements ShouldQueue
|
||||
{
|
||||
use Dispatchable;
|
||||
use Queueable;
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
if ($currentYearPeriod === null) {
|
||||
$this->createCurrentYearPeriod();
|
||||
}
|
||||
|
||||
if (YearPeriod::query()->max("year") === Carbon::now()->year) {
|
||||
$this->createNextYearPeriod();
|
||||
}
|
||||
}
|
||||
|
||||
protected function createCurrentYearPeriod(): void
|
||||
{
|
||||
YearPeriod::query()->create([
|
||||
"year" => Carbon::now()->year,
|
||||
]);
|
||||
}
|
||||
|
||||
protected function createNextYearPeriod(): void
|
||||
{
|
||||
YearPeriod::query()->create([
|
||||
"year" => Carbon::now()->year + 1,
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user