- Updated DataTableService to accept a Pagination object for pagination parameters. - Refactored paginateQuery method to utilize pageSize and pageNumber from Pagination. refactor: replace ActionExecutor with Executor in controller traits - Updated ChangesModelOrder, TogglesModelStar, and TogglesModelStatus traits to use Executor interface instead of ActionExecutor. feat: add PictureMetadata and Slug value objects - Introduced PictureMetadata for managing image metadata with validation. - Added Slug value object for slug generation and validation. feat: update breadcrumbs to support RangeDto - Modified breadcrumbs-bo.php to accept RangeDto in the edit route. test: add tests for RangesController - Added tests for accessing, creating, updating, and deleting ranges. - Included tests for toggling range status. test: add integration tests for range actions - Created tests for CreateRange, DeleteRange, and UpdateRange actions. - Validated input handling and database interactions. test: add unit tests for range input classes - Implemented tests for CreateRangeInput and UpdateRangeInput to validate input constraints. test: add unit tests for value objects - Added tests for PictureMetadata and Slug to ensure proper validation and instantiation. test: add unit tests for RangeDto - Created tests to verify RangeDto mapping from Range model. test: add unit tests for RangePolicy - Implemented tests for RangePolicy to validate permissions based on user roles.
141 lines
4.6 KiB
PHP
141 lines
4.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Actions\Ranges\CreateRange;
|
|
use App\Actions\Ranges\CreateRangeInput;
|
|
use App\Actions\Ranges\DeleteRange;
|
|
use App\Actions\Ranges\DeleteRangeInput;
|
|
use App\Actions\Ranges\UpdateRange;
|
|
use App\Actions\Ranges\UpdateRangeInput;
|
|
use App\Contracts\Executor;
|
|
use App\Dto\RangeDto;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Bo\Ranges\StoreRangeRequest;
|
|
use App\Http\Requests\Bo\Ranges\UpdateRangeRequest;
|
|
use App\Models\Range;
|
|
use App\Queries\Ranges\GetPaginatedRangesQuery;
|
|
use App\Queries\Ranges\GetPaginatedRangesQueryInput;
|
|
use App\Traits\Controllers\ChangesModelOrder;
|
|
use App\Traits\Controllers\TogglesModelStatus;
|
|
use Domain\Models\ValueObjects\PictureMetadata;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Str;
|
|
|
|
class RangesController extends Controller
|
|
{
|
|
use ChangesModelOrder;
|
|
use TogglesModelStatus;
|
|
|
|
public function __construct(
|
|
private readonly Executor $executor,
|
|
) {
|
|
}
|
|
|
|
public function index(Request $request, GetPaginatedRangesQuery $query): View
|
|
{
|
|
$this->authorize('viewAny', Range::class);
|
|
|
|
$pagination = $request->pagination();
|
|
|
|
$ranges = $this->executor->execute(
|
|
$query,
|
|
new GetPaginatedRangesQueryInput(
|
|
pagination: $pagination,
|
|
)
|
|
);
|
|
|
|
return view('bo.ranges.index', compact('ranges'));
|
|
}
|
|
|
|
public function create(): View
|
|
{
|
|
$this->authorize('create', Range::class);
|
|
|
|
return view('bo.ranges.create');
|
|
}
|
|
|
|
public function store(StoreRangeRequest $request, CreateRange $action): RedirectResponse
|
|
{
|
|
$this->authorize('create', Range::class);
|
|
|
|
$pictureAlt = $request->filled('picture_alt') ? $request->string('picture_alt')->value() : null;
|
|
$pictureTitle = $request->filled('picture_title') ? $request->string('picture_title')->value() : null;
|
|
|
|
$range = $this->executor->execute(
|
|
$action,
|
|
new CreateRangeInput(
|
|
name: $request->string('name')->value(),
|
|
description: $request->filled('description') ? $request->string('description')->value() : null,
|
|
picture: $request->file('picture'),
|
|
pictureMetadata: new PictureMetadata(
|
|
alt: $pictureAlt,
|
|
title: $pictureTitle,
|
|
),
|
|
status: $request->boolean('status'),
|
|
),
|
|
);
|
|
|
|
return to_route('bo.ranges.edit', $range)
|
|
->with('success', trans('crud.messages.has_been_created', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.ranges', 1)),
|
|
]));
|
|
}
|
|
|
|
public function edit(Range $range): View
|
|
{
|
|
$this->authorize('update', $range);
|
|
|
|
$range = RangeDto::fromModel($range);
|
|
|
|
return view('bo.ranges.edit', compact('range'));
|
|
}
|
|
|
|
public function update(UpdateRangeRequest $request, Range $range, UpdateRange $action): RedirectResponse
|
|
{
|
|
$this->authorize('update', $range);
|
|
|
|
$pictureAlt = $request->filled('picture_alt') ? $request->string('picture_alt')->value() : null;
|
|
$pictureTitle = $request->filled('picture_title') ? $request->string('picture_title')->value() : null;
|
|
|
|
$this->executor->execute(
|
|
$action,
|
|
new UpdateRangeInput(
|
|
range: $range,
|
|
name: $request->string('name')->value(),
|
|
description: $request->filled('description') ? $request->string('description')->value() : null,
|
|
picture: $request->file('picture'),
|
|
pictureMetadata: new PictureMetadata(
|
|
alt: $pictureAlt,
|
|
title: $pictureTitle,
|
|
),
|
|
status: $request->boolean('status'),
|
|
),
|
|
);
|
|
|
|
return to_route('bo.ranges.edit', $range)
|
|
->with('success', trans('crud.messages.has_been_updated', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.ranges', 1)),
|
|
]));
|
|
}
|
|
|
|
public function destroy(Range $range, DeleteRange $action): RedirectResponse
|
|
{
|
|
$this->authorize('delete', $range);
|
|
|
|
$this->executor->execute(
|
|
$action,
|
|
new DeleteRangeInput(range: $range),
|
|
);
|
|
|
|
return to_route('bo.ranges.index')
|
|
->with('warning', trans(
|
|
'crud.messages.has_been_deleted',
|
|
['model' => Str::ucfirst(trans_choice('models.classes.ranges', 1))]
|
|
));
|
|
}
|
|
}
|