From 9dacdd3557a5165ebe2ad4ab5e553203acca112e Mon Sep 17 00:00:00 2001 From: Shohrat Date: Wed, 8 Mar 2023 20:49:30 +0000 Subject: [PATCH] apis --- config/database.php | 6 +- .../api/CategoriesAPIController.php | 138 ++++----- .../controllers/api/ProductAPIController.php | 268 +++++++++--------- .../controllers/api/SliderAPIController.php | 94 +++--- plugins/ahmadfatoni/apigenerator/routes.php | 50 ++-- 5 files changed, 286 insertions(+), 270 deletions(-) diff --git a/config/database.php b/config/database.php index 06c985da..c830c63c 100644 --- a/config/database.php +++ b/config/database.php @@ -57,9 +57,9 @@ return [ 'engine' => 'InnoDB', 'host' => 'localhost', 'port' => 3306, - 'database' => 'sapaly_git', - 'username' => 'root', - 'password' => '', + 'database' => 'sapaly_october', + 'username' => 'sapaly', + 'password' => '22MOcP6^I#8tI5ovcXluXDT#%vWC^CtsFvKHOygi8TMnzaMuLYx@123', 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/CategoriesAPIController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/CategoriesAPIController.php index 9353e6a0..5024fcde 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/CategoriesAPIController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/CategoriesAPIController.php @@ -1,68 +1,72 @@ -Category = $Category; - $this->helpers = $helpers; - } - - public function index(){ - - $data = $this->Category - ->select("id", "name", "slug") - ->orderBy("nest_left", "asc") - ->with('translations:locale,model_id,attribute_data') - ->where("nest_depth", 0) - ->active() - ->get(); - - return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); - } - - public function GetParent($id){ - - $data = $this->Category - ->select("id", "name", "slug") - ->orderBy("nest_left", "asc") - ->with('translations:locale,model_id,attribute_data') - ->where("parent_id", $id) - ->active() - ->get(); - - return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); - } - - public function show($id){ - - $data = $this->Category::find($id); - - if ($data){ - return $this->helpers->apiArrayResponseBuilder(200, 'success', [$data]); - } else { - $this->helpers->apiArrayResponseBuilder(404, 'not found', ['error' => 'Resource id=' . $id . ' could not be found']); - } - - } - - public static function getAfterFilters() {return [];} - public static function getBeforeFilters() {return [];} - public static function getMiddleware() {return [];} - public function callAction($method, $parameters=false) { - return call_user_func_array(array($this, $method), $parameters); - } - +Category = $Category; + $this->helpers = $helpers; + } + + public function index(){ + + $data = $this->Category + ->select("id", "name", "slug") + ->orderBy("nest_left", "asc") + ->with('translations:locale,model_id,attribute_data') + ->with('icon') + ->with('preview_image') + ->where("nest_depth", 0) + ->active() + ->get(); + + return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); + } + + public function GetParent($id){ + + $data = $this->Category + ->select("id", "name", "slug") + ->orderBy("nest_left", "asc") + ->with('translations:locale,model_id,attribute_data') + ->with('icon') + ->with('preview_image') + ->where("parent_id", $id) + ->active() + ->get(); + + return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); + } + + public function show($id){ + + $data = $this->Category::find($id); + + if ($data){ + return $this->helpers->apiArrayResponseBuilder(200, 'success', [$data]); + } else { + $this->helpers->apiArrayResponseBuilder(404, 'not found', ['error' => 'Resource id=' . $id . ' could not be found']); + } + + } + + public static function getAfterFilters() {return [];} + public static function getBeforeFilters() {return [];} + public static function getMiddleware() {return [];} + public function callAction($method, $parameters=false) { + return call_user_func_array(array($this, $method), $parameters); + } + } \ No newline at end of file diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/ProductAPIController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/ProductAPIController.php index 080eb56d..75a0070b 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/ProductAPIController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/ProductAPIController.php @@ -1,130 +1,140 @@ -Product = $Product; - $this->helpers = $helpers; - } - - public function index(){ - - $data = $this->Product - ->select("id", "name", "slug", "category_id", "featured") - ->with('translations:locale,model_id,attribute_data') - // ->with(['category' => function ($query) { - // $query->with('translations:locale,model_id,attribute_data'); - // }]) - ->active() - ->paginate(10); - - if($data) { - $data->each(function ($item, $key) { - $item->icon = $this->pageUrl('index') . \Config::get('cms.storage.media.path') . $item->icon; - }); - } - - return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); - } - - public function ByCatId($id){ - - $data = $this->Product - ->select("id", "name", "slug", "category_id", "featured") - ->with('translations:locale,model_id,attribute_data') - ->where("category_id", $id) - ->active() - ->paginate(10); - - return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); - } - - - public function show($id){ - - $data = $this->Product::with('translations:locale,model_id,attribute_data') - ->with(['category' => function ($query) { - $query->with('translations:locale,model_id,attribute_data'); - }]) - ->find($id); - - - if ($data){ - return $this->helpers->apiArrayResponseBuilder(200, 'success', [$data]); - } else { - $this->helpers->apiArrayResponseBuilder(404, 'not found', ['error' => 'Resource id=' . $id . ' could not be found']); - } - - } - - // public function store(Request $request){ - - // $arr = $request->all(); - - // while ( $data = current($arr)) { - // $this->Product->{key($arr)} = $data; - // next($arr); - // } - - // $validation = Validator::make($request->all(), $this->Product->rules); - - // if( $validation->passes() ){ - // $this->Product->save(); - // return $this->helpers->apiArrayResponseBuilder(201, 'created', ['id' => $this->Product->id]); - // }else{ - // return $this->helpers->apiArrayResponseBuilder(400, 'fail', $validation->errors() ); - // } - - // } - - // public function update($id, Request $request){ - - // $status = $this->Product->where('id',$id)->update($data); - - // if( $status ){ - - // return $this->helpers->apiArrayResponseBuilder(200, 'success', 'Data has been updated successfully.'); - - // }else{ - - // return $this->helpers->apiArrayResponseBuilder(400, 'bad request', 'Error, data failed to update.'); - - // } - // } - - // public function delete($id){ - - // $this->Product->where('id',$id)->delete(); - - // return $this->helpers->apiArrayResponseBuilder(200, 'success', 'Data has been deleted successfully.'); - // } - - // public function destroy($id){ - - // $this->Product->where('id',$id)->delete(); - - // return $this->helpers->apiArrayResponseBuilder(200, 'success', 'Data has been deleted successfully.'); - // } - - - public static function getAfterFilters() {return [];} - public static function getBeforeFilters() {return [];} - public static function getMiddleware() {return [];} - public function callAction($method, $parameters=false) { - return call_user_func_array(array($this, $method), $parameters); - } - +Product = $Product; + $this->helpers = $helpers; + } + + public function index(){ + + $data = $this->Product + ->select("id", "name", "slug", "category_id", "featured", "description") + //->with(['preview_image' => function ($query) { + // $query->select("id", "path"); + // }]) + ->with('preview_image') + //->with('offer:id,main_price') + //->with('images') + ->with('translations:locale,model_id,attribute_data') + ->with(['offer' => function ($query) { + $query->with('main_price'); + }]) + ->active() + ->paginate(10); + + if($data) { + $data->each(function ($item, $key) { + $item->icon = $this->pageUrl('index') . \Config::get('cms.storage.media.path') . $item->icon; + }); + } + + return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); + } + + public function ByCatId($id){ + + $data = $this->Product + ->select("id", "name", "slug", "category_id", "featured") + ->with('preview_image') + ->with('translations:locale,model_id,attribute_data') + ->where("category_id", $id) + ->with(['offer' => function ($query) { + $query->with('main_price'); + }]) + ->active() + ->paginate(10); + + return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); + } + + + public function show($id){ + + $data = $this->Product::with('translations:locale,model_id,attribute_data') + ->with(['category' => function ($query) { + $query->with('translations:locale,model_id,attribute_data'); + }]) + ->find($id); + + + if ($data){ + return $this->helpers->apiArrayResponseBuilder(200, 'success', [$data]); + } else { + $this->helpers->apiArrayResponseBuilder(404, 'not found', ['error' => 'Resource id=' . $id . ' could not be found']); + } + + } + + // public function store(Request $request){ + + // $arr = $request->all(); + + // while ( $data = current($arr)) { + // $this->Product->{key($arr)} = $data; + // next($arr); + // } + + // $validation = Validator::make($request->all(), $this->Product->rules); + + // if( $validation->passes() ){ + // $this->Product->save(); + // return $this->helpers->apiArrayResponseBuilder(201, 'created', ['id' => $this->Product->id]); + // }else{ + // return $this->helpers->apiArrayResponseBuilder(400, 'fail', $validation->errors() ); + // } + + // } + + // public function update($id, Request $request){ + + // $status = $this->Product->where('id',$id)->update($data); + + // if( $status ){ + + // return $this->helpers->apiArrayResponseBuilder(200, 'success', 'Data has been updated successfully.'); + + // }else{ + + // return $this->helpers->apiArrayResponseBuilder(400, 'bad request', 'Error, data failed to update.'); + + // } + // } + + // public function delete($id){ + + // $this->Product->where('id',$id)->delete(); + + // return $this->helpers->apiArrayResponseBuilder(200, 'success', 'Data has been deleted successfully.'); + // } + + // public function destroy($id){ + + // $this->Product->where('id',$id)->delete(); + + // return $this->helpers->apiArrayResponseBuilder(200, 'success', 'Data has been deleted successfully.'); + // } + + + public static function getAfterFilters() {return [];} + public static function getBeforeFilters() {return [];} + public static function getMiddleware() {return [];} + public function callAction($method, $parameters=false) { + return call_user_func_array(array($this, $method), $parameters); + } + } \ No newline at end of file diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/SliderAPIController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/SliderAPIController.php index 9cd5d820..bf4d67bf 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/SliderAPIController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/SliderAPIController.php @@ -1,47 +1,49 @@ -Slider = $Slider; - $this->helpers = $helpers; - } - - public function index(){ - - $data = $this->Slider - ->select("id", "img") - ->with('translations:locale,model_id,attribute_data') - ->get(); - - if($data) { - $data->each(function ($item, $key) { - $item->img = $this->pageUrl('index') . \Config::get('cms.storage.media.path') . $item->img; - }); - } - - return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); - } - - - public static function getAfterFilters() {return [];} - public static function getBeforeFilters() {return [];} - public static function getMiddleware() {return [];} - public function callAction($method, $parameters=false) { - return call_user_func_array(array($this, $method), $parameters); - } - +Slider = $Slider; + $this->helpers = $helpers; + } + + public function index(){ + $path = Config::get('app.cdn').Config::get('cms.storage.media.path'); + + $data = $this->Slider + ->select("id", "img") + ->with('translations:locale,model_id,attribute_data') + ->get(); + + if($data) { + $data->each(function ($item, $key) { + $item->img = "http://sapalymahabat.com.tm" . \Config::get('cms.storage.media.path') . $item->img; + }); + } + + return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); + } + + + public static function getAfterFilters() {return [];} + public static function getBeforeFilters() {return [];} + public static function getMiddleware() {return [];} + public function callAction($method, $parameters=false) { + return call_user_func_array(array($this, $method), $parameters); + } + } \ No newline at end of file diff --git a/plugins/ahmadfatoni/apigenerator/routes.php b/plugins/ahmadfatoni/apigenerator/routes.php index 4fc4518b..bd9ab69a 100644 --- a/plugins/ahmadfatoni/apigenerator/routes.php +++ b/plugins/ahmadfatoni/apigenerator/routes.php @@ -1,25 +1,25 @@ - 'fatoni.generate.api', 'uses' => 'AhmadFatoni\ApiGenerator\Controllers\ApiGeneratorController@generateApi')); -Route::post('fatoni/update/api/{id}', array('as' => 'fatoni.update.api', 'uses' => 'AhmadFatoni\ApiGenerator\Controllers\ApiGeneratorController@updateApi')); -Route::get('fatoni/delete/api/{id}', array('as' => 'fatoni.delete.api', 'uses' => 'AhmadFatoni\ApiGenerator\Controllers\ApiGeneratorController@deleteApi')); - -Route::group(['prefix' =>'api/v1','namespace' =>'AhmadFatoni\ApiGenerator\Controllers\API'],function ($route){ - - Route::get('products','ProductAPIController@index'); - Route::get('products/category/{id}','ProductAPIController@ByCatId'); - Route::get('products/{id}', 'ProductAPIController@show'); - - Route::get('categories', 'CategoriesAPIController@index'); - Route::get('category/sub/{id}', 'CategoriesAPIController@getParent'); - - Route::get('sliders', 'SliderAPIController@index'); - - - Route::middleware([\ReaZzon\JWTAuth\Http\Middlewares\ResolveUser::class])->group(function () { - - Route::get('cart', 'CartAPIController@index'); - - }); -}); - + 'fatoni.generate.api', 'uses' => 'AhmadFatoni\ApiGenerator\Controllers\ApiGeneratorController@generateApi')); +Route::post('fatoni/update/api/{id}', array('as' => 'fatoni.update.api', 'uses' => 'AhmadFatoni\ApiGenerator\Controllers\ApiGeneratorController@updateApi')); +Route::get('fatoni/delete/api/{id}', array('as' => 'fatoni.delete.api', 'uses' => 'AhmadFatoni\ApiGenerator\Controllers\ApiGeneratorController@deleteApi')); + +Route::group(['prefix' =>'api/v1','namespace' =>'AhmadFatoni\ApiGenerator\Controllers\API'],function ($route){ + + Route::get('products','ProductAPIController@index'); + Route::get('products/category/{id}','ProductAPIController@ByCatId'); + Route::get('products/{id}', 'ProductAPIController@show'); + + Route::get('categories', 'CategoriesAPIController@index'); + Route::get('category/sub/{id}', 'CategoriesAPIController@getParent'); + + Route::get('sliders', 'SliderAPIController@index'); + + + //Route::middleware([\ReaZzon\JWTAuth\Http\Middlewares\ResolveUser::class])->group(function () { + + //Route::get('cart', 'CartAPIController@index'); + + // }); +}); +