-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: manage recruiting stages (#1221)
- Loading branch information
Showing
34 changed files
with
2,521 additions
and
6 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
191 changes: 191 additions & 0 deletions
191
app/Http/Controllers/Company/Adminland/AdminRecruitmentController.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,191 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Company\Adminland; | ||
|
||
use Inertia\Inertia; | ||
use Inertia\Response; | ||
use Illuminate\Http\Request; | ||
use App\Helpers\InstanceHelper; | ||
use Illuminate\Http\JsonResponse; | ||
use App\Helpers\NotificationHelper; | ||
use App\Http\Controllers\Controller; | ||
use App\Models\Company\RecruitingStageTemplate; | ||
use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
use App\Http\ViewHelpers\Adminland\AdminRecruitmentViewHelper; | ||
use App\Services\Company\Adminland\JobOpening\CreateRecruitingStage; | ||
use App\Services\Company\Adminland\JobOpening\UpdateRecruitingStage; | ||
use App\Services\Company\Adminland\JobOpening\DestroyRecruitingStage; | ||
use App\Services\Company\Adminland\JobOpening\CreateRecruitingStageTemplate; | ||
|
||
class AdminRecruitmentController extends Controller | ||
{ | ||
/** | ||
* Show the recruitment page. | ||
* | ||
* @return Response | ||
*/ | ||
public function index(): Response | ||
{ | ||
$company = InstanceHelper::getLoggedCompany(); | ||
|
||
$templates = AdminRecruitmentViewHelper::index($company); | ||
|
||
return Inertia::render('Adminland/Recruitment/Index', [ | ||
'notifications' => NotificationHelper::getNotifications(InstanceHelper::getLoggedEmployee()), | ||
'templates' => $templates, | ||
]); | ||
} | ||
|
||
/** | ||
* Create the template. | ||
* | ||
* @param Request $request | ||
* @param int $companyId | ||
* @return JsonResponse | ||
*/ | ||
public function store(Request $request, int $companyId): JsonResponse | ||
{ | ||
$company = InstanceHelper::getLoggedCompany(); | ||
$loggedEmployee = InstanceHelper::getLoggedEmployee(); | ||
|
||
$data = [ | ||
'company_id' => $company->id, | ||
'author_id' => $loggedEmployee->id, | ||
'name' => $request->input('name'), | ||
]; | ||
|
||
$template = (new CreateRecruitingStageTemplate)->execute($data); | ||
|
||
return response()->json([ | ||
'data' => [ | ||
'id' => $template->id, | ||
'name' => $template->name, | ||
'stages' => null, | ||
'url' => route('recruitment.show', [ | ||
'company' => $company, | ||
'template' => $template, | ||
]), | ||
], | ||
], 201); | ||
} | ||
|
||
/** | ||
* Show the template content. | ||
* | ||
* @param Request $request | ||
* @param int $companyId | ||
* @param int $templateId | ||
* @return mixed | ||
*/ | ||
public function show(Request $request, int $companyId, int $templateId) | ||
{ | ||
$company = InstanceHelper::getLoggedCompany(); | ||
|
||
try { | ||
$template = RecruitingStageTemplate::where('company_id', $company->id) | ||
->findOrFail($templateId); | ||
} catch (ModelNotFoundException $e) { | ||
return redirect('home'); | ||
} | ||
|
||
$template = AdminRecruitmentViewHelper::show($company, $template); | ||
|
||
return Inertia::render('Adminland/Recruitment/Show', [ | ||
'notifications' => NotificationHelper::getNotifications(InstanceHelper::getLoggedEmployee()), | ||
'template' => $template, | ||
]); | ||
} | ||
|
||
/** | ||
* Create the stage. | ||
* | ||
* @param Request $request | ||
* @param int $companyId | ||
* @param int $templateId | ||
* @return JsonResponse | ||
*/ | ||
public function storeStage(Request $request, int $companyId, int $templateId): JsonResponse | ||
{ | ||
$company = InstanceHelper::getLoggedCompany(); | ||
$loggedEmployee = InstanceHelper::getLoggedEmployee(); | ||
|
||
$data = [ | ||
'company_id' => $company->id, | ||
'author_id' => $loggedEmployee->id, | ||
'recruiting_stage_template_id' => $templateId, | ||
'name' => $request->input('name'), | ||
]; | ||
|
||
$stage = (new CreateRecruitingStage)->execute($data); | ||
|
||
return response()->json([ | ||
'data' => [ | ||
'id' => $stage->id, | ||
'name' => $stage->name, | ||
'position' => $stage->position, | ||
], | ||
], 201); | ||
} | ||
|
||
/** | ||
* Update the stage. | ||
* | ||
* @param Request $request | ||
* @param int $companyId | ||
* @param int $templateId | ||
* @param int $stageId | ||
* @return JsonResponse | ||
*/ | ||
public function updateStage(Request $request, int $companyId, int $templateId, int $stageId): JsonResponse | ||
{ | ||
$company = InstanceHelper::getLoggedCompany(); | ||
$loggedEmployee = InstanceHelper::getLoggedEmployee(); | ||
|
||
$data = [ | ||
'company_id' => $company->id, | ||
'author_id' => $loggedEmployee->id, | ||
'recruiting_stage_template_id' => $templateId, | ||
'recruiting_stage_id' => $stageId, | ||
'name' => $request->input('name'), | ||
'position' => $request->input('position'), | ||
]; | ||
|
||
$stage = (new UpdateRecruitingStage)->execute($data); | ||
|
||
return response()->json([ | ||
'data' => [ | ||
'id' => $stage->id, | ||
'name' => $stage->name, | ||
'position' => $stage->position, | ||
], | ||
], 200); | ||
} | ||
|
||
/** | ||
* Delete the stage. | ||
* | ||
* @param Request $request | ||
* @param int $companyId | ||
* @param int $templateId | ||
* @param int $stageId | ||
* @return JsonResponse | ||
*/ | ||
public function destroyStage(Request $request, int $companyId, int $templateId, int $stageId): JsonResponse | ||
{ | ||
$company = InstanceHelper::getLoggedCompany(); | ||
$loggedEmployee = InstanceHelper::getLoggedEmployee(); | ||
|
||
$data = [ | ||
'company_id' => $company->id, | ||
'author_id' => $loggedEmployee->id, | ||
'recruiting_stage_template_id' => $templateId, | ||
'recruiting_stage_id' => $stageId, | ||
]; | ||
|
||
(new DestroyRecruitingStage)->execute($data); | ||
|
||
return response()->json([ | ||
'data' => true, | ||
], 200); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
app/Http/ViewHelpers/Adminland/AdminRecruitmentViewHelper.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,74 @@ | ||
<?php | ||
|
||
namespace App\Http\ViewHelpers\Adminland; | ||
|
||
use App\Models\Company\Company; | ||
use Illuminate\Support\Collection; | ||
use App\Models\Company\RecruitingStageTemplate; | ||
|
||
class AdminRecruitmentViewHelper | ||
{ | ||
/** | ||
* Get all the recruiting stage templates in the company. | ||
* | ||
* @param Company $company | ||
* @return Collection | ||
*/ | ||
public static function index(Company $company): ?Collection | ||
{ | ||
$templates = $company->recruitingStageTemplates() | ||
->with('stages') | ||
->orderBy('name') | ||
->get(); | ||
|
||
$templatesCollection = collect(); | ||
foreach ($templates as $template) { | ||
$stages = $template->stages; | ||
$stagesCollection = collect(); | ||
foreach ($stages as $stage) { | ||
$stagesCollection->push([ | ||
'id' => $stage->id, | ||
'name' => $stage->name, | ||
'position' => $stage->position, | ||
]); | ||
} | ||
|
||
$templatesCollection->push([ | ||
'id' => $template->id, | ||
'name' => $template->name, | ||
'stages' => $stagesCollection, | ||
'url' => route('recruitment.show', [ | ||
'company' => $company, | ||
'template' => $template, | ||
]), | ||
]); | ||
} | ||
|
||
return $templatesCollection; | ||
} | ||
|
||
/** | ||
* Get the information about the given template. | ||
* | ||
* @param Company $company | ||
* @return array | ||
*/ | ||
public static function show(Company $company, RecruitingStageTemplate $template): ?array | ||
{ | ||
$stages = $template->stages; | ||
$stagesCollection = collect(); | ||
foreach ($stages as $stage) { | ||
$stagesCollection->push([ | ||
'id' => $stage->id, | ||
'name' => $stage->name, | ||
'position' => $stage->position, | ||
]); | ||
} | ||
|
||
return [ | ||
'id' => $template->id, | ||
'name' => $template->name, | ||
'stages' => $stagesCollection, | ||
]; | ||
} | ||
} |
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.