mirror of
https://github.com/cp6/my-idlers.git
synced 2024-11-16 23:42:32 +01:00
Added pricing update with API
Added pricing update with API
This commit is contained in:
parent
b34780546b
commit
b9c756c8d5
@ -12,6 +12,7 @@ use App\Models\Server;
|
|||||||
use App\Models\Shared;
|
use App\Models\Shared;
|
||||||
use DataTables;
|
use DataTables;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
@ -432,7 +433,7 @@ class ApiController extends Controller
|
|||||||
return response()->json(array('result' => 'fail'), 500);
|
return response()->json(array('result' => 'fail'), 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateServer(Request $request, Server $server)
|
public function updateServer(Request $request)
|
||||||
{
|
{
|
||||||
$rules = array(
|
$rules = array(
|
||||||
'hostname' => 'string|min:3',
|
'hostname' => 'string|min:3',
|
||||||
@ -487,4 +488,47 @@ class ApiController extends Controller
|
|||||||
return response()->json(array('result' => 'fail', 'request' => $request->post()), 500);
|
return response()->json(array('result' => 'fail', 'request' => $request->post()), 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function updatePricing(Request $request)
|
||||||
|
{
|
||||||
|
$rules = array(
|
||||||
|
'price' => 'required|numeric',
|
||||||
|
'currency' => 'required|string|size:3',
|
||||||
|
'term' => 'required|integer',
|
||||||
|
'active' => 'integer',
|
||||||
|
'next_due_date' => 'date',
|
||||||
|
);
|
||||||
|
|
||||||
|
$messages = array(
|
||||||
|
'required' => ':attribute is required',
|
||||||
|
'integer' => ':attribute must be an integer',
|
||||||
|
'string' => ':attribute must be a string',
|
||||||
|
'size' => ':attribute must be exactly :size characters',
|
||||||
|
'numeric' => ':attribute must be a float',
|
||||||
|
'date' => ':attribute must be a date Y-m-d',
|
||||||
|
);
|
||||||
|
|
||||||
|
$validator = Validator::make($request->all(), $rules, $messages);
|
||||||
|
|
||||||
|
if ($validator->fails()) {
|
||||||
|
return response()->json(['result' => 'fail', 'messages' => $validator->messages()], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pricing = new Pricing();
|
||||||
|
|
||||||
|
$request->as_usd = $pricing->convertToUSD($request->price, $request->currency);
|
||||||
|
|
||||||
|
$request->usd_per_month = $pricing->costAsPerMonth($request->as_usd, $request->term);
|
||||||
|
|
||||||
|
$price_update = Pricing::where('id', $request->id)->update(request()->all());
|
||||||
|
|
||||||
|
Cache::forget("all_pricing");
|
||||||
|
Server::serverRelatedCacheForget();
|
||||||
|
|
||||||
|
if ($price_update) {
|
||||||
|
return response()->json(array('result' => 'success', 'server_id' => $request->id), 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json(array('result' => 'fail', 'request' => $request->post()), 500);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ Route::middleware('auth:api')->get('os/{id}', 'App\Http\Controllers\ApiControlle
|
|||||||
|
|
||||||
Route::middleware('auth:api')->get('pricing/', 'App\Http\Controllers\ApiController@getAllPricing');
|
Route::middleware('auth:api')->get('pricing/', 'App\Http\Controllers\ApiController@getAllPricing');
|
||||||
Route::middleware('auth:api')->get('pricing/{id}', 'App\Http\Controllers\ApiController@getPricing');
|
Route::middleware('auth:api')->get('pricing/{id}', 'App\Http\Controllers\ApiController@getPricing');
|
||||||
|
Route::middleware('auth:api')->put('pricing/{id}', 'App\Http\Controllers\ApiController@updatePricing');
|
||||||
|
|
||||||
Route::middleware('auth:api')->get('providers/', 'App\Http\Controllers\ApiController@getAllProviders');
|
Route::middleware('auth:api')->get('providers/', 'App\Http\Controllers\ApiController@getAllProviders');
|
||||||
Route::middleware('auth:api')->get('providers/{id}', 'App\Http\Controllers\ApiController@getProvider');
|
Route::middleware('auth:api')->get('providers/{id}', 'App\Http\Controllers\ApiController@getProvider');
|
||||||
|
Loading…
Reference in New Issue
Block a user