This commit is contained in:
Shohrat 2023-03-08 20:49:30 +00:00
parent e351b69f7f
commit 9dacdd3557
5 changed files with 286 additions and 270 deletions

View File

@ -57,9 +57,9 @@ return [
'engine' => 'InnoDB', 'engine' => 'InnoDB',
'host' => 'localhost', 'host' => 'localhost',
'port' => 3306, 'port' => 3306,
'database' => 'sapaly_git', 'database' => 'sapaly_october',
'username' => 'root', 'username' => 'sapaly',
'password' => '', 'password' => '22MOcP6^I#8tI5ovcXluXDT#%vWC^CtsFvKHOygi8TMnzaMuLYx@123',
'charset' => 'utf8mb4', 'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci', 'collation' => 'utf8mb4_unicode_ci',
'prefix' => '', 'prefix' => '',

View File

@ -1,68 +1,72 @@
<?php namespace AhmadFatoni\ApiGenerator\Controllers\API; <?php namespace AhmadFatoni\ApiGenerator\Controllers\API;
use Cms\Classes\Controller; use Cms\Classes\Controller;
use BackendMenu; use BackendMenu;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use AhmadFatoni\ApiGenerator\Helpers\Helpers; use AhmadFatoni\ApiGenerator\Helpers\Helpers;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
use Lovata\Shopaholic\Models\Category; use Lovata\Shopaholic\Models\Category;
class CategoriesAPIController extends Controller class CategoriesAPIController extends Controller
{ {
protected $Category; protected $Category;
protected $helpers; protected $helpers;
public function __construct(Category $Category, Helpers $helpers) public function __construct(Category $Category, Helpers $helpers)
{ {
parent::__construct(); parent::__construct();
$this->Category = $Category; $this->Category = $Category;
$this->helpers = $helpers; $this->helpers = $helpers;
} }
public function index(){ public function index(){
$data = $this->Category $data = $this->Category
->select("id", "name", "slug") ->select("id", "name", "slug")
->orderBy("nest_left", "asc") ->orderBy("nest_left", "asc")
->with('translations:locale,model_id,attribute_data') ->with('translations:locale,model_id,attribute_data')
->where("nest_depth", 0) ->with('icon')
->active() ->with('preview_image')
->get(); ->where("nest_depth", 0)
->active()
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); ->get();
}
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
public function GetParent($id){ }
$data = $this->Category public function GetParent($id){
->select("id", "name", "slug")
->orderBy("nest_left", "asc") $data = $this->Category
->with('translations:locale,model_id,attribute_data') ->select("id", "name", "slug")
->where("parent_id", $id) ->orderBy("nest_left", "asc")
->active() ->with('translations:locale,model_id,attribute_data')
->get(); ->with('icon')
->with('preview_image')
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); ->where("parent_id", $id)
} ->active()
->get();
public function show($id){
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
$data = $this->Category::find($id); }
if ($data){ public function show($id){
return $this->helpers->apiArrayResponseBuilder(200, 'success', [$data]);
} else { $data = $this->Category::find($id);
$this->helpers->apiArrayResponseBuilder(404, 'not found', ['error' => 'Resource id=' . $id . ' could not be found']);
} 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); 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);
}
} }

View File

@ -1,130 +1,140 @@
<?php namespace AhmadFatoni\ApiGenerator\Controllers\API; <?php namespace AhmadFatoni\ApiGenerator\Controllers\API;
use Cms\Classes\Controller; use Cms\Classes\Controller;
use BackendMenu; use BackendMenu;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use AhmadFatoni\ApiGenerator\Helpers\Helpers; use AhmadFatoni\ApiGenerator\Helpers\Helpers;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
use Lovata\Shopaholic\Models\Product; use Lovata\Shopaholic\Models\Product;
class ProductAPIController extends Controller class ProductAPIController extends Controller
{ {
protected $Product; protected $Product;
protected $helpers; protected $helpers;
public function __construct(Product $Product, Helpers $helpers) public function __construct(Product $Product, Helpers $helpers)
{ {
parent::__construct(); parent::__construct();
$this->Product = $Product; $this->Product = $Product;
$this->helpers = $helpers; $this->helpers = $helpers;
} }
public function index(){ public function index(){
$data = $this->Product $data = $this->Product
->select("id", "name", "slug", "category_id", "featured") ->select("id", "name", "slug", "category_id", "featured", "description")
->with('translations:locale,model_id,attribute_data') //->with(['preview_image' => function ($query) {
// ->with(['category' => function ($query) { // $query->select("id", "path");
// $query->with('translations:locale,model_id,attribute_data'); // }])
// }]) ->with('preview_image')
->active() //->with('offer:id,main_price')
->paginate(10); //->with('images')
->with('translations:locale,model_id,attribute_data')
if($data) { ->with(['offer' => function ($query) {
$data->each(function ($item, $key) { $query->with('main_price');
$item->icon = $this->pageUrl('index') . \Config::get('cms.storage.media.path') . $item->icon; }])
}); ->active()
} ->paginate(10);
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); if($data) {
} $data->each(function ($item, $key) {
$item->icon = $this->pageUrl('index') . \Config::get('cms.storage.media.path') . $item->icon;
public function ByCatId($id){ });
}
$data = $this->Product
->select("id", "name", "slug", "category_id", "featured") return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
->with('translations:locale,model_id,attribute_data') }
->where("category_id", $id)
->active() public function ByCatId($id){
->paginate(10);
$data = $this->Product
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); ->select("id", "name", "slug", "category_id", "featured")
} ->with('preview_image')
->with('translations:locale,model_id,attribute_data')
->where("category_id", $id)
public function show($id){ ->with(['offer' => function ($query) {
$query->with('main_price');
$data = $this->Product::with('translations:locale,model_id,attribute_data') }])
->with(['category' => function ($query) { ->active()
$query->with('translations:locale,model_id,attribute_data'); ->paginate(10);
}])
->find($id); return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
}
if ($data){
return $this->helpers->apiArrayResponseBuilder(200, 'success', [$data]); public function show($id){
} else {
$this->helpers->apiArrayResponseBuilder(404, 'not found', ['error' => 'Resource id=' . $id . ' could not be found']); $data = $this->Product::with('translations:locale,model_id,attribute_data')
} ->with(['category' => function ($query) {
$query->with('translations:locale,model_id,attribute_data');
} }])
->find($id);
// public function store(Request $request){
// $arr = $request->all(); if ($data){
return $this->helpers->apiArrayResponseBuilder(200, 'success', [$data]);
// while ( $data = current($arr)) { } else {
// $this->Product->{key($arr)} = $data; $this->helpers->apiArrayResponseBuilder(404, 'not found', ['error' => 'Resource id=' . $id . ' could not be found']);
// next($arr); }
// }
}
// $validation = Validator::make($request->all(), $this->Product->rules);
// public function store(Request $request){
// if( $validation->passes() ){
// $this->Product->save(); // $arr = $request->all();
// return $this->helpers->apiArrayResponseBuilder(201, 'created', ['id' => $this->Product->id]);
// }else{ // while ( $data = current($arr)) {
// return $this->helpers->apiArrayResponseBuilder(400, 'fail', $validation->errors() ); // $this->Product->{key($arr)} = $data;
// } // next($arr);
// }
// }
// $validation = Validator::make($request->all(), $this->Product->rules);
// public function update($id, Request $request){
// if( $validation->passes() ){
// $status = $this->Product->where('id',$id)->update($data); // $this->Product->save();
// return $this->helpers->apiArrayResponseBuilder(201, 'created', ['id' => $this->Product->id]);
// if( $status ){ // }else{
// return $this->helpers->apiArrayResponseBuilder(400, 'fail', $validation->errors() );
// 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 update($id, Request $request){
// } // $status = $this->Product->where('id',$id)->update($data);
// }
// if( $status ){
// public function delete($id){
// return $this->helpers->apiArrayResponseBuilder(200, 'success', 'Data has been updated successfully.');
// $this->Product->where('id',$id)->delete();
// }else{
// return $this->helpers->apiArrayResponseBuilder(200, 'success', 'Data has been deleted successfully.');
// } // return $this->helpers->apiArrayResponseBuilder(400, 'bad request', 'Error, data failed to update.');
// public function destroy($id){ // }
// }
// $this->Product->where('id',$id)->delete();
// public function delete($id){
// return $this->helpers->apiArrayResponseBuilder(200, 'success', 'Data has been deleted successfully.');
// } // $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 destroy($id){
public function callAction($method, $parameters=false) {
return call_user_func_array(array($this, $method), $parameters); // $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);
}
} }

View File

@ -1,47 +1,49 @@
<?php namespace AhmadFatoni\ApiGenerator\Controllers\API; <?php namespace AhmadFatoni\ApiGenerator\Controllers\API;
use Cms\Classes\Controller; use Cms\Classes\Controller;
use BackendMenu; use BackendMenu;
use Config;
use Illuminate\Http\Request;
use AhmadFatoni\ApiGenerator\Helpers\Helpers; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator; use AhmadFatoni\ApiGenerator\Helpers\Helpers;
use Akami\Coffe30\Models\Slider; use Illuminate\Support\Facades\Validator;
class SliderAPIController extends Controller use Akami\Coffe30\Models\Slider;
{ class SliderAPIController extends Controller
protected $Slider; {
protected $Slider;
protected $helpers;
protected $helpers;
public function __construct(Slider $Slider, Helpers $helpers)
{ public function __construct(Slider $Slider, Helpers $helpers)
parent::__construct(); {
$this->Slider = $Slider; parent::__construct();
$this->helpers = $helpers; $this->Slider = $Slider;
} $this->helpers = $helpers;
}
public function index(){
public function index(){
$data = $this->Slider $path = Config::get('app.cdn').Config::get('cms.storage.media.path');
->select("id", "img")
->with('translations:locale,model_id,attribute_data') $data = $this->Slider
->get(); ->select("id", "img")
->with('translations:locale,model_id,attribute_data')
if($data) { ->get();
$data->each(function ($item, $key) {
$item->img = $this->pageUrl('index') . \Config::get('cms.storage.media.path') . $item->img; 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); }
}
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
}
public static function getAfterFilters() {return [];}
public static function getBeforeFilters() {return [];}
public static function getMiddleware() {return [];} public static function getAfterFilters() {return [];}
public function callAction($method, $parameters=false) { public static function getBeforeFilters() {return [];}
return call_user_func_array(array($this, $method), $parameters); public static function getMiddleware() {return [];}
} public function callAction($method, $parameters=false) {
return call_user_func_array(array($this, $method), $parameters);
}
} }

View File

@ -1,25 +1,25 @@
<?php <?php
Route::post('fatoni/generate/api', array('as' => 'fatoni.generate.api', 'uses' => 'AhmadFatoni\ApiGenerator\Controllers\ApiGeneratorController@generateApi')); Route::post('fatoni/generate/api', array('as' => '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::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::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::group(['prefix' =>'api/v1','namespace' =>'AhmadFatoni\ApiGenerator\Controllers\API'],function ($route){
Route::get('products','ProductAPIController@index'); Route::get('products','ProductAPIController@index');
Route::get('products/category/{id}','ProductAPIController@ByCatId'); Route::get('products/category/{id}','ProductAPIController@ByCatId');
Route::get('products/{id}', 'ProductAPIController@show'); Route::get('products/{id}', 'ProductAPIController@show');
Route::get('categories', 'CategoriesAPIController@index'); Route::get('categories', 'CategoriesAPIController@index');
Route::get('category/sub/{id}', 'CategoriesAPIController@getParent'); Route::get('category/sub/{id}', 'CategoriesAPIController@getParent');
Route::get('sliders', 'SliderAPIController@index'); Route::get('sliders', 'SliderAPIController@index');
Route::middleware([\ReaZzon\JWTAuth\Http\Middlewares\ResolveUser::class])->group(function () { //Route::middleware([\ReaZzon\JWTAuth\Http\Middlewares\ResolveUser::class])->group(function () {
Route::get('cart', 'CartAPIController@index'); //Route::get('cart', 'CartAPIController@index');
}); // });
}); });