fipamo/app/Http/Controllers/API/FileUploadAPIController.php
ro 321feb9b92
Page Admin API, part 1
API accessible tasks (create, update, delete) have been updated to the
new format.

The controller needs to be cleaned up because it's a bit heavy and the
new API flow still needs to be properly documented, but it's a good
start
2024-07-23 17:46:45 -06:00

46 lines
1.3 KiB
PHP

<?php
namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Services\Assets\FileUploadService;
use App\Interfaces\MemberRepositoryInterface;
use App\Services\Data\SettingsService;
class FileUploadAPIController extends Controller
{
protected $upload;
protected $member;
protected $settings;
public function __construct(
FileUploadService $fileUploadService,
MemberRepositoryInterface $memberRepo,
SettingsService $settingsService
) {
$this->upload = $fileUploadService;
$this->member = $memberRepo;
$this->settings = $settingsService;
}
public function upload(Request $request)
{
$result = $this->upload->handleFile($request);
//update configs for specfic uploads
switch ($request['source']) {
case 'avatar-upload':
$member = [];
$member = session('member');
$member['avatar'] = $result['filePath'];
$member = (object) $member;
$this->member->update($member);
break;
case 'background-upload':
$this->settings->updateGlobalData('background', $result['filePath']);
break;
}
return $result;
}
}