mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-08-01 08:16:55 -04:00
100 lines
2.7 KiB
PHP
100 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace Modules\Frontend\Http\Controllers;
|
|
|
|
use Illuminate\Contracts\Support\Renderable;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Controller;
|
|
use Modules\Frontend\Entities\Section;
|
|
use Modules\Frontend\Http\Requests\SectionRequest;
|
|
use Modules\Frontend\Repositories\SectionRepository;
|
|
use Modules\Frontend\Services\Sections;
|
|
|
|
class SectionController extends Controller
|
|
{
|
|
protected $repository;
|
|
protected $service;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->repository = new SectionRepository();
|
|
$this->service = new Sections();
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$sections = $this->service->all();
|
|
|
|
return response()->json([
|
|
'sections' => $sections,
|
|
]);
|
|
}
|
|
|
|
public function store(SectionRequest $request)
|
|
{
|
|
$section = $this->repository->create($request->title, $request->layout);
|
|
|
|
if ($section) {
|
|
return response()->json([
|
|
'message' => __('frontend::common.section-saved'),
|
|
'section' => $section,
|
|
]);
|
|
}
|
|
|
|
return response()->json([
|
|
'message' => __('frontend::common.store-section-failed'),
|
|
], 400);
|
|
}
|
|
|
|
public function update(SectionRequest $request)
|
|
{
|
|
$result = $this->repository->update($request->id, $request->title, $request->layout);
|
|
|
|
if ($result) {
|
|
return response()->json([
|
|
'message' => __('frontend::common.section-updated'),
|
|
'section' => $result,
|
|
]);
|
|
}
|
|
|
|
return response()->json([
|
|
'message' => __('frontend::common.update-section-failed'),
|
|
], 400);
|
|
}
|
|
|
|
public function destroy(SectionRequest $request)
|
|
{
|
|
$result = $this->repository->destroy($request->id);
|
|
|
|
if ($result) {
|
|
return response()->json([
|
|
'message' => __('frontend::common.section-deleted'),
|
|
]);
|
|
}
|
|
|
|
return response()->json([
|
|
'message' => __('frontend::common.delete-section-failed'),
|
|
], 400);
|
|
}
|
|
|
|
public function updateSectionItems(Request $request, Section $section)
|
|
{
|
|
$sections = $request->items;
|
|
$this->service->updateSectionItems($section, $sections);
|
|
|
|
return response()->json([
|
|
'message' => __('frontend::common.section-items-updated'),
|
|
]);
|
|
}
|
|
|
|
public function updateSectionCategories(Request $request, Section $section)
|
|
{
|
|
$categories = $request->items;
|
|
$this->service->updateSectionCategories($section, $categories);
|
|
|
|
return response()->json([
|
|
'message' => __('frontend::common.section-categories-updated'),
|
|
]);
|
|
}
|
|
}
|