api settings

This commit is contained in:
Kerim 2023-07-28 01:13:51 +05:00
parent 5a985dc5dd
commit 7c6ef8e82f
20 changed files with 308 additions and 119 deletions

View File

@ -44,33 +44,48 @@ class BlogPostsApiController extends Controller
->orderBy('published_at', $data['sort_order'] ?? 'desc')
->paginate($data['per_page'] ?? 7))->response()->getData(), 200);
}
public function getAccounts(Request $request)
{
//$path = Config::get('cms.storage.media.path');
$dataAccounts = User::where('is_featured', 1)
->select('id', 'name', 'email', 'username', 'type', 'logo', 'shop_title', 'slogan', 'work_time', 'description', 'map')
->get();
$data = $request->all();
$dataAccounts = User::select('id', 'name', 'email', 'username', 'type', 'logo', 'shop_title', 'slogan', 'work_time', 'description', 'map', 'banner', 'is_instagram')
->with('categories:id,name,slug,icon')
->get();
if($data && $data["type"] == "home"){
$dataAccounts = User::where('is_featured', 1)
->select('id', 'name', 'email', 'username', 'type', 'logo', 'shop_title', 'slogan', 'work_time', 'description', 'map', 'banner', 'is_instagram')
->with('categories:id,name,slug,icon')
->paginate(9);
}elseif($data && $data["type"] == "category"){
$dataAccounts = User::where('is_category', 1)
->select('id', 'name', 'email', 'username', 'type', 'logo', 'shop_title', 'slogan', 'work_time', 'description', 'map', 'is_instagram')
->with('categories:id,name,slug,icon')
->paginate(9);
}
//$dataSlider["img"] = $path.$dataSlider["img"];
if($dataAccounts){
$dataAccounts->each(function ($item, $key) {
$item->logo = 'http://78.111.88.8:9086'.Config::get('cms.storage.media.path').$item->logo;
$item->banner = 'http://78.111.88.8:9086'.Config::get('cms.storage.media.path').$item->banner;
});
}
return response()->json($dataAccounts, 200);
}
public function getSliders(Request $request)
{
$path = Config::get('cms.storage.media.path');
$data = $request->all();
$validator = Validator::make($data, [
//'locale' => 'required|in:ru,en,tm',
@ -80,15 +95,15 @@ class BlogPostsApiController extends Controller
return $this->helpers->apiArrayResponseBuilder(400, 'fail', $validator->errors() );
}
$dataSlider = SliderApp::where('type', $data['type'])->orderBy('order', 'desc')->select('id', 'img', 'type', 'order')->get();
//$dataSlider["img"] = $path.$dataSlider["img"];
if($dataSlider){
$dataSlider->each(function ($item, $key) {
$item->img = 'http://78.111.88.8:9086'.Config::get('cms.storage.media.path').$item->img;
});
}
return response()->json($dataSlider, 200);
}

View File

@ -47,10 +47,7 @@ class ProductsAPIController extends Controller
$query = $this->Product::with([
'translations:locale,model_id,attribute_data',
'images:attachment_id,attachment_type,disk_name,file_name',
//'measure.translations:locale,model_id,attribute_data',
//'currency.translations:locale,model_id,attribute_data'
])
// ->approvedAndFreshEndDate()
->approved()
->orderBy('ends_at', $sortOrder);
@ -58,25 +55,22 @@ class ProductsAPIController extends Controller
$category = Category::find($categoryId);
if($category) {
$query = $category->products()
// ->with('categories:id,name')
->with('categories:id,name')
->with([
'translations:locale,model_id,attribute_data',
'images:attachment_id,attachment_type,disk_name,file_name',
//'measure.translations:locale,model_id,attribute_data',
//'currency.translations:locale,model_id,attribute_data'
])
// ->approvedAndFreshEndDate()
->approved()
->orderBy('ends_at', $sortOrder);
} else {
$query = null;
}
}
}
if($productId) { // fetch offers with products in the same category
$product = $this->Product::find($productId);
if($product) {
$category = $product->categories->first();
@ -86,8 +80,6 @@ class ProductsAPIController extends Controller
->with([
'translations:locale,model_id,attribute_data',
'images:attachment_id,attachment_type,disk_name,file_name',
//'measure.translations:locale,model_id,attribute_data',
//'currency.translations:locale,model_id,attribute_data'
])
// ->approvedAndFreshEndDate()
->approved()
@ -102,24 +94,12 @@ class ProductsAPIController extends Controller
->with([
'translations:locale,model_id,attribute_data',
'images:attachment_id,attachment_type,disk_name,file_name',
//'measure.translations:locale,model_id,attribute_data',
//'currency.translations:locale,model_id,attribute_data'
])
->orderBy('ends_at', $sortOrder);
}
$data = $query ? $query->paginate($perPage) : null;
//if($data) {
// foreach ($data as $product) {
// $product->unit = new MeasureResource($product->measure);
// }
// }
// if($data) {
// $data->each(function ($item, $key) {
// $item->img_url_start = $this->pageUrl('index') . \Config::get('cms.storage.media.path') . $item->icon;
// });
// }
return response()->json($data, 200);
}
@ -129,10 +109,6 @@ class ProductsAPIController extends Controller
$data = $this->Product::with([
'translations:locale,model_id,attribute_data',
'images:attachment_id,attachment_type,disk_name,file_name',
'measure.translations:locale,model_id,attribute_data',
'currency.translations:locale,model_id,attribute_data',
'payment_term.translations:locale,model_id,attribute_data',
'delivery_term.translations:locale,model_id,attribute_data',
'vendor:id,name,surname,email,username'
])->find($id);
@ -163,12 +139,12 @@ class ProductsAPIController extends Controller
}
}
],
'mark' => 'required',
'manufacturer' => 'required',
'country' => 'required',
'market_type' => 'required|in:in,out',
// if product is being edited - not added
// 'mark' => 'required',
// 'manufacturer' => 'required',
// 'country' => 'required',
// 'market_type' => 'required|in:in,out',
// if product is being edited - not added
'productForEditing' => [
// validation for product deleted_at field - it should
// be null, means it should not be deleted (exists rule not working)
@ -191,7 +167,7 @@ class ProductsAPIController extends Controller
if(!$product = $this->checkUserHasProduct($data['productForEditing'])) {
return $this->helpers->apiArrayResponseBuilder(404, 'not found', ['error' => "Resource id = {$data['productForEditing']} could not be found"]);
}
//approved edilen produkty prodlenie uchin drafta tayinlamak, bagly transacsiasyny goparmak,
if($product && $product->status == 'approved' && $product->transaction)
{
@ -214,10 +190,10 @@ class ProductsAPIController extends Controller
$product->slug = \Str::slug($data['name_tm'],'-');
$product->status = 'draft';
$product->mark = $data['mark'];
$product->manufacturer = $data['manufacturer'];
$product->country = $data['country'];
$product->market_type = $data['market_type'];
// $product->mark = $data['mark'];
// $product->manufacturer = $data['manufacturer'];
// $product->country = $data['country'];
// $product->market_type = $data['market_type'];
$product->vendor_id = \JWTAuth::parseToken()->authenticate()->id;
@ -233,7 +209,7 @@ class ProductsAPIController extends Controller
// attach to a new category
$category->products()->save($product);
}
return $this->helpers->apiArrayResponseBuilder(200, 'ok', ['product' => $product]);
}
@ -311,7 +287,7 @@ class ProductsAPIController extends Controller
return $this->helpers->apiArrayResponseBuilder(400, 'fail', $validator->errors() );
}
}
// if old_img field is passed but empty
if($request->has('old_img')) {
$rules = [
@ -433,7 +409,7 @@ class ProductsAPIController extends Controller
{
return Validator::make($data, $rules);
}
protected function fillProduct($data, $attachedProduct) {
$attachedProduct->translateContext('tm');
@ -475,12 +451,12 @@ class ProductsAPIController extends Controller
} catch (\Throwable $th) {
return $this->helpers->apiArrayResponseBuilder(500, 'server error', ['message' => 'Something went wrong']);
}
return response()->json($products, 200);
}
public function showMyProductById($id) {
if(!$product = $this->checkUserHasProduct($id)) {
return $this->helpers->apiArrayResponseBuilder(404, 'not found', ['error' => "Resource id = {$id} could not be found"]);
} else {
@ -494,4 +470,4 @@ class ProductsAPIController extends Controller
return $currentUser->products->find($id);
}
}
}

View File

@ -25,7 +25,7 @@ class TermsapiController extends Controller
$inputData = $request->all();
$rules = [
'type' => 'required|in:payment,delivery'
'type' => 'required|in:about,privacy'
];
$validator = Validator::make($inputData, $rules);
@ -34,14 +34,14 @@ class TermsapiController extends Controller
}
switch ($inputData['type']) {
case 'payment':
$data = $this->Term::payment()->with('translations:locale,model_id,attribute_data')->get()->toArray();
case 'about':
$data = $this->Term::about()->with('translations:locale,model_id,attribute_data')->get()->toArray();
break;
case 'delivery':
$data = $this->Term::delivery()->with('translations:locale,model_id,attribute_data')->get()->toArray();
case 'privacy':
$data = $this->Term::privacy()->with('translations:locale,model_id,attribute_data')->get()->toArray();
break;
default:
# code...
break;
@ -72,7 +72,7 @@ class TermsapiController extends Controller
}
$validation = Validator::make($request->all(), $this->Term->rules);
if( $validation->passes() ){
$this->Term->save();
return $this->helpers->apiArrayResponseBuilder(201, 'created', ['id' => $this->Term->id]);
@ -85,9 +85,9 @@ class TermsapiController extends Controller
public function update($id, Request $request){
$status = $this->Term->where('id',$id)->update($data);
if( $status ){
return $this->helpers->apiArrayResponseBuilder(200, 'success', 'Data has been updated successfully.');
}else{
@ -118,5 +118,5 @@ class TermsapiController extends Controller
public function callAction($method, $parameters=false) {
return call_user_func_array(array($this, $method), $parameters);
}
}
}

View File

@ -14,9 +14,11 @@ Route::group(['prefix' =>'api/v1','namespace' =>'AhmadFatoni\ApiGenerator\Contro
// Route::get('products/{id}/delete', ['as' => 'products.delete', 'uses' => 'ProductsApiController@destroy']);
Route::resource('countries', 'CountriesapiController', ['except' => ['destroy', 'create', 'edit']]);
Route::resource('currencies', 'CurrenciesapiController', ['except' => ['destroy', 'create', 'edit']]);
Route::resource('measures', 'MeasuresapiController', ['except' => ['destroy', 'create', 'edit']]);
// Route::resource('countries', 'CountriesapiController', ['except' => ['destroy', 'create', 'edit']]);
// Route::resource('currencies', 'CurrenciesapiController', ['except' => ['destroy', 'create', 'edit']]);
// Route::resource('measures', 'MeasuresapiController', ['except' => ['destroy', 'create', 'edit']]);
// Route::get('measures/{id}/delete', ['as' => 'measures.delete', 'uses' => 'MeasuresapiController@destroy']);
Route::resource('terms', 'TermsapiController', ['except' => ['destroy', 'create', 'edit']]);
@ -26,7 +28,7 @@ Route::group(['prefix' =>'api/v1','namespace' =>'AhmadFatoni\ApiGenerator\Contro
Route::get('news', 'BlogPostsApiController@index');
Route::get('news/{id}', 'BlogPostsApiController@show')->where(['id' => '[0-9]+']);
Route::get('sliders', 'BlogPostsApiController@getSliders');
Route::get('accounts', 'BlogPostsApiController@getAccounts');
@ -72,10 +74,10 @@ Route::group(['prefix' =>'api/v1','namespace' =>'AhmadFatoni\ApiGenerator\Contro
Route::post('send-email-verification-link', 'EmailVerificationController@sendEmailVerificationLink');
});
Route::get('bank-info', 'BanksApiController@getBankInfo');
Route::get('bank-types', 'BanksApiController@getBankTypes');
});

View File

@ -84,14 +84,6 @@ tabs:
default: simple
type: balloon-selector
tab: Gurlushyk
logo:
label: Logo
mode: image
imageWidth: '100'
imageHeight: '100'
span: auto
type: mediafinder
tab: Gurlushyk
shop_title:
label: 'Brend Ady'
span: auto
@ -109,11 +101,6 @@ tabs:
span: auto
type: text
tab: Gurlushyk
is_instagram:
label: 'Instagram Stilmi'
span: auto
type: switch
tab: Gurlushyk
map:
label: Map
size: ''
@ -126,12 +113,6 @@ tabs:
span: auto
type: textarea
tab: Gurlushyk
is_featured:
label: 'Bash Sahypa'
span: auto
disabled: 0
type: switch
tab: Gurlushyk
categories:
label: Relation
nameFrom: name
@ -139,6 +120,37 @@ tabs:
span: auto
type: relation
tab: Kategoriyalar
is_featured:
label: 'Bash Sahypa'
span: auto
disabled: 0
type: switch
tab: Suratlar
is_instagram:
label: 'Instagram Stilmi'
span: auto
type: switch
tab: Suratlar
is_category:
label: 'Category Page'
span: auto
type: switch
tab: Suratlar
logo:
label: Logo
mode: image
imageWidth: '100'
imageHeight: '100'
span: left
type: mediafinder
tab: Suratlar
banner:
label: Banner
mode: image
span: auto
imageWidth: '200'
type: mediafinder
tab: Suratlar
secondaryTabs:
fields:
avatar:

View File

@ -0,0 +1,25 @@
<?php namespace RainLab\User\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class UsersAddBanner extends Migration
{
public function up()
{
Schema::table('users', function($table)
{
$table->string('banner')->nullable();
});
}
public function down()
{
if (Schema::hasColumn('users', 'banner')) {
Schema::table('users', function($table)
{
$table->dropColumn('banner');
});
}
}
}

View File

@ -0,0 +1,25 @@
<?php namespace RainLab\User\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class UsersAddIsCategory extends Migration
{
public function up()
{
Schema::table('users', function($table)
{
$table->boolean('is_category')->default(false);
});
}
public function down()
{
if (Schema::hasColumn('users', 'is_category')) {
Schema::table('users', function($table)
{
$table->dropColumn('is_category');
});
}
}
}

View File

@ -92,3 +92,9 @@ v1.7.5:
v1.7.6:
- Add featured user gurlushyk
- users_add_featured.php
v1.7.7:
- Add banner user gurlushyk
- users_add_banner.php
v1.7.8:
- Add is category user gurlushyk
- users_add_is_category.php

View File

@ -34,7 +34,7 @@ class Product extends Model
'name' => 'required',
'slug' => 'required',
'images' => 'required',
'quantity' => 'required',
// 'quantity' => 'required',
//'measure' => 'required',
'price' => 'required|numeric|max:9999999',
//'currency' => 'required',

View File

@ -34,11 +34,11 @@ class Term extends Model
public $translatable = ['name'];
public function scopePayment($query){
return $query->where('type','payment');
public function scopeAbout($query){
return $query->where('type','about');
}
public function scopeDelivery($query){
return $query->where('type','delivery');
public function scopePrivacy($query){
return $query->where('type','privacy');
}
}

View File

@ -16,11 +16,6 @@ columns:
label: Status
type: status
sortable: true
mark:
label: Marka
type: text
searchable: true
sortable: true
updated_at:
label: 'Updated at'
type: datetime
@ -29,3 +24,6 @@ columns:
label: 'Ends at'
type: datetime
invisible: true
is_home:
label: 'Is Home'
type: switch

View File

@ -12,20 +12,12 @@ fields:
preset:
field: name
type: slug
mark:
label: Marka
span: auto
type: text
created_at:
label: 'Created at'
mode: datetime
span: auto
readOnly: 1
type: datepicker
quantity:
label: Quantity
span: auto
type: number
ends_at:
label: 'Ends at'
mode: datetime
@ -62,6 +54,10 @@ fields:
extension: auto
span: auto
type: fileupload
is_home:
label: 'Is Home'
span: auto
type: switch
tabs:
fields:
categories:

View File

@ -7,8 +7,13 @@ fields:
type:
label: Type
options:
payment: payment
delivery: delivery
about: About
privacy: 'Privacy Policy'
span: auto
required: 1
type: balloon-selector
content:
label: Content
size: huge
span: full
type: richeditor

View File

@ -0,0 +1,39 @@
<?php namespace TPS\Birzha\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableUpdateTpsBirzhaProducts27 extends Migration
{
public function up()
{
Schema::table('tps_birzha_products', function($table)
{
$table->dropColumn('mark');
$table->dropColumn('quantity');
$table->dropColumn('measure_id');
$table->dropColumn('currency_id');
$table->dropColumn('payment_term_id');
$table->dropColumn('delivery_term_id');
$table->dropColumn('packaging');
$table->dropColumn('payment_id');
$table->dropColumn('payed_fee_for_publ');
});
}
public function down()
{
Schema::table('tps_birzha_products', function($table)
{
$table->string('mark', 191)->nullable();
$table->decimal('quantity', 10, 2)->nullable();
$table->integer('measure_id')->nullable();
$table->integer('currency_id')->nullable();
$table->integer('payment_term_id')->nullable();
$table->integer('delivery_term_id')->nullable();
$table->string('packaging', 191)->nullable();
$table->integer('payment_id')->nullable();
$table->decimal('payed_fee_for_publ', 10, 2)->nullable();
});
}
}

View File

@ -0,0 +1,23 @@
<?php namespace TPS\Birzha\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableUpdateTpsBirzhaProducts28 extends Migration
{
public function up()
{
Schema::table('tps_birzha_products', function($table)
{
$table->boolean('is_home')->nullable();
});
}
public function down()
{
Schema::table('tps_birzha_products', function($table)
{
$table->dropColumn('is_home');
});
}
}

View File

@ -0,0 +1,23 @@
<?php namespace TPS\Birzha\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableUpdateTpsBirzhaProducts29 extends Migration
{
public function up()
{
Schema::table('tps_birzha_products', function($table)
{
$table->boolean('is_home')->default(false)->change();
});
}
public function down()
{
Schema::table('tps_birzha_products', function($table)
{
$table->boolean('is_home')->default(null)->change();
});
}
}

View File

@ -0,0 +1,23 @@
<?php namespace TPS\Birzha\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableUpdateTpsBirzhaTerms extends Migration
{
public function up()
{
Schema::table('tps_birzha_terms', function($table)
{
$table->text('content')->nullable();
});
}
public function down()
{
Schema::table('tps_birzha_terms', function($table)
{
$table->dropColumn('content');
});
}
}

View File

@ -335,3 +335,15 @@
1.0.118:
- 'Updated table tps_birzha_user_sliders'
- builder_table_update_tps_birzha_user_sliders_5.php
1.0.119:
- 'Updated table tps_birzha_products'
- builder_table_update_tps_birzha_products_27.php
1.0.120:
- 'Updated table tps_birzha_products'
- builder_table_update_tps_birzha_products_28.php
1.0.121:
- 'Updated table tps_birzha_products'
- builder_table_update_tps_birzha_products_29.php
1.0.122:
- 'Updated table tps_birzha_terms'
- builder_table_update_tps_birzha_terms.php

View File

@ -0,0 +1,4 @@
title = "home"
url = "/"
is_hidden = 0
==

View File

@ -0,0 +1,5 @@
name: gulushyk2
description: ''
author: ''
homepage: ''
code: ''