- 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:
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"));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user