fix
This commit is contained in:
57
app/Infrastructure/Http/Controllers/TechnologyController.php
Normal file
57
app/Infrastructure/Http/Controllers/TechnologyController.php
Normal 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,
|
||||
]));
|
||||
}
|
||||
}
|
@@ -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"],
|
||||
];
|
||||
}
|
||||
|
29
app/Infrastructure/Http/Requests/TechnologyRequest.php
Normal file
29
app/Infrastructure/Http/Requests/TechnologyRequest.php
Normal 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"),
|
||||
];
|
||||
}
|
||||
}
|
20
app/Infrastructure/Http/Resources/TechnologyResource.php
Normal file
20
app/Infrastructure/Http/Resources/TechnologyResource.php
Normal 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,
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user