mirror of
https://gitlab.com/izyim/prototypes/lumen-microservices/microservice-api-gateway.git
synced 2026-08-28 08:54:28 +00:00
initial commit
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Traits\ApiResponse;
|
||||
use Laravel\Lumen\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use ApiResponse;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\OrderService;
|
||||
use App\Services\ProductService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
|
||||
private $orderService;
|
||||
private $productService;
|
||||
|
||||
public function __construct(OrderService $orderService, ProductService $productService)
|
||||
{
|
||||
$this->orderService = $orderService;
|
||||
$this->productService = $productService;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return $this->successResponse($this->orderService->fetchOrders());
|
||||
}
|
||||
|
||||
public function show($order)
|
||||
{
|
||||
return $this->successResponse($this->orderService->fetchOrder($order));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$result = $this->productService->fetchProduct($request->product_id);
|
||||
// dd($result);
|
||||
|
||||
return $this->successResponse($this->orderService->createOrder($request->all()));
|
||||
}
|
||||
|
||||
public function update(Request $request, $order)
|
||||
{
|
||||
return $this->successResponse($this->orderService->updateOrder($order, $request->all()));
|
||||
}
|
||||
|
||||
public function destroy($order)
|
||||
{
|
||||
return $this->successResponse($this->orderService->deleteOrder($order));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\ProductService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ProductController extends Controller
|
||||
{
|
||||
|
||||
private $productService;
|
||||
|
||||
public function __construct(ProductService $productService)
|
||||
{
|
||||
$this->productService = $productService;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return $this->successResponse($this->productService->fetchProducts());
|
||||
}
|
||||
|
||||
public function show($product)
|
||||
{
|
||||
return $this->successResponse($this->productService->fetchProduct($product));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
return $this->successResponse($this->productService->createProduct($request->all()));
|
||||
}
|
||||
|
||||
public function update(Request $request, $product)
|
||||
{
|
||||
return $this->successResponse($this->productService->updateProduct($product, $request->all()));
|
||||
}
|
||||
|
||||
public function destroy($product)
|
||||
{
|
||||
return $this->successResponse($this->productService->deleteProduct($product));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Auth\Factory as Auth;
|
||||
|
||||
class Authenticate
|
||||
{
|
||||
/**
|
||||
* The authentication guard factory instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Auth\Factory
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* Create a new middleware instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Auth\Factory $auth
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Auth $auth)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
if ($this->auth->guard($guard)->guest()) {
|
||||
return response('Unauthorized.', 401);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
|
||||
class ExampleMiddleware
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user