2024-03-07 22:42:11 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
|
2024-03-08 21:09:43 +01:00
|
|
|
use App\Interfaces\PageRepositoryInterface;
|
2024-07-24 01:46:45 +02:00
|
|
|
use App\Interfaces\MemberRepositoryInterface;
|
2024-03-07 22:42:11 +01:00
|
|
|
use App\Http\Controllers\Controller;
|
2024-07-24 01:46:45 +02:00
|
|
|
use App\Services\Assets\FileUploadService;
|
2024-03-07 22:42:11 +01:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
2024-07-24 01:46:45 +02:00
|
|
|
use function _\find;
|
|
|
|
|
2024-03-07 22:42:11 +01:00
|
|
|
class PageAPIController extends Controller
|
|
|
|
{
|
2024-03-08 21:09:43 +01:00
|
|
|
protected $pages;
|
2024-07-24 01:46:45 +02:00
|
|
|
protected $member;
|
|
|
|
protected $upload;
|
2024-03-08 21:09:43 +01:00
|
|
|
|
2024-03-07 22:42:11 +01:00
|
|
|
public function __construct(
|
2024-07-24 01:46:45 +02:00
|
|
|
PageRepositoryInterface $pageRepository,
|
|
|
|
MemberRepositoryInterface $memberRepo,
|
|
|
|
FileUploadService $fileUploadService,
|
2024-03-07 22:42:11 +01:00
|
|
|
) {
|
2024-07-24 01:46:45 +02:00
|
|
|
$this->pages = $pageRepository;
|
|
|
|
$this->upload = $fileUploadService;
|
|
|
|
$this->member = $memberRepo;
|
2024-03-07 22:42:11 +01:00
|
|
|
}
|
|
|
|
|
2024-07-24 01:46:45 +02:00
|
|
|
public function update(Request $request)
|
2024-03-07 22:42:11 +01:00
|
|
|
{
|
2024-07-24 22:57:04 +02:00
|
|
|
$body = json_decode($request->getContent());
|
|
|
|
//check to see if required fields are present
|
|
|
|
if ($body->uuid == '' || $body->uuid == null) {
|
|
|
|
$error = [
|
|
|
|
'message' => "[uuidx ] is a required field",
|
|
|
|
'type' => 'postError',
|
|
|
|
];
|
|
|
|
return response()->json($error)->header('Content-Type', 'application/json');
|
2024-07-24 01:46:45 +02:00
|
|
|
}
|
2024-07-24 22:57:04 +02:00
|
|
|
$apiKey = $request->header('fipamo-api-key');
|
|
|
|
$body->slug = strtolower(str_replace(' ', '-', $body->title));
|
|
|
|
if (!isset($body->imageList)) {
|
|
|
|
$body->imageList = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($body->fileList)) {
|
|
|
|
$body->fileList = '';
|
|
|
|
}
|
|
|
|
//find member based on key and create a session
|
2024-07-24 01:46:45 +02:00
|
|
|
$folks = $this->member->getAll();
|
|
|
|
$member = find($folks, ['key' => $apiKey]);
|
|
|
|
$request->session()->put('member', $member);
|
2024-07-24 22:57:04 +02:00
|
|
|
$result = $this->pages->update($body);
|
|
|
|
//clear session once page is created
|
2024-07-24 01:46:45 +02:00
|
|
|
session()->flush();
|
|
|
|
return response()->json($result)->header('Content-Type', 'application/json');
|
2024-03-07 22:42:11 +01:00
|
|
|
}
|
2024-03-12 23:16:36 +01:00
|
|
|
|
|
|
|
public function create(Request $request)
|
|
|
|
{
|
2024-07-24 22:57:04 +02:00
|
|
|
$body = json_decode($request->getContent());
|
|
|
|
//check to see if required fields are present
|
|
|
|
if ($body->title == '' || $body->title == null) {
|
|
|
|
$error = [
|
|
|
|
'message' => "[title] is a required field",
|
|
|
|
'type' => 'postError',
|
|
|
|
];
|
|
|
|
return response()->json($error)->header('Content-Type', 'application/json');
|
2024-07-24 01:46:45 +02:00
|
|
|
}
|
2024-07-24 22:57:04 +02:00
|
|
|
$apiKey = $request->header('fipamo-api-key');
|
|
|
|
$folks = $this->member->getAll();
|
|
|
|
$body->slug = strtolower(str_replace(' ', '-', $body->title));
|
|
|
|
if (!isset($body->imageList)) {
|
|
|
|
$body->imageList = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($body->fileList)) {
|
|
|
|
$body->fileList = '';
|
|
|
|
}
|
|
|
|
//find member based on key and create a session
|
2024-07-24 01:46:45 +02:00
|
|
|
$member = find($folks, ['key' => $apiKey]);
|
|
|
|
$request->session()->put('member', $member);
|
2024-07-24 22:57:04 +02:00
|
|
|
$result = $this->pages->create($body);
|
|
|
|
//clear session once page is created
|
2024-07-24 01:46:45 +02:00
|
|
|
session()->flush();
|
2024-03-12 23:16:36 +01:00
|
|
|
return response()->json($result)->header('Content-Type', 'application/json');
|
|
|
|
}
|
2024-07-07 00:23:23 +02:00
|
|
|
|
|
|
|
public function delete(Request $request)
|
|
|
|
{
|
2024-07-24 22:57:04 +02:00
|
|
|
$body = json_decode($request->getContent());
|
|
|
|
//check to see if required fields are present
|
|
|
|
if ($body->uuid == '' || $body->uuid == null) {
|
|
|
|
$error = [
|
|
|
|
'message' => "[uuidx ] is a required field",
|
|
|
|
'type' => 'postError',
|
|
|
|
];
|
|
|
|
return response()->json($error)->header('Content-Type', 'application/json');
|
|
|
|
}
|
2024-07-24 01:46:45 +02:00
|
|
|
$apiKey = $request->header('fipamo-api-key');
|
|
|
|
$folks = $this->member->getAll();
|
|
|
|
$member = find($folks, ['key' => $apiKey]);
|
|
|
|
$request->session()->put('member', $member);
|
2024-07-07 00:23:23 +02:00
|
|
|
$result = $this->pages->delete($body);
|
2024-07-24 01:46:45 +02:00
|
|
|
session()->flush();
|
2024-07-07 00:23:23 +02:00
|
|
|
return response()->json($result)->header('Content-Type', 'application/json');
|
|
|
|
}
|
2024-03-07 22:42:11 +01:00
|
|
|
}
|