mirror of
https://gitlab.com/izyim/prototypes/lumen-microservices/microservice-api-gateway.git
synced 2026-08-19 04:24:15 +00:00
fixing missed step
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace App\Console;
|
namespace App\Console;
|
||||||
|
|
||||||
use Illuminate\Console\Scheduling\Schedule;
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
@@ -12,18 +14,16 @@ class Kernel extends ConsoleKernel
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $commands = [
|
protected $commands = [];
|
||||||
//
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define the application's command schedule.
|
* Define the application's command schedule.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace App\Events;
|
namespace App\Events;
|
||||||
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace App\Events;
|
namespace App\Events;
|
||||||
|
|
||||||
class ExampleEvent extends Event
|
class ExampleEvent extends Event
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Create a new event instance.
|
* Create a new event instance.
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
//
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace App\Exceptions;
|
namespace App\Exceptions;
|
||||||
|
|
||||||
use App\Traits\ApiResponse;
|
use App\Traits\ApiResponse;
|
||||||
@@ -13,6 +15,8 @@ use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|||||||
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
|
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
|
||||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||||
|
|
||||||
|
use function env;
|
||||||
|
|
||||||
class Handler extends ExceptionHandler
|
class Handler extends ExceptionHandler
|
||||||
{
|
{
|
||||||
use ApiResponse;
|
use ApiResponse;
|
||||||
@@ -51,7 +55,6 @@ class Handler extends ExceptionHandler
|
|||||||
*/
|
*/
|
||||||
public function render($request, Exception $exception)
|
public function render($request, Exception $exception)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($exception instanceof HttpException) {
|
if ($exception instanceof HttpException) {
|
||||||
$errorCode = $exception->getStatusCode();
|
$errorCode = $exception->getStatusCode();
|
||||||
$errorMessage = Response::$statusTexts[$errorCode];
|
$errorMessage = Response::$statusTexts[$errorCode];
|
||||||
@@ -99,6 +102,5 @@ class Handler extends ExceptionHandler
|
|||||||
return $this->errorResponse(
|
return $this->errorResponse(
|
||||||
"Unexpected error. Try later!",
|
"Unexpected error. Try later!",
|
||||||
Response::HTTP_INTERNAL_SERVER_ERROR);
|
Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Traits\ApiResponse;
|
use App\Traits\ApiResponse;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Services\OrderService;
|
use App\Services\OrderService;
|
||||||
@@ -8,42 +10,74 @@ use Illuminate\Http\Request;
|
|||||||
|
|
||||||
class OrderController extends Controller
|
class OrderController extends Controller
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var \App\Services\OrderService
|
||||||
|
*/
|
||||||
|
protected $orderService;
|
||||||
|
|
||||||
private $orderService;
|
/**
|
||||||
private $productService;
|
* @var \App\Services\ProductService
|
||||||
|
*/
|
||||||
|
protected $productService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OrderController constructor.
|
||||||
|
*
|
||||||
|
* @param \App\Services\OrderService $orderService
|
||||||
|
* @param \App\Services\ProductService $productService
|
||||||
|
*/
|
||||||
public function __construct(OrderService $orderService, ProductService $productService)
|
public function __construct(OrderService $orderService, ProductService $productService)
|
||||||
{
|
{
|
||||||
$this->orderService = $orderService;
|
$this->orderService = $orderService;
|
||||||
$this->productService = $productService;
|
$this->productService = $productService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
return $this->successResponse($this->orderService->fetchOrders());
|
return $this->successResponse($this->orderService->fetchOrders());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $order
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function show($order)
|
public function show($order)
|
||||||
{
|
{
|
||||||
return $this->successResponse($this->orderService->fetchOrder($order));
|
return $this->successResponse($this->orderService->fetchOrder($order));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$result = $this->productService->fetchProduct($request->product_id);
|
|
||||||
// dd($result);
|
|
||||||
|
|
||||||
return $this->successResponse($this->orderService->createOrder($request->all()));
|
return $this->successResponse($this->orderService->createOrder($request->all()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param $order
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function update(Request $request, $order)
|
public function update(Request $request, $order)
|
||||||
{
|
{
|
||||||
return $this->successResponse($this->orderService->updateOrder($order, $request->all()));
|
return $this->successResponse($this->orderService->updateOrder($order, $request->all()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $order
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function destroy($order)
|
public function destroy($order)
|
||||||
{
|
{
|
||||||
return $this->successResponse($this->orderService->deleteOrder($order));
|
return $this->successResponse($this->orderService->deleteOrder($order));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Services\ProductService;
|
use App\Services\ProductService;
|
||||||
@@ -10,33 +12,62 @@ class ProductController extends Controller
|
|||||||
|
|
||||||
private $productService;
|
private $productService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ProductController constructor.
|
||||||
|
*
|
||||||
|
* @param \App\Services\ProductService $productService
|
||||||
|
*/
|
||||||
public function __construct(ProductService $productService)
|
public function __construct(ProductService $productService)
|
||||||
{
|
{
|
||||||
$this->productService = $productService;
|
$this->productService = $productService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
return $this->successResponse($this->productService->fetchProducts());
|
return $this->successResponse($this->productService->fetchProducts());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $product
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function show($product)
|
public function show($product)
|
||||||
{
|
{
|
||||||
return $this->successResponse($this->productService->fetchProduct($product));
|
return $this->successResponse($this->productService->fetchProduct($product));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
return $this->successResponse($this->productService->createProduct($request->all()));
|
return $this->successResponse($this->productService->createProduct($request->all()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param $product
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function update(Request $request, $product)
|
public function update(Request $request, $product)
|
||||||
{
|
{
|
||||||
return $this->successResponse($this->productService->updateProduct($product, $request->all()));
|
return $this->successResponse($this->productService->updateProduct($product, $request->all()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $product
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function destroy($product)
|
public function destroy($product)
|
||||||
{
|
{
|
||||||
return $this->successResponse($this->productService->deleteProduct($product));
|
return $this->successResponse($this->productService->deleteProduct($product));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Contracts\Auth\Factory as Auth;
|
use Illuminate\Contracts\Auth\Factory as Auth;
|
||||||
|
|
||||||
|
use function response;
|
||||||
|
|
||||||
class Authenticate
|
class Authenticate
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace App\Jobs;
|
namespace App\Jobs;
|
||||||
|
|
||||||
class ExampleJob extends Job
|
class ExampleJob extends Job
|
||||||
@@ -11,7 +13,6 @@ class ExampleJob extends Job
|
|||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
//
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,8 +20,7 @@ class ExampleJob extends Job
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle() : void
|
||||||
{
|
{
|
||||||
//
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace App\Jobs;
|
namespace App\Jobs;
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace App\Listeners;
|
namespace App\Listeners;
|
||||||
|
|
||||||
use App\Events\ExampleEvent;
|
use App\Events\ExampleEvent;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
|
|
||||||
class ExampleListener
|
class ExampleListener
|
||||||
{
|
{
|
||||||
@@ -15,7 +15,6 @@ class ExampleListener
|
|||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
//
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,6 +25,5 @@ class ExampleListener
|
|||||||
*/
|
*/
|
||||||
public function handle(ExampleEvent $event)
|
public function handle(ExampleEvent $event)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
@@ -13,6 +15,5 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
//
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use App\User;
|
|
||||||
use Dusterio\LumenPassport\LumenPassport;
|
use Dusterio\LumenPassport\LumenPassport;
|
||||||
use Illuminate\Support\Facades\Gate;
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
class AuthServiceProvider extends ServiceProvider
|
class AuthServiceProvider extends ServiceProvider
|
||||||
@@ -16,11 +16,16 @@ class AuthServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
//
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Boot the authentication services for the application.
|
* Boot the authentication services for the application.
|
||||||
|
* If you desire to handle the request via simple mechanism
|
||||||
|
* $this->app['auth']->viaRequest('api', function ($request) {
|
||||||
|
* if ($request->input('api_token')) {
|
||||||
|
* return User::where('api_token', $request->input('api_token'))->first();
|
||||||
|
* }
|
||||||
|
* });
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@@ -31,12 +36,6 @@ class AuthServiceProvider extends ServiceProvider
|
|||||||
// should return either a User instance or null. You're free to obtain
|
// should return either a User instance or null. You're free to obtain
|
||||||
// the User instance via an API token or any other method necessary.
|
// the User instance via an API token or any other method necessary.
|
||||||
|
|
||||||
// $this->app['auth']->viaRequest('api', function ($request) {
|
|
||||||
// if ($request->input('api_token')) {
|
|
||||||
// return User::where('api_token', $request->input('api_token'))->first();
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
LumenPassport::routes($this->app->router);
|
LumenPassport::routes($this->app->router);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use Laravel\Lumen\Providers\EventServiceProvider as ServiceProvider;
|
use Laravel\Lumen\Providers\EventServiceProvider as ServiceProvider;
|
||||||
|
|||||||
@@ -1,15 +1,26 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
use App\Traits\RequestService;
|
use App\Traits\RequestService;
|
||||||
|
|
||||||
|
use function config;
|
||||||
|
|
||||||
class OrderService
|
class OrderService
|
||||||
{
|
{
|
||||||
use RequestService;
|
use RequestService;
|
||||||
|
|
||||||
public $baseUri;
|
/**
|
||||||
public $secret;
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $baseUri;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $secret;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@@ -17,28 +28,52 @@ class OrderService
|
|||||||
$this->secret = config('services.orders.secret');
|
$this->secret = config('services.orders.secret');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetchOrders()
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function fetchOrders() : string
|
||||||
{
|
{
|
||||||
return $this->request('GET', '/api/order');
|
return $this->request('GET', '/api/order');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetchOrder($order)
|
/**
|
||||||
|
* @param $order
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function fetchOrder($order) : string
|
||||||
{
|
{
|
||||||
return $this->request('GET', "/api/order/{$order}");
|
return $this->request('GET', "/api/order/{$order}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createOrder($data)
|
/**
|
||||||
|
* @param $data
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function createOrder($data) : string
|
||||||
{
|
{
|
||||||
return $this->request('POST', '/api/order', $data);
|
return $this->request('POST', '/api/order', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateOrder($order, $data)
|
/**
|
||||||
|
* @param $order
|
||||||
|
* @param $data
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function updateOrder($order, $data) : string
|
||||||
{
|
{
|
||||||
return $this->request('PATCH', "/api/order/{$order}", $data);
|
return $this->request('PATCH', "/api/order/{$order}", $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteOrder($order)
|
/**
|
||||||
|
* @param $order
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function deleteOrder($order) : string
|
||||||
{
|
{
|
||||||
return $this->request('DELETE', "/api/order/{$order}");
|
return $this->request('DELETE', "/api/order/{$order}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,46 +1,82 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
use App\Traits\RequestService;
|
use App\Traits\RequestService;
|
||||||
|
|
||||||
|
use function config;
|
||||||
|
|
||||||
class ProductService
|
class ProductService
|
||||||
{
|
{
|
||||||
use RequestService;
|
use RequestService;
|
||||||
|
|
||||||
public $baseUri;
|
/**
|
||||||
public $secret;
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $baseUri;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $secret;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ProductService constructor.
|
||||||
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->baseUri = config('services.products.base_uri');
|
$this->baseUri = config('services.products.base_uri');
|
||||||
$this->secret = config('services.products.secret');
|
$this->secret = config('services.products.secret');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
public function fetchProducts()
|
* @return string
|
||||||
|
*/
|
||||||
|
public function fetchProducts() : string
|
||||||
{
|
{
|
||||||
return $this->request('GET', '/api/product');
|
return $this->request('GET', '/api/product');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetchProduct($product)
|
/**
|
||||||
|
* @param $product
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function fetchProduct($product) : string
|
||||||
{
|
{
|
||||||
return $this->request('GET', "/api/product/{$product}");
|
return $this->request('GET', "/api/product/{$product}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createProduct($data)
|
/**
|
||||||
|
* @param $data
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function createProduct($data) : string
|
||||||
{
|
{
|
||||||
return $this->request('POST', '/api/product', $data);
|
return $this->request('POST', '/api/product', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateProduct($product, $data)
|
/**
|
||||||
|
* @param $product
|
||||||
|
* @param $data
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function updateProduct($product, $data) : string
|
||||||
{
|
{
|
||||||
return $this->request('PATCH', "/api/product/{$product}", $data);
|
return $this->request('PATCH', "/api/product/{$product}", $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteProduct($product)
|
/**
|
||||||
|
* @param $product
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function deleteProduct($product) : string
|
||||||
{
|
{
|
||||||
return $this->request('DELETE', "/api/product/{$product}");
|
return $this->request('DELETE', "/api/product/{$product}");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,26 +1,45 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace App\Traits;
|
namespace App\Traits;
|
||||||
|
|
||||||
|
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
|
use function response;
|
||||||
|
|
||||||
trait ApiResponse
|
trait ApiResponse
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param $data
|
||||||
|
* @param int $statusCode
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function successResponse($data, $statusCode = Response::HTTP_OK)
|
public function successResponse($data, $statusCode = Response::HTTP_OK)
|
||||||
{
|
{
|
||||||
return response($data, $statusCode)->header('Content-Type', 'application/json');
|
return response($data, $statusCode)->header('Content-Type', 'application/json');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $errorMessage
|
||||||
|
* @param $statusCode
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function errorResponse($errorMessage, $statusCode)
|
public function errorResponse($errorMessage, $statusCode)
|
||||||
{
|
{
|
||||||
return response()->json(['error' => $errorMessage, 'error_code' => $statusCode], $statusCode);
|
return response()->json(['error' => $errorMessage, 'error_code' => $statusCode], $statusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $errorMessage
|
||||||
|
* @param $statusCode
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function errorMessage($errorMessage, $statusCode)
|
public function errorMessage($errorMessage, $statusCode)
|
||||||
{
|
{
|
||||||
return response($errorMessage, $statusCode)->header('Content-Type', 'application/json');
|
return response($errorMessage, $statusCode)->header('Content-Type', 'application/json');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,39 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace App\Traits;
|
namespace App\Traits;
|
||||||
|
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
|
||||||
trait RequestService
|
trait RequestService
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
public function request($method, $requestUrl, $formParams = [], $headers = [])
|
* @param $method
|
||||||
|
* @param $requestUrl
|
||||||
|
* @param array $formParams
|
||||||
|
* @param array $headers
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||||
|
*/
|
||||||
|
public function request($method, $requestUrl, $formParams = [], $headers = []) : string
|
||||||
{
|
{
|
||||||
$client = new Client([
|
$client = new Client([
|
||||||
'base_uri' => $this->baseUri
|
'base_uri' => $this->baseUri
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (isset($this->secret)) {
|
if (isset($this->secret)) {
|
||||||
$headers['Authorization'] = $this->secret;
|
$headers['Authorization'] = $this->secret;
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = $client->request($method, $requestUrl,
|
$response = $client->request($method, $requestUrl,
|
||||||
[
|
[
|
||||||
'form_params' => $formParams,
|
'form_params' => $formParams,
|
||||||
'headers' => $headers
|
'headers' => $headers
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
return $response->getBody()->getContents();
|
return $response->getBody()->getContents();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|||||||
+5
-3
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
use Illuminate\Auth\Authenticatable;
|
use Illuminate\Auth\Authenticatable;
|
||||||
@@ -15,10 +17,10 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
|||||||
/**
|
/**
|
||||||
* The attributes that are mass assignable.
|
* The attributes that are mass assignable.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'name', 'email',
|
'name', 'email'
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,4 +31,4 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
|||||||
protected $hidden = [
|
protected $hidden = [
|
||||||
'password',
|
'password',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -1,9 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
require_once __DIR__.'/../vendor/autoload.php';
|
require_once __DIR__.'/../vendor/autoload.php';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
(new Dotenv\Dotenv(dirname(__DIR__)))->load();
|
(new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
|
||||||
|
dirname(__DIR__)
|
||||||
|
))->bootstrap();
|
||||||
} catch (Dotenv\Exception\InvalidPathException $e) {
|
} catch (Dotenv\Exception\InvalidPathException $e) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-4
@@ -8,13 +8,14 @@
|
|||||||
"php": ">=7.1.3",
|
"php": ">=7.1.3",
|
||||||
"dusterio/lumen-passport": "^0.2.15",
|
"dusterio/lumen-passport": "^0.2.15",
|
||||||
"guzzlehttp/guzzle": "^6.5",
|
"guzzlehttp/guzzle": "^6.5",
|
||||||
"laravel/lumen-framework": "5.7.*",
|
"laravel/lumen-framework": "5.8.*",
|
||||||
"vlucas/phpdotenv": "~2.2"
|
"lcobucci/jwt": "3.3.3",
|
||||||
|
"vlucas/phpdotenv": "^3.3"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"fzaninotto/faker": "~1.4",
|
"fzaninotto/faker": "~1.4",
|
||||||
"phpunit/phpunit": "~7.0",
|
"mockery/mockery": "~1.0",
|
||||||
"mockery/mockery": "~1.0"
|
"phpunit/phpunit": "~7.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"classmap": [
|
"classmap": [
|
||||||
|
|||||||
+3
-1
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'defaults' => [
|
'defaults' => [
|
||||||
'guard' => 'api',
|
'guard' => 'api',
|
||||||
@@ -19,4 +21,4 @@ return [
|
|||||||
'model' => \App\User::class
|
'model' => \App\User::class
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|||||||
+2
-1
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'products' => [
|
'products' => [
|
||||||
@@ -10,4 +11,4 @@ return [
|
|||||||
'base_uri' => env('ORDERS_SERVICE_BASE_URI'),
|
'base_uri' => env('ORDERS_SERVICE_BASE_URI'),
|
||||||
'secret' => env('ORDERS_SERVICE_SECRET'),
|
'secret' => env('ORDERS_SERVICE_SECRET'),
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Model Factories
|
| Model Factories
|
||||||
@@ -10,4 +12,3 @@
|
|||||||
| database. Just tell the factory how a default model should look.
|
| database. Just tell the factory how a default model should look.
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class AddUsersTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up() : void
|
||||||
|
{
|
||||||
|
Schema::create('users', function (Blueprint $table) {
|
||||||
|
$table->bigIncrements('id');
|
||||||
|
$table->string('name', 256);
|
||||||
|
$table->string('email', 256);
|
||||||
|
$table->string('password', 512);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down() : void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('users');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
class DatabaseSeeder extends Seeder
|
class DatabaseSeeder extends Seeder
|
||||||
@@ -11,6 +13,7 @@ class DatabaseSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
// $this->call('UsersTableSeeder');
|
\Illuminate\Support\Facades\Artisan::call('passport:install');
|
||||||
|
$this->call(UserTableSeeder::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|
||||||
|
class UserTableSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
\App\User::create([
|
||||||
|
'name' => 'user1',
|
||||||
|
'email' => 'user1@gmail.com',
|
||||||
|
'password' => Hash::make('123456')
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Create The Application
|
| Create The Application
|
||||||
|
|||||||
+3
-1
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Application Routes
|
| Application Routes
|
||||||
@@ -29,4 +31,4 @@ $router->group(['prefix' => 'api', 'middleware' => ['client.credentials']], func
|
|||||||
$router->delete('/{order}', ['uses' => 'OrderController@destroy']);
|
$router->delete('/{order}', ['uses' => 'OrderController@destroy']);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user