diff --git a/app/Http/Controllers/PublicController.php b/app/Http/Controllers/PublicController.php index abf6138..f7e9ff8 100644 --- a/app/Http/Controllers/PublicController.php +++ b/app/Http/Controllers/PublicController.php @@ -23,6 +23,23 @@ class PublicController extends BaseController use AuthorizesRequests, DispatchesJobs, ValidatesRequests; + public function listGalleriesViewAPI($name, Request $request) { + $data = []; + $tenant = Tenant::query()->where("url", "=", $name)->firstOrFail(); + $galleries = Gallery::query() + ->where("tenant", "=", $tenant->id) + ->where("status", "=", "online") + ->where("listed", "=", 1) + ->orderByDesc("gallery_create_time") + ->orderByDesc("created_at") + ->get(); + $parser = new \Parsedown(); + foreach ($galleries as $gallery) { + $gallery->html = $parser->parse($gallery->description); + } + + return response()->json(["data" => \App\Http\Resources\Gallery::collection(collect($galleries))]); + } public function listGalleriesView($name, Request $request) { $tenant = Tenant::query()->where("url", "=", $name)->firstOrFail(); $galleries = Gallery::query() diff --git a/app/Http/Resources/Gallery.php b/app/Http/Resources/Gallery.php new file mode 100644 index 0000000..aeb21ac --- /dev/null +++ b/app/Http/Resources/Gallery.php @@ -0,0 +1,36 @@ +id; + $data["name"] = $this->name; + $data["created"] = $this->gallery_create_time; + $data["url"] = [ + "name" => $this->url, + "url" => url("/".$this->getTenant()->url."/".$this->url)]; + $data["mainImage"] = [ + "id" => $this->main_image, + "url" => [ + "small" => url("/".$this->getTenant()->url."/".$this->url."/".$this->main_image."/file?size=small"), + "medium" => url("/".$this->getTenant()->url."/".$this->url."/".$this->main_image."/file?size=medium"), + "big" => url("/".$this->getTenant()->url."/".$this->url."/".$this->main_image."/file?size=big") + ]]; + $data["description"] = $this->description; + $data["tags"] = json_decode($this->tags); + return $data; + #return parent::toArray($request); + } +} diff --git a/app/Models/Gallery.php b/app/Models/Gallery.php index 86b3298..3a3269c 100644 --- a/app/Models/Gallery.php +++ b/app/Models/Gallery.php @@ -45,4 +45,9 @@ class Gallery extends Authenticatable public static function getByTenantAndUrl($tenant_id, $url) { return Gallery::query()->where("tenant", "=", $tenant_id)->where("url", "=", $url)->first(); } + + public function getTenant() { + $tenant = Tenant::query()->where("id", "=", $this->tenant)->firstOrFail(); + return $tenant; + } } diff --git a/routes/web.php b/routes/web.php index dd2a0aa..d1d7928 100644 --- a/routes/web.php +++ b/routes/web.php @@ -60,8 +60,10 @@ Route::middleware([\App\Http\Middleware\TenanMiddleware::class, \App\Http\Middle Route::post("a/themes", [\App\Http\Controllers\AdminController::class, "themesSettings"]); }); +Route::get("/{name}.json", [\App\Http\Controllers\PublicController::class, 'listGalleriesViewAPI'])->middleware([\App\Http\Middleware\TenanMiddleware::class]); Route::get("/{name}", [\App\Http\Controllers\PublicController::class, 'listGalleriesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]); Route::get("/{tenant}/{gallery}", [\App\Http\Controllers\PublicController::class, 'listGalleryImagesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]); +Route::get("/{tenant}/{gallery}.json", [\App\Http\Controllers\PublicController::class, 'listGalleryImagesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]); Route::get("/{tenant}/{gallery}/{image}/file", [\App\Http\Controllers\PublicController::class, 'returnImageFile']);