This repository was archived by the owner on Jan 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathShelfController.php
More file actions
52 lines (43 loc) · 1.49 KB
/
ShelfController.php
File metadata and controls
52 lines (43 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace App\Http\Controllers\API;
use App\Repositories\ShelfRepository;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class ShelfController extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
private $repository;
public function __construct(ShelfRepository $repository)
{
$this->repository = $repository;
}
public function getBooks($shelf_slug){
$shelf = $this->repository->findShelfViaSlug($shelf_slug);
if(empty($shelf)){
return response()->json(['message'=>'slug invaild'], 404);
}
/* @var \Illuminate\Support\Collection */
$books = $this->repository->grabBooksFromShelf($shelf);
$data = $books->transform(function ($book){
return [
'name' => $book->name,
'isbn' => $book->isbn,
'id' => $book->book_id,
];
})->all();
return response()->json($data);
}
public function getAllShelives(){
$shelvies = $this->repository->getAllShelvies();
$data = $shelvies->transform(function ($shelf){
return [
'name' => $shelf->name,
'slug' => $shelf->slug,
'id' => $shelf->shelf_id,
];
})->all();
return response()->json($data);
}
}