From 64525fcb0b81c9231f9d67b00c5e8a51965d514b Mon Sep 17 00:00:00 2001 From: merdan Date: Wed, 27 Oct 2021 21:06:17 +0500 Subject: [PATCH] Channels list with sliders --- composer.json | 3 +- config/app.php | 2 ++ .../Sarga/API/Http/Controllers/Channels.php | 36 +++++++++++++++++++ .../API/Http/Resources/Catalog/Category.php | 36 +++++++++++++++++++ .../Sarga/API/Http/Resources/Core/Channel.php | 32 +++++++++++++++++ .../Sarga/API/Http/Resources/Core/Slider.php | 27 ++++++++++++++ packages/Sarga/API/Http/routes.php | 10 ++++++ .../API/Providers/APIServiceProvider.php | 17 +++++++++ packages/Sarga/API/composer.json | 30 ++++++++++++++++ packages/Sarga/Shop/src/Models/Channel.php | 11 ++++++ .../Shop/src/Models/ChannelTranslation.php | 9 +++++ .../src/Repositories/ChannelRepository.php | 14 ++++++++ .../API/Http/Resources/Checkout/Cart.php | 2 +- .../Webkul/API/Http/Resources/Sales/Order.php | 2 +- packages/Webkul/API/Http/routes.php | 6 ++-- 15 files changed, 231 insertions(+), 6 deletions(-) create mode 100644 packages/Sarga/API/Http/Controllers/Channels.php create mode 100644 packages/Sarga/API/Http/Resources/Catalog/Category.php create mode 100644 packages/Sarga/API/Http/Resources/Core/Channel.php create mode 100644 packages/Sarga/API/Http/Resources/Core/Slider.php create mode 100644 packages/Sarga/API/Http/routes.php create mode 100644 packages/Sarga/API/Providers/APIServiceProvider.php create mode 100644 packages/Sarga/API/composer.json create mode 100644 packages/Sarga/Shop/src/Models/Channel.php create mode 100644 packages/Sarga/Shop/src/Models/ChannelTranslation.php create mode 100644 packages/Sarga/Shop/src/Repositories/ChannelRepository.php diff --git a/composer.json b/composer.json index ef0fa5042..6bcc8e1ac 100755 --- a/composer.json +++ b/composer.json @@ -105,7 +105,8 @@ "Webkul\\SocialLogin\\": "packages/Webkul/SocialLogin/src", "Webkul\\DebugBar\\": "packages/Webkul/DebugBar/src", "Webkul\\Marketing\\": "packages/Webkul/Marketing/src", - "Sarga\\Shop\\": "packages/Sarga/Shop/src" + "Sarga\\Shop\\": "packages/Sarga/Shop/src", + "Sarga\\API\\": "packages/Sarga/API" } }, "autoload-dev": { diff --git a/config/app.php b/config/app.php index cc79426c2..d0674a98f 100755 --- a/config/app.php +++ b/config/app.php @@ -282,6 +282,8 @@ return [ Webkul\SocialLogin\Providers\SocialLoginServiceProvider::class, Webkul\DebugBar\Providers\DebugBarServiceProvider::class, Webkul\Marketing\Providers\MarketingServiceProvider::class, + Sarga\Shop\Providers\ShopServiceProvider::class, + Sarga\API\Providers\APIServiceProvider::class ], /* diff --git a/packages/Sarga/API/Http/Controllers/Channels.php b/packages/Sarga/API/Http/Controllers/Channels.php new file mode 100644 index 000000000..e9d6d14f3 --- /dev/null +++ b/packages/Sarga/API/Http/Controllers/Channels.php @@ -0,0 +1,36 @@ +channelRepository = $channelRepository; + + } + + public function index() + { + + $channels = $this->channelRepository->with('sliders')->get(); + + if($channels) + { + return Channel::collection($channels); + } + else + { + return response()->json(['not found'],404); + } + } + + public function get($channel_id){ + $this->categoryRepository->getVisibleCategoryTree(request()->input('parent_id')); + } + +} \ No newline at end of file diff --git a/packages/Sarga/API/Http/Resources/Catalog/Category.php b/packages/Sarga/API/Http/Resources/Catalog/Category.php new file mode 100644 index 000000000..88dde44c6 --- /dev/null +++ b/packages/Sarga/API/Http/Resources/Catalog/Category.php @@ -0,0 +1,36 @@ + $this->id, + 'code' => $this->code, + 'name' => $this->name, + 'slug' => $this->slug, + 'display_mode' => $this->display_mode, + 'description' => $this->description, + 'status' => $this->status, + 'image_url' => $this->image_url, + 'category_icon_path' => $this->category_icon_path + ? Storage::url($this->category_icon_path) + : null, + 'additional' => is_array($this->resource->additional) + ? $this->resource->additional + : json_decode($this->resource->additional, true), + + ]; + } +} diff --git a/packages/Sarga/API/Http/Resources/Core/Channel.php b/packages/Sarga/API/Http/Resources/Core/Channel.php new file mode 100644 index 000000000..e8bd2c3b7 --- /dev/null +++ b/packages/Sarga/API/Http/Resources/Core/Channel.php @@ -0,0 +1,32 @@ + $this->id, + 'code' => $this->code, + 'name' => $this->name, + 'hostname' => $this->hostname, + 'root_category_id' => $this->root_category_id, + 'is_maintenance_on' => $this->is_maintenance_on, + 'sliders' => Slider::collection($this->sliders) +// 'root_category' => $this->when($this->root_category_id, new CategoryResource($this->root_category)), +// 'main_categories' => $this->when(request()->has('channel_id'),Category::collection($this->categories)) + + ]; + } +} \ No newline at end of file diff --git a/packages/Sarga/API/Http/Resources/Core/Slider.php b/packages/Sarga/API/Http/Resources/Core/Slider.php new file mode 100644 index 000000000..dd3e38b7f --- /dev/null +++ b/packages/Sarga/API/Http/Resources/Core/Slider.php @@ -0,0 +1,27 @@ + $this->id, + 'title' => $this->title, + 'image_url' => $this->image_url, + 'content' => $this->content, + 'expired_at'=> $this->expired_at, + 'sort_order'=> $this->sort_order, + 'slider_path'=>$this->slider_path + ]; + } +} \ No newline at end of file diff --git a/packages/Sarga/API/Http/routes.php b/packages/Sarga/API/Http/routes.php new file mode 100644 index 000000000..b16d0eb23 --- /dev/null +++ b/packages/Sarga/API/Http/routes.php @@ -0,0 +1,10 @@ + 'api'], function ($router) { + Route::group(['middleware' => ['locale', 'currency']], function ($router) { + //Channel routes + Route::get('channels',[Channels::class, 'index']); + Route::get('channels/{channel_id}',[Channels::class, 'get']); + }); +}); diff --git a/packages/Sarga/API/Providers/APIServiceProvider.php b/packages/Sarga/API/Providers/APIServiceProvider.php new file mode 100644 index 000000000..12096e054 --- /dev/null +++ b/packages/Sarga/API/Providers/APIServiceProvider.php @@ -0,0 +1,17 @@ +loadRoutesFrom(__DIR__.'/../Http/routes.php'); + } +} \ No newline at end of file diff --git a/packages/Sarga/API/composer.json b/packages/Sarga/API/composer.json new file mode 100644 index 000000000..e1a3340c5 --- /dev/null +++ b/packages/Sarga/API/composer.json @@ -0,0 +1,30 @@ +{ + "name": "sarga/api", + "description": "API for Sarga.", + "license": "MIT", + + "authors": [ + { + "name": "merdan muhammedow", + "email": "merdan.m@gmail.com" + } + ], + + "require": {}, + "autoload": { + "psr-4": { + "Sarga\\Shop\\": "src/" + } + }, + + "extra": { + "laravel": { + "providers": [ + "Sarga\\API\\Providers\\APIerviceProvider" + ], + "aliases": {} + } + }, + + "minimum-stability": "dev" +} diff --git a/packages/Sarga/Shop/src/Models/Channel.php b/packages/Sarga/Shop/src/Models/Channel.php new file mode 100644 index 000000000..70717affd --- /dev/null +++ b/packages/Sarga/Shop/src/Models/Channel.php @@ -0,0 +1,11 @@ +hasMany(SliderProxy::modelClass()); + } +} \ No newline at end of file diff --git a/packages/Sarga/Shop/src/Models/ChannelTranslation.php b/packages/Sarga/Shop/src/Models/ChannelTranslation.php new file mode 100644 index 000000000..fe7de38d7 --- /dev/null +++ b/packages/Sarga/Shop/src/Models/ChannelTranslation.php @@ -0,0 +1,9 @@ + 'api'], function ($router) { //Channel routes Route::get('channels', [ResourceController::class, 'index'])->defaults('_config', [ 'repository' => ChannelRepository::class, - 'resource' => Channel::class, + 'resource' => ChannelResource::class, ]); Route::get('channels/{id}', [ResourceController::class, 'get'])->defaults('_config', [ 'repository' => ChannelRepository::class, - 'resource' => Channel::class, + 'resource' => ChannelResource::class, ]);