added page repository and interface

plugged in classes for a page repository to handle editing and
retrieving page content and an interface class for the controller to talk to to
keep the methodoloy seperate from the controller to keep it all clean

now whatever changes that need to be made won't bother the controller
because it will always be looking for the same functions. super sweet
This commit is contained in:
ro 2024-03-05 13:27:27 -06:00
parent 2b437c0173
commit 177f29802b
No known key found for this signature in database
GPG key ID: 29B551CDBD4D3B50
6 changed files with 111 additions and 21 deletions

View file

@ -2,16 +2,16 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Services\PaginateService; use App\Interfaces\PageRepositoryInterface;
class DashController extends Controller class DashController extends Controller
{ {
protected $pages; protected PageRepositoryInterface $pages;
public function __construct( public function __construct(
PaginateService $paginateService, PageRepositoryInterface $pageRepository,
) { ) {
$this->pages = $paginateService; $this->pages = $pageRepository;
} }
public function start() public function start()
@ -19,7 +19,7 @@ class DashController extends Controller
$status = session('handle') !== null ? true : false; $status = session('handle') !== null ? true : false;
$result = []; $result = [];
if ($status) { if ($status) {
$result = $this->pages->getPage(1, 4); $result = $this->pages->getGroup(1, 4);
} }
return view('back.start', [ return view('back.start', [
"status" => $status, "status" => $status,
@ -28,7 +28,22 @@ class DashController extends Controller
]); ]);
} }
public function book($pageFilter = 'all', $pageNum = '1') public function book($pageFilter = 'all', $pageNum = 1)
{
$status = session('handle') !== null ? true : false;
$result = [];
if ($status) {
$result = $this->pages->getGroup($pageNum, 4, $pageFilter);
}
return view('back.book', [
"status" => $status,
"result" => $result,
"currentPage" => $pageNum,
"title" => "Pages"
]);
}
public function page($uuid)
{ {
$status = session('handle') !== null ? true : false; $status = session('handle') !== null ? true : false;
$result = []; $result = [];

View file

@ -0,0 +1,18 @@
<?php
namespace App\Interfaces;
interface PageRepositoryInterface
{
public function getAll();
public function getByID($uuid);
public function delete($uuid);
public function create(array $page);
public function update($uuid, array $page);
public function getGroup($num, $limit, $filter);
}

View file

@ -3,6 +3,8 @@
namespace App\Providers; namespace App\Providers;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use App\Repositories\PageRepository;
use App\Interfaces\PageRepositoryInterface;
use App\Services\SettingsService; use App\Services\SettingsService;
use App\Services\AuthService; use App\Services\AuthService;
use App\Services\ContentService; use App\Services\ContentService;
@ -15,6 +17,7 @@ class FipamoServiceProvider extends ServiceProvider
*/ */
public function register(): void public function register(): void
{ {
//services
$this->app->bind(SettingsService::class, function ($app) { $this->app->bind(SettingsService::class, function ($app) {
return new SettingsService(); return new SettingsService();
}); });
@ -37,6 +40,6 @@ class FipamoServiceProvider extends ServiceProvider
*/ */
public function boot(): void public function boot(): void
{ {
// $this->app->bind(PageRepositoryInterface::class, PageRepository::class);
} }
} }

View file

@ -0,0 +1,53 @@
<?php
namespace App\Repositories;
use App\Interfaces\PageRepositoryInterface;
use App\Services\SettingsService;
use App\Services\ContentService;
use App\Services\PaginateService;
class PageRepository implements PageRepositoryInterface
{
protected $content;
protected $setttings;
protected $paginate;
protected $pages;
public function __construct(
ContentService $contentService,
SettingsService $settingsService,
PaginateService $paginateService
) {
$this->content = $contentService;
$this->settings = $settingsService;
$this->paginate = $paginateService;
$this->pages = $this->content->loadAllPages();
}
public function getAll()
{
return $this->pages;
}
public function getById($uuid)
{
}
public function delete($uuid)
{
}
public function create(array $page)
{
}
public function update($uuid, array $page)
{
}
public function getGroup($num, $limit, $sort = "all")
{
return $this->paginate->getPage($num, $limit, $sort);
}
}

View file

@ -28,5 +28,6 @@ Route::post("/login", [AuthController::class, 'enter']);
Route::group(['prefix' => 'dashboard'], function () { Route::group(['prefix' => 'dashboard'], function () {
Route::get("/", [DashController::class, 'start']); Route::get("/", [DashController::class, 'start']);
Route::get("/pages/{pageFilter?}/{pageNum?}", [DashController::class, 'book']); Route::get("/pages/{pageFilter?}/{pageNum?}", [DashController::class, 'book']);
Route::get("/page/{uuid}", [DashController::class, 'page']);
Route::get("/logout", [AuthController::class, 'exit']); Route::get("/logout", [AuthController::class, 'exit']);
}); });