Add optional category selection when creating documentation
- Update `DocumentationService::create` to support an optional `categoryId` parameter. - Introduce `CreateRequest` for input validation. - Adjust controller logic to handle `categoryId`. - Restructure create/edit views under the `documentation-versions` directory.
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin\Projects;
|
|||||||
|
|
||||||
use App\Dto\QuerySettingsDto;
|
use App\Dto\QuerySettingsDto;
|
||||||
use App\Http\Controllers\Admin\Controller;
|
use App\Http\Controllers\Admin\Controller;
|
||||||
|
use App\Http\Requests\Admin\Projects\Documentations\CreateRequest;
|
||||||
use App\Http\Requests\Admin\Projects\Documentations\IndexRequest;
|
use App\Http\Requests\Admin\Projects\Documentations\IndexRequest;
|
||||||
use App\Http\Requests\Admin\Projects\Documentations\StoreUpdateRequest;
|
use App\Http\Requests\Admin\Projects\Documentations\StoreUpdateRequest;
|
||||||
use App\Services\Admin\Project\DocumentationService;
|
use App\Services\Admin\Project\DocumentationService;
|
||||||
@@ -32,18 +33,23 @@ final class DocumentationsController extends Controller
|
|||||||
$this->errors($result);
|
$this->errors($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('admin/projects/documentations/index', $result->getData());
|
return view('admin/projects/documentation-versions/documentations/index', $result->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(int $projectId, int $versionId, Request $request): View
|
public function create(int $projectId, int $versionId, CreateRequest $request): View
|
||||||
{
|
{
|
||||||
|
$categoryId = null;
|
||||||
|
if ($request->has('category')) {
|
||||||
|
$categoryId = (int) $request->input('category');
|
||||||
|
}
|
||||||
|
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
$result = $this->documentationService->create($projectId, $versionId, $user);
|
$result = $this->documentationService->create($projectId, $versionId, $user, $categoryId);
|
||||||
if ($result->isError()) {
|
if ($result->isError()) {
|
||||||
$this->errors($result);
|
$this->errors($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('admin/projects/documentations/create', $result->getData());
|
return view('admin/projects/documentation-versions/documentations/create', $result->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit(int $projectId, int $versionId, int $id, Request $request): View
|
public function edit(int $projectId, int $versionId, int $id, Request $request): View
|
||||||
@@ -54,7 +60,7 @@ final class DocumentationsController extends Controller
|
|||||||
$this->errors($result);
|
$this->errors($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('admin/projects/documentations/edit', $result->getData());
|
return view('admin/projects/documentation-versions/documentations/edit', $result->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(int $projectId, int $versionId, StoreUpdateRequest $request): RedirectResponse
|
public function store(int $projectId, int $versionId, StoreUpdateRequest $request): RedirectResponse
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Admin\Projects\Documentations;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
final class CreateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'category' => ['nullable', 'integer', 'min:1'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -75,7 +75,7 @@ final class DocumentationService extends Service
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(int $projectId, int $versionId, User $user): ServiceResultError | ServiceResultArray
|
public function create(int $projectId, int $versionId, User $user, ?int $categoryId = null): ServiceResultError | ServiceResultArray
|
||||||
{
|
{
|
||||||
$version = $this->documentationVersionRepository->getVersionById($versionId);
|
$version = $this->documentationVersionRepository->getVersionById($versionId);
|
||||||
$project = $version?->project;
|
$project = $version?->project;
|
||||||
@@ -87,11 +87,16 @@ final class DocumentationService extends Service
|
|||||||
return $this->errFobidden(__('Access is denied'));
|
return $this->errFobidden(__('Access is denied'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$documentation = new Documentation();
|
||||||
|
if ($categoryId !== null) {
|
||||||
|
$documentation->category_id = $categoryId;
|
||||||
|
}
|
||||||
|
|
||||||
$defaultLanguage = $project->languages->where('is_default', 1)->first();
|
$defaultLanguage = $project->languages->where('is_default', 1)->first();
|
||||||
return $this->result([
|
return $this->result([
|
||||||
'version' => $version,
|
'version' => $version,
|
||||||
'project' => $project,
|
'project' => $project,
|
||||||
'documentation' => new Documentation(),
|
'documentation' => $documentation,
|
||||||
'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage),
|
'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage),
|
||||||
'serviceTranslationEnable' => config('translation_service.enable', false),
|
'serviceTranslationEnable' => config('translation_service.enable', false),
|
||||||
]);
|
]);
|
||||||
|
|||||||
+2
-2
@@ -3,14 +3,14 @@
|
|||||||
{{ __('admin-sections.Project') . ': ' . $project->name . ' (' . $version->title . ')' }}
|
{{ __('admin-sections.Project') . ': ' . $project->name . ' (' . $version->title . ')' }}
|
||||||
@endsection
|
@endsection
|
||||||
<x-admin.layout>
|
<x-admin.layout>
|
||||||
@include('admin.projects.documentations._top')
|
@include('admin.projects.documentation-versions.documentations._top')
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12 mb-4">
|
<div class="col-12 mb-4">
|
||||||
<div class="card border-0 shadow components-section">
|
<div class="card border-0 shadow components-section">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h3 id="category" class="mb-4">{{ __('admin-sections.Documentation') }}</h3>
|
<h3 id="category" class="mb-4">{{ __('admin-sections.Documentation') }}</h3>
|
||||||
<form method="post" action="{{ route('admin.projects.documentation-versions.documentations.store', ['project' => $project->id, 'version' => $version->id]) }}">
|
<form method="post" action="{{ route('admin.projects.documentation-versions.documentations.store', ['project' => $project->id, 'version' => $version->id]) }}">
|
||||||
@include('admin.projects.documentations._from')
|
@include('admin.projects.documentation-versions.documentations._from')
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
Reference in New Issue
Block a user