[CLEAR-29] Retrieving list of products
This commit is contained in:
parent
c3d2c3330c
commit
f7d3aa68b9
@ -4,10 +4,12 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\AddProductRequest;
|
||||
use App\Repositories\ProductsRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ProductsController extends Controller
|
||||
{
|
||||
private ProductsRepositoryInterface $productsRepository;
|
||||
private int $paginationSize = 10;
|
||||
|
||||
public function __construct(ProductsRepositoryInterface $productsRepository)
|
||||
{
|
||||
@ -20,4 +22,11 @@ class ProductsController extends Controller
|
||||
|
||||
return response()->json(['success' => true, 'data' => ['product' => $product]], 200);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$products = $this->productsRepository->paginate($this->paginationSize);
|
||||
|
||||
return response()->json(['success' => true, 'data' => ['products' => $products]], 200);
|
||||
}
|
||||
}
|
||||
|
@ -12,4 +12,9 @@ class ProductsRepository implements ProductsRepositoryInterface
|
||||
{
|
||||
return Product::create($data);
|
||||
}
|
||||
|
||||
public function paginate($chunkSize)
|
||||
{
|
||||
return Product::paginate($chunkSize);
|
||||
}
|
||||
}
|
||||
|
@ -6,4 +6,5 @@ namespace App\Repositories;
|
||||
interface ProductsRepositoryInterface
|
||||
{
|
||||
public function create($data);
|
||||
public function paginate($chunkSize);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ Route::group(['prefix' => 'user', 'middleware' => ['assign.guard:users']], funct
|
||||
Route::get('/me', 'UsersController@me');
|
||||
});
|
||||
|
||||
Route::group(['prefix' => 'product', 'middleware' => ['assign.guard:users']], function () {
|
||||
Route::post('/', 'ProductsController@add');
|
||||
Route::prefix('product')->group(function () {
|
||||
Route::post('/', 'ProductsController@add')->middleware(['assign.guard:users']);
|
||||
Route::get('/', 'ProductsController@index');
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user