First commit for project
This commit is contained in:
37
app/Repository/CategoryRepository.php
Normal file
37
app/Repository/CategoryRepository.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Http\Resources\CategoryCollection;
|
||||
use App\Http\Resources\CategoryResource;
|
||||
use App\Models\Category;
|
||||
use App\Repository\Interfaces\CategoryRepository as CategoryRepositoryInterface;
|
||||
|
||||
class CategoryRepository implements CategoryRepositoryInterface
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
private Category $category
|
||||
) {}
|
||||
|
||||
public function all()
|
||||
{
|
||||
$categories = $this->category
|
||||
->query()
|
||||
->orderby('priority', 'ASC')
|
||||
->orderby('name', 'ASC')->get();
|
||||
return (new CategoryCollection($categories))->collection;
|
||||
}
|
||||
|
||||
public function get(string $slug)
|
||||
{
|
||||
$category = $this->category
|
||||
->query()
|
||||
->where('slug', $slug)
|
||||
->firstOrFail();
|
||||
return new CategoryResource($category);
|
||||
}
|
||||
|
||||
}
|
13
app/Repository/Interfaces/CategoryRepository.php
Normal file
13
app/Repository/Interfaces/CategoryRepository.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Repository\Interfaces;
|
||||
|
||||
interface CategoryRepository
|
||||
{
|
||||
|
||||
public function all();
|
||||
public function get(string $slug);
|
||||
|
||||
}
|
13
app/Repository/Interfaces/ProjectRepository.php
Normal file
13
app/Repository/Interfaces/ProjectRepository.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Repository\Interfaces;
|
||||
|
||||
interface ProjectRepository
|
||||
{
|
||||
|
||||
public function all();
|
||||
public function get(int $id);
|
||||
|
||||
}
|
37
app/Repository/ProjectRepository.php
Normal file
37
app/Repository/ProjectRepository.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Http\Resources\ProjectCollection;
|
||||
use App\Http\Resources\ProjectResource;
|
||||
use App\Models\Project;
|
||||
use App\Repository\Interfaces\ProjectRepository as ProjectRepositoryInterface;
|
||||
|
||||
class ProjectRepository implements ProjectRepositoryInterface
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
private Project $project
|
||||
) {}
|
||||
|
||||
public function all()
|
||||
{
|
||||
$project = $this->project
|
||||
->query()
|
||||
->orderBy('release_data', 'ASC')
|
||||
->get();
|
||||
return (new ProjectCollection($project))->collection;
|
||||
}
|
||||
|
||||
public function get(int $id)
|
||||
{
|
||||
$project = $this->project
|
||||
->query()
|
||||
->find($id)
|
||||
->first();
|
||||
return new ProjectResource($project);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user