+ Multi Language
This commit is contained in:
parent
ede547ca5f
commit
2801547f9a
|
@ -69,7 +69,7 @@ class Handler extends ExceptionHandler
|
||||||
{
|
{
|
||||||
$model = strtolower(class_basename($exception->getModel()));
|
$model = strtolower(class_basename($exception->getModel()));
|
||||||
|
|
||||||
return $this->errorResponse("Does not exist any instance of {$model} with given id",
|
return $this->errorResponse(trans('errors.model_not_found',['model'=>$model]),
|
||||||
Response::HTTP_NOT_FOUND);
|
Response::HTTP_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ class Handler extends ExceptionHandler
|
||||||
return parent::render($request,$exception);
|
return parent::render($request,$exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->errorResponse('Unexcepted error. Try later',
|
return $this->errorResponse(trans('errors.unexpected_error'),
|
||||||
Response::HTTP_INTERNAL_SERVER_ERROR);
|
Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ use App\Traits\ApiResponser;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
class WalletController extends Controller
|
class WalletServiceController extends Controller
|
||||||
{
|
{
|
||||||
use ApiResponser;
|
use ApiResponser;
|
||||||
/**
|
/**
|
||||||
|
@ -28,25 +28,22 @@ class WalletController extends Controller
|
||||||
|
|
||||||
public function get(Request $request)
|
public function get(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
return $this->successResponse($this->walletService->get(
|
return $this->successResponse($this->walletService->get(
|
||||||
substr($request->getRequestUri(),strlen(env('WALLET_SERVICE_NAME'))+1), $request->all()
|
substr($request->getRequestUri(),strlen(env('WALLET_SERVICE_NAME'))+1), $request->all(),$request->header()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function post(Request $request)
|
public function post(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
return $this->successResponse($this->walletService->post(
|
return $this->successResponse($this->walletService->post(
|
||||||
substr($request->getRequestUri(),strlen(env('WALLET_SERVICE_NAME'))+1), $request->all()
|
substr($request->getRequestUri(),strlen(env('WALLET_SERVICE_NAME'))+1), $request->all(),$request->header()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function put(Request $request)
|
public function put(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
return $this->successResponse($this->walletService->put(
|
return $this->successResponse($this->walletService->put(
|
||||||
substr($request->getRequestUri(),strlen(env('WALLET_SERVICE_NAME'))+1), $request->all()
|
substr($request->getRequestUri(),strlen(env('WALLET_SERVICE_NAME'))+1), $request->all(),$request->header()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class Localization
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle($request, Closure $next)
|
||||||
|
{
|
||||||
|
$enLangs=["en","en-US","en_US","ca","in","gb","GB","us","en-029","en-AU","en-BZ","en-CA","en-GB","en-IE","en-IN","en-JM","en-MY","en-NZ","en-PH","en-SG","en-TT","en-US","en-ZA","en-ZW","au","bz","ie","in","jm","my","nz","ph","sg","tt","za"];
|
||||||
|
|
||||||
|
// Check header request and determine localizaton
|
||||||
|
if ($request->hasHeader('X-localization')){
|
||||||
|
$local = $request->header('X-localization');
|
||||||
|
$pos=strpos($local,"-");
|
||||||
|
if($pos!=false){
|
||||||
|
$local=strtolower(explode("-",$local)[0]);
|
||||||
|
}
|
||||||
|
$local= in_array($local, $enLangs) ? 'en' : 'fr';
|
||||||
|
}else{
|
||||||
|
$local ='fr';
|
||||||
|
}
|
||||||
|
// set laravel localization
|
||||||
|
app()->setLocale($local);
|
||||||
|
// continue request
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,18 +24,18 @@ class WalletService
|
||||||
$this->key = config('services.wallet_service.key');
|
$this->key = config('services.wallet_service.key');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function post($uri , $data)
|
public function post($uri , $data, $headers)
|
||||||
{
|
{
|
||||||
return $this->perfomRequest('POST',$uri,$data);
|
return $this->perfomRequest('POST',$uri,$data,$headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get($uri , $data)
|
public function get($uri , $data, $headers)
|
||||||
{
|
{
|
||||||
return $this->perfomRequest('GET',$uri,$data);
|
return $this->perfomRequest('GET',$uri,$data,$headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function put($uri , $data)
|
public function put($uri , $data, $headers)
|
||||||
{
|
{
|
||||||
return $this->perfomRequest('PUT',$uri,$data);
|
return $this->perfomRequest('PUT',$uri,$data,$headers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,13 +14,14 @@ trait ConsumesExternalService
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function perfomRequest($method, $requestUrl, $body = [], $formParams = [], $headers = [])
|
public function perfomRequest($method, $requestUrl, $body = [], $headers = [], $formParams = [])
|
||||||
{
|
{
|
||||||
$client = new Client([
|
$client = new Client([
|
||||||
'base_uri' => $this->baseUri,
|
'base_uri' => $this->baseUri,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if(isset($this->key)){
|
if(isset($this->key)){
|
||||||
|
unset($headers['authorization']);
|
||||||
$headers['Authorization'] = $this->key;
|
$headers['Authorization'] = $this->key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,9 +78,10 @@ $app->configure('app');
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// $app->middleware([
|
$app->middleware([
|
||||||
|
App\Http\Middleware\Localization::class,
|
||||||
// App\Http\Middleware\ExampleMiddleware::class
|
// App\Http\Middleware\ExampleMiddleware::class
|
||||||
// ]);
|
]);
|
||||||
|
|
||||||
$app->routeMiddleware([
|
$app->routeMiddleware([
|
||||||
'auth' => App\Http\Middleware\Authenticate::class,
|
'auth' => App\Http\Middleware\Authenticate::class,
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
<?php
|
||||||
|
return [
|
||||||
|
'model_not_found' => 'Does not exist any instance of :model with given id',
|
||||||
|
'unexpected_error'=> 'Unexpected error. Try later'
|
||||||
|
];
|
|
@ -0,0 +1,5 @@
|
||||||
|
<?php
|
||||||
|
return [
|
||||||
|
'model_not_found' => 'Il n\'existe aucune instance de :model avec l\'id donné',
|
||||||
|
'unexpected_error'=> 'Erreur inattendue. Essayer plus tard'
|
||||||
|
];
|
|
@ -34,17 +34,19 @@
|
||||||
/**
|
/**
|
||||||
* Routes for MobileBackendTest
|
* Routes for MobileBackendTest
|
||||||
*/
|
*/
|
||||||
$router->group(['prefix' => '/mobilebackendtest/interacted' , 'middleware' => 'auth:api'], function () use ($router){
|
$router->group(['prefix' => '/mobilebackendtest/interacted'], function () use ($router){
|
||||||
|
|
||||||
$router->post('LoginAction', 'MobileBackendTestController@action');
|
$router->post('LoginAction', 'MobileBackendTestController@action');
|
||||||
$router->post('BalanceAction', 'MobileBackendTestController@action');
|
|
||||||
$router->post('ConfigAction', 'MobileBackendTestController@action');
|
|
||||||
$router->post('DemandeAction', 'MobileBackendTestController@action');
|
|
||||||
$router->post('MembersAction', 'MobileBackendTestController@action');
|
$router->post('MembersAction', 'MobileBackendTestController@action');
|
||||||
$router->post('LocationAction', 'MobileBackendTestController@action');
|
|
||||||
$router->post('NetworkAction', 'MobileBackendTestController@action');
|
|
||||||
$router->post('WalletAction', 'MobileBackendTestController@action');
|
|
||||||
|
|
||||||
|
$router->group(['middleware' => 'auth:api'], function () use ($router){
|
||||||
|
$router->post('BalanceAction', 'MobileBackendTestController@action');
|
||||||
|
$router->post('ConfigAction', 'MobileBackendTestController@action');
|
||||||
|
$router->post('DemandeAction', 'MobileBackendTestController@action');
|
||||||
|
$router->post('LocationAction', 'MobileBackendTestController@action');
|
||||||
|
$router->post('NetworkAction', 'MobileBackendTestController@action');
|
||||||
|
$router->post('WalletAction', 'MobileBackendTestController@action');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,22 +56,22 @@
|
||||||
|
|
||||||
// Transactions routes
|
// Transactions routes
|
||||||
$router->group(['prefix' => '/transactions'] , function () use ($router){
|
$router->group(['prefix' => '/transactions'] , function () use ($router){
|
||||||
$router->post('','WalletController@post');
|
$router->post('','WalletServiceController@post');
|
||||||
$router->get('{id_wallet}','WalletController@get');
|
$router->get('{id_wallet}','WalletServiceController@get');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Credits routes
|
// Credits routes
|
||||||
$router->group(['prefix' => '/credits'] , function () use ($router){
|
$router->group(['prefix' => '/credits'] , function () use ($router){
|
||||||
$router->put('treatDemand/{id_demand}','WalletController@put');
|
$router->put('treatDemand/{id_demand}','WalletServiceController@put');
|
||||||
$router->put('cancelDemand/{id_demand}','WalletController@put');
|
$router->put('cancelDemand/{id_demand}','WalletServiceController@put');
|
||||||
});
|
});
|
||||||
|
|
||||||
$router->put('/virement/{id_wallet}','WalletController@put');
|
$router->put('/virement/{id_wallet}','WalletServiceController@put');
|
||||||
|
|
||||||
// Wallets routes
|
// Wallets routes
|
||||||
$router->group(['prefix' => '/wallets'] , function () use ($router){
|
$router->group(['prefix' => '/wallets'] , function () use ($router){
|
||||||
$router->get('{id_agent}/activated', 'WalletController@get');
|
$router->get('{id_agent}/activated', 'WalletServiceController@get');
|
||||||
$router->get('{id_wallet}', 'WalletController@get');
|
$router->get('{id_wallet}', 'WalletServiceController@get');
|
||||||
$router->post('', 'WalletController@post');
|
$router->post('', 'WalletServiceController@post');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue