fipamo/app/Http/Controllers/RoutePutController.php
ro 3d17771f76
API Decoupling, Part 1
The first part of improving the API is removing all admin functions from
the front end so those no admin methods will be available client side.

The urls in the FipamoAdmin js file have been changed to post directly to the
system and they are handled from there. To account for this change
controller routes for every standard method have been created for better
organization and readability.

The FipamoAdmin js file will be integrated with the rest of the front
end code and will not be seperate library
2024-07-13 14:23:01 -06:00

72 lines
2.2 KiB
PHP

<?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 Illuminate\Http\Request;
class RoutePutController extends Controller
{
protected $page;
protected $assets;
protected $render;
protected $settings;
protected $member;
public function __construct(
PageRepositoryInterface $pageRepo,
AssetService $assetService,
RenderService $renderService,
SettingsService $settingsService,
MemberRepositoryInterface $memberRepo,
) {
$this->page = $pageRepo;
$this->assets = $assetService;
$this->render = $renderService;
$this->settings = $settingsService;
$this->member = $memberRepo;
}
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;
}
}
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');
}
}