2019-12-04 12:49:41 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Http\Requests\AddProductRequest;
|
|
|
|
use App\Repositories\ProductsRepositoryInterface;
|
2019-12-05 10:25:36 +01:00
|
|
|
use Illuminate\Http\Request;
|
2019-12-04 12:49:41 +01:00
|
|
|
|
|
|
|
class ProductsController extends Controller
|
|
|
|
{
|
|
|
|
private ProductsRepositoryInterface $productsRepository;
|
2019-12-05 10:25:36 +01:00
|
|
|
private int $paginationSize = 10;
|
2019-12-04 12:49:41 +01:00
|
|
|
|
|
|
|
public function __construct(ProductsRepositoryInterface $productsRepository)
|
|
|
|
{
|
|
|
|
$this->productsRepository = $productsRepository;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function add(AddProductRequest $request)
|
|
|
|
{
|
|
|
|
$product = $this->productsRepository->create($request->all());
|
|
|
|
|
|
|
|
return response()->json(['success' => true, 'data' => ['product' => $product]], 200);
|
|
|
|
}
|
2019-12-05 10:25:36 +01:00
|
|
|
|
|
|
|
public function index(Request $request)
|
|
|
|
{
|
|
|
|
$products = $this->productsRepository->paginate($this->paginationSize);
|
|
|
|
|
|
|
|
return response()->json(['success' => true, 'data' => ['products' => $products]], 200);
|
|
|
|
}
|
2019-12-04 12:49:41 +01:00
|
|
|
}
|