Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
135 additions
and
12 deletions.
There are no files selected for viewing
4 changes: 3 additions & 1 deletion
4
src/Containers/DirectorySection/Directory/Configs/admin-kit.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
return [ | ||
'directories' => [], | ||
'directories' => [ | ||
'enable_routes' => false, | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/Containers/DirectorySection/Directory/UI/API/Controllers/DirectoryController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AdminKit\Core\Containers\DirectorySection\Directory\UI\API\Controllers; | ||
|
||
use AdminKit\Core\Containers\DirectorySection\Directory\UI\API\Repositories\DirectoryInterface; | ||
|
||
class DirectoryController | ||
{ | ||
public function __construct( | ||
public DirectoryInterface $repository, | ||
) { | ||
} | ||
|
||
public function index() | ||
{ | ||
return $this->repository->getListAll(); | ||
} | ||
|
||
public function listBySlug(string $slug) | ||
{ | ||
return $this->repository->getListBySlug($slug); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Containers/DirectorySection/Directory/UI/API/DTO/DirectoryDTO.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AdminKit\Core\Containers\DirectorySection\Directory\UI\API\DTO; | ||
|
||
use Spatie\LaravelData\Attributes\DataCollectionOf; | ||
use Spatie\LaravelData\Attributes\MapInputName; | ||
use Spatie\LaravelData\Data; | ||
use Spatie\LaravelData\DataCollection; | ||
|
||
class DirectoryDTO extends Data | ||
{ | ||
public function __construct( | ||
public int $id, | ||
public string $slug, | ||
public string $name, | ||
#[DataCollectionOf(RecordDTO::class), MapInputName('children')] | ||
public DataCollection $records, | ||
) { | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Containers/DirectorySection/Directory/UI/API/DTO/RecordDTO.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AdminKit\Core\Containers\DirectorySection\Directory\UI\API\DTO; | ||
|
||
use Spatie\LaravelData\Data; | ||
|
||
class RecordDTO extends Data | ||
{ | ||
public function __construct( | ||
public int $id, | ||
public string $name, | ||
) { | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Containers/DirectorySection/Directory/UI/API/Repositories/DirectoryInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AdminKit\Core\Containers\DirectorySection\Directory\UI\API\Repositories; | ||
|
||
use AdminKit\Core\Repositories\RepositoryInterface; | ||
use Spatie\LaravelData\DataCollection; | ||
|
||
interface DirectoryInterface extends RepositoryInterface | ||
{ | ||
public function getListAll(): DataCollection; | ||
|
||
public function getListBySlug($slug): DataCollection; | ||
} |
39 changes: 39 additions & 0 deletions
39
src/Containers/DirectorySection/Directory/UI/API/Repositories/DirectoryRepository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AdminKit\Core\Containers\DirectorySection\Directory\UI\API\Repositories; | ||
|
||
use AdminKit\Core\Containers\DirectorySection\Directory\Models\Directory; | ||
use AdminKit\Core\Containers\DirectorySection\Directory\UI\API\DTO\DirectoryDTO; | ||
use AdminKit\Core\Containers\DirectorySection\Directory\UI\API\DTO\RecordDTO; | ||
use AdminKit\Core\Repositories\AbstractRepository; | ||
use Spatie\LaravelData\DataCollection; | ||
|
||
class DirectoryRepository extends AbstractRepository implements DirectoryInterface | ||
{ | ||
public function model(): string | ||
{ | ||
return Directory::class; | ||
} | ||
|
||
public function getListAll(): DataCollection | ||
{ | ||
$directories = $this->model | ||
->defaultOrder() | ||
->get() | ||
->toTree(); | ||
|
||
return DirectoryDTO::collection($directories); | ||
} | ||
|
||
public function getListBySlug($slug): DataCollection | ||
{ | ||
$directories = $this->model | ||
->initial($slug) | ||
->defaultOrder() | ||
->get(); | ||
|
||
return RecordDTO::collection($directories); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Containers/DirectorySection/Directory/UI/API/Routes/api.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
use AdminKit\Core\Containers\DirectorySection\Directory\UI\API\Controllers\DirectoryController; | ||
use Illuminate\Support\Facades\Route; | ||
|
||
if (config('admin-kit.directories.enable_routes')) { | ||
Route::get('/directories', [DirectoryController::class, 'index']); | ||
Route::get('/directories/{slug}', [DirectoryController::class, 'listBySlug']); | ||
} |