fipamo/app/Http/Controllers/RoutePutController.php

93 lines
3 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Http\Controllers;
use App\Interfaces\PageRepositoryInterface;
use App\Services\Assets\AssetService;
use App\Services\Assets\RenderService;
use App\Interfaces\MemberRepositoryInterface;
use App\Services\Data\SettingsService;
use App\Services\Upkeep\MaintenanceService;
use Illuminate\Http\Request;
class RoutePutController extends Controller
{
protected $page;
protected $assets;
protected $render;
protected $settings;
protected $member;
protected $maintenance;
public function __construct(
PageRepositoryInterface $pageRepo,
AssetService $assetService,
RenderService $renderService,
SettingsService $settingsService,
MemberRepositoryInterface $memberRepo,
MaintenanceService $maintenanceService,
) {
$this->page = $pageRepo;
$this->assets = $assetService;
$this->render = $renderService;
$this->settings = $settingsService;
$this->member = $memberRepo;
$this->maintenance = $maintenanceService;
}
public function handleRequest(Request $request)
{
$path = explode('/', $request->path());
switch ($path[0]) {
case 'page':
$body = json_decode($request->getContent());
$result = $this->page->update($body);
return response()->json($result)->header('Content-Type', 'application/json');
break;
case 'settings':
return $this->settingsTasks($request, $path[1]);
break;
case 'backup':
return $this->createBackup($request);
break;
}
}
private function createBackup($request)
{
$body = json_decode($request->getContent());
if ($body->task == 'content_backup') {
return response()->json(
$this->maintenance->createContentBackUp()
)->header('Content-Type', 'application/json');
} else {
return response()->json(
$this->maintenance->createFileBackUp()
)->header('Content-Type', 'application/json');
}
}
private function settingsTasks($request, $task)
{
$result = [];
switch ($task) {
case 'publish':
$this->assets->moveToTheme(true);
$result = $this->render->publishAll();
break;
case 'sync':
$body = json_decode($request->getContent());
//update member if needed
$this->member->update($body->member);
//sync settings
$result = $this->settings->sync($body);
break;
case 'nav-sync':
$body = json_decode($request->getContent());
$result = $this->settings->navSync($body);
break;
}
return response()->json($result)->header('Content-Type', 'application/json');
}
}