This commit is contained in:
Adrian Hopek
2022-05-17 11:38:16 +02:00
parent 45510a898b
commit d2babab7a0
17 changed files with 596 additions and 110 deletions

View File

@@ -35,6 +35,6 @@ class AuthServiceProvider extends ServiceProvider
Gate::define("manageVacationLimits", fn(User $user): bool => $user->role === Role::AdministrativeApprover);
Gate::define("generateTimesheet", fn(User $user): bool => $user->role === Role::AdministrativeApprover);
Gate::define("listMonthlyUsage", fn(User $user): bool => $user->role === Role::AdministrativeApprover);
Gate::define("manageResumes", fn(User $user): bool => $user->role === Role::AdministrativeApprover);
Gate::define("manageResumes", fn(User $user): bool => $user->role === Role::TechnicalApprover);
}
}

View File

@@ -40,7 +40,7 @@ class ResumeGenerator
protected function fillTechnologies(TemplateProcessor $processor, Resume $resume): void
{
if ($resume->technologies->count() <= 0) {
if ($resume->technologies->isEmpty()) {
$processor->deleteBlock("technologies");
return;
@@ -51,7 +51,7 @@ class ResumeGenerator
protected function fillLanguages(TemplateProcessor $processor, Resume $resume): void
{
if ($resume->education->count() <= 0) {
if ($resume->education->isEmpty()) {
$processor->deleteBlock("languages");
return;
@@ -62,7 +62,7 @@ class ResumeGenerator
protected function fillEducation(TemplateProcessor $processor, Resume $resume): void
{
if ($resume->education->count() <= 0) {
if ($resume->education->isEmpty()) {
$processor->deleteBlock("education");
return;
@@ -73,7 +73,7 @@ class ResumeGenerator
protected function fillProjects(TemplateProcessor $processor, Resume $resume): void
{
if ($resume->projects->count() <= 0) {
if ($resume->projects->isEmpty()) {
$processor->deleteBlock("projects");
return;
@@ -94,7 +94,7 @@ class ResumeGenerator
return [
"index#{$index}" => $index,
"start_date#{$index}" => Carbon::create($project["startDate"])->toDisplayString(),
"end_date#{$index}" => Carbon::create($project["endDate"])->toDisplayString(),
"end_date#{$index}" => $project["current"] ? "present" : Carbon::create($project["endDate"])->format("m.Y"),
"description#{$index}" => $project["description"],
"tasks#{$index}" => $this->withNewLines($project["tasks"]),
];
@@ -134,7 +134,7 @@ class ResumeGenerator
{
return $resume->education->map(fn(array $project, int $index): array => [
"start_date" => Carbon::create($project["startDate"])->toDisplayString(),
"end_date" => Carbon::create($project["endDate"])->toDisplayString(),
"end_date" => $project["current"] ? "present" : Carbon::create($project["endDate"])->format("m.Y"),
"school" => $project["school"],
"field_of_study" => $project["fieldOfStudy"],
"degree" => $project["degree"],

View File

@@ -16,6 +16,8 @@ class Technology extends Model
{
use HasFactory;
protected $guarded = [];
protected static function newFactory(): TechnologyFactory
{
return TechnologyFactory::new();

View File

@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
namespace Toby\Infrastructure\Http\Controllers;
use Illuminate\Auth\Access\AuthorizationException;
use Inertia\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Toby\Eloquent\Models\Technology;
use Toby\Infrastructure\Http\Requests\TechnologyRequest;
use Toby\Infrastructure\Http\Resources\TechnologyResource;
class TechnologyController extends Controller
{
public function index(): Response
{
$this->authorize("manageResumes");
$technologies = Technology::query()
->orderBy("name")
->get();
return inertia("Technologies", [
"technologies" => TechnologyResource::collection($technologies),
]);
}
/**
* @throws AuthorizationException
*/
public function store(TechnologyRequest $request): RedirectResponse
{
$this->authorize("manageResumes");
$technology = Technology::query()->create($request->data());
return redirect()
->back()
->with("success", __("Technology :name has been created.", [
"name" => $technology->name,
]));
}
public function destroy(Technology $technology): RedirectResponse
{
$this->authorize("manageResumes");
$technology->delete();
return redirect()
->back()
->with("success", __("Technology :name has been deleted.", [
"name" => $technology->name,
]));
}
}

View File

@@ -20,19 +20,21 @@ class ResumeRequest extends FormRequest
"education.*.school" => ["required"],
"education.*.degree" => ["required"],
"education.*.fieldOfStudy" => ["required"],
"education.*.startDate" => ["required", "date_format:Y-m-d"],
"education.*.endDate" => ["required", "date_format:Y-m-d", "after:education.*.startDate"],
"education.*.startDate" => ["required", "date_format:m/Y"],
"education.*.current" => ["required", "boolean"],
"education.*.endDate" => ["required_if:education.*.current,false", "nullable", "date_format:m/Y", "after:education.*.startDate"],
"languages.*.name" => ["required", "distinct"],
"languages.*.level" => ["required", Rule::in(1, 2, 3, 4, 5, 6)],
"technologies.*.name" => ["required", "exists:technologies,name", "distinct"],
"technologies.*.name" => ["required", "distinct"],
"technologies.*.level" => ["required", Rule::in(1, 2, 3, 4, 5)],
"projects.*.description" => ["required"],
"projects.*.technologies" => ["array", "min:1", "exists:technologies,name", "distinct"],
"projects.*.startDate" => ["required", "date_format:Y-m-d"],
"projects.*.endDate" => ["required", "date_format:Y-m-d", "after:projects.*.startDate"],
"projects.*.technologies" => ["array", "min:1", "distinct"],
"projects.*.startDate" => ["required", "date_format:m/Y"],
"projects.*.current" => ["required", "boolean"],
"projects.*.endDate" => ["required_if:projects.*.current,false", "nullable", "date_format:m/Y", "after:projects.*.startDate"],
"projects.*.tasks" => ["required"],
];
}

View File

@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace Toby\Infrastructure\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class TechnologyRequest extends FormRequest
{
public function rules(): array
{
return [
"name" => [
"required",
Rule::unique("technologies", "name")->ignore($this->technology),
"max:255",
],
];
}
public function data(): array
{
return [
"name" => $this->get("name"),
];
}
}

View File

@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace Toby\Infrastructure\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class TechnologyResource extends JsonResource
{
public static $wrap = null;
public function toArray($request): array
{
return [
"id" => $this->id,
"name" => $this->name,
];
}
}