-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
48cfbb1
commit c6c231f
Showing
25 changed files
with
1,086 additions
and
250 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,4 @@ yarn-error.log | |
!/storage/framework/testing | ||
!/storage/framework/views | ||
bun.lockb | ||
data | ||
public/content |
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,40 @@ | ||
<?php | ||
|
||
namespace App\Http\Views; | ||
|
||
use App\Http\Resources\BookResource; | ||
use App\Interfaces\ViewProvider; | ||
use App\Models\Book; | ||
use App\Models\Series; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Http\Request; | ||
|
||
class SeriesViewProvider extends ViewProvider | ||
{ | ||
protected ?string $view = "books"; | ||
private Series $series; | ||
|
||
public function __construct(int $id) | ||
{ | ||
$series = Series::find($id); | ||
|
||
if ($series === null) { | ||
throw new \RuntimeException("Shelf with id $id not found"); | ||
} | ||
|
||
$this->series = $series; | ||
} | ||
|
||
public function toArray(Request $request): array | ||
{ | ||
$books = Book::whereHas("serieses", function (Builder $query) { | ||
$query->where("series.id", "=", $this->series->id); | ||
}) | ||
->get(); | ||
|
||
return [ | ||
"books" => BookResource::collection($books)->toArray($request), | ||
"title" => "Books in " . $this->series->name, | ||
]; | ||
} | ||
} |
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 | ||
|
||
namespace App\Http\Views; | ||
|
||
use App\Interfaces\ViewProvider; | ||
use App\Models\Book; | ||
use App\Models\Series; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Database\Eloquent\Collection; | ||
use Illuminate\Http\Request; | ||
|
||
class SeriesesViewProvider extends ViewProvider | ||
{ | ||
protected ?string $view = "serieses"; | ||
|
||
public function toArray(Request $request): array | ||
{ | ||
return [ | ||
"serieses" => Series::all() | ||
->map(function (Series $series) { | ||
$book = Book::whereHas("serieses", function (Builder $query) use ($series) { | ||
$query->where("series.id", "=", $series->id); | ||
}) | ||
->first(); | ||
|
||
return [ | ||
"authors" => $book->authors | ||
->map(fn($author) => $author->name) | ||
->implode(", "), | ||
|
||
"name" => $series->name, | ||
"id" => $series->id, | ||
"cover" => "/content/$book->path/cover.jpg", | ||
]; | ||
}) | ||
->toArray() | ||
]; | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
namespace App\Http\Views; | ||
|
||
use App\Http\Resources\BookResource; | ||
use App\Interfaces\ViewProvider; | ||
use App\Models\Book; | ||
use App\Models\Shelf; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Http\Request; | ||
|
||
class ShelfViewProvider extends ViewProvider | ||
{ | ||
protected ?string $view = "books"; | ||
private Shelf $shelf; | ||
|
||
public function __construct(int $id) | ||
{ | ||
$shelf = Shelf::find($id); | ||
|
||
if ($shelf === null) { | ||
throw new \RuntimeException("Shelf with id $id not found"); | ||
} | ||
|
||
$this->shelf = $shelf; | ||
} | ||
|
||
public function toArray(Request $request): array | ||
{ | ||
$books = Book::whereHas("shelves", function (Builder $query) { | ||
$query->where("calibuh_shelves.id", "=", $this->shelf->id); | ||
}) | ||
->get(); | ||
|
||
return [ | ||
"books" => BookResource::collection($books)->toArray($request), | ||
"title" => "Books in shelf " . $this->shelf->name, | ||
]; | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
|
||
namespace App\Http\Views; | ||
|
||
use App\Http\Resources\BookResource; | ||
use App\Interfaces\ViewProvider; | ||
use App\Models\Book; | ||
use App\Models\Shelf; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Http\Request; | ||
|
||
class ShelvesViewProvider extends ViewProvider | ||
{ | ||
protected ?string $view = "shelves"; | ||
|
||
public function toArray(Request $request): array | ||
{ | ||
return [ | ||
"shelves" => Shelf::all() | ||
->map(function (Shelf $shelf) use ($request) { | ||
$books = Book::whereHas("shelves", function (Builder $query) use ($shelf) { | ||
$query->where("calibuh_shelves.id", "=", $shelf->id); | ||
}) | ||
->get(); | ||
|
||
return [ | ||
"books" => BookResource::collection($books)->toArray($request), | ||
"name" => $shelf->name, | ||
"id" => $shelf->id, | ||
"cover" => "/content/" . $books->first()->path ."/cover.jpg", | ||
]; | ||
}) | ||
->toArray() | ||
]; | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
|
||
namespace App\Interfaces; | ||
|
||
use Illuminate\Contracts\Support\Responsable; | ||
use Illuminate\Contracts\View\Factory; | ||
use Illuminate\Contracts\View\View; | ||
use Illuminate\Foundation\Application; | ||
use Illuminate\Http\Request; | ||
|
||
|
||
abstract class ViewProvider implements Responsable | ||
{ | ||
protected ?string $view = null; | ||
|
||
/** | ||
* Transform the resource collection into an array. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public abstract function toArray(Request $request): array; | ||
|
||
/** | ||
* Create an HTTP response that represents the object. | ||
* | ||
* @param Request $request | ||
*/ | ||
public function toResponse($request): View|Factory|Application | ||
{ | ||
if ($this->view === null) { | ||
throw new \LogicException('$view should be set when extending ViewProvider'); | ||
} | ||
|
||
return view($this->view, $this->toArray($request)); | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
/** | ||
* | ||
* | ||
* @property int|null $id the author's name | ||
* @property string $name the name of the author in a sortable manner | ||
* @property string|null $sort | ||
* @property string $link ?? | ||
* @method static \Illuminate\Database\Eloquent\Builder|Author newModelQuery() | ||
* @method static \Illuminate\Database\Eloquent\Builder|Author newQuery() | ||
* @method static \Illuminate\Database\Eloquent\Builder|Author query() | ||
* @method static \Illuminate\Database\Eloquent\Builder|Author whereId($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|Author whereLink($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|Author whereName($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|Author whereSort($value) | ||
* @mixin \Eloquent | ||
*/ | ||
class Author extends Model | ||
{ | ||
/** | ||
* The table associated with the model. | ||
* | ||
* @var string | ||
*/ | ||
protected $table = "authors"; | ||
|
||
/** | ||
* Indicates if the model should be timestamped. | ||
* | ||
* @var bool | ||
*/ | ||
public $timestamps = 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
Oops, something went wrong.