Commit f39ee5a5 authored by 20194288-huannh's avatar 20194288-huannh

update OrderController part 3

parent d5f42690
......@@ -26,8 +26,8 @@ public function index(GetOrderRequest $request)
{
$user = auth('api')->user();
$order = $user->role == User::ROLE_ADMIN ?
$this->orderRepository->getListOrder($request->all())->paginate()
: $this->orderRepository->getListOrderOfUser($user->id, $request->all());
$this->orderRepository->getListOrder($request->all())
: $this->orderRepository->getListOrder($request->all(), $user->id);
return response()->json([
'success' => true,
'meta' => [
......@@ -96,7 +96,7 @@ public function edit(Request $request)
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
public function update(Request $request)
{
$is_update = $this->orderRepository->update(
$request->id,
......
<?php
namespace App\Http\Controllers\Api;
namespace App\Http\Controllers;
use App\Http\Resources\OrderResource;
use App\Repositories\OrderRepository;
use App\Http\Controllers\Controller;
use App\Repositories\UserRepository;
use App\Http\Requests\GetOrderRequest;
use Illuminate\Http\Request;
use App\Models\User;
......@@ -26,8 +25,8 @@ public function index(GetOrderRequest $request)
{
$user = auth('api')->user();
$order = $user->role == User::ROLE_ADMIN ?
$this->orderRepository->getListOrder($request->all())->paginate()
: $this->orderRepository->getListOrderOfUser($user->id, $request->all());
$this->orderRepository->getListOrder($request->all())
: $this->orderRepository->getListOrder($request->all(), $user->id);
return response()->json([
'success' => true,
'meta' => [
......
......@@ -24,7 +24,8 @@ public function authorize()
public function rules()
{
return [
'status' => 'integer'
'status' => 'integer',
'keyword' => 'max:255'
];
}
}
......@@ -4,7 +4,6 @@
use App\Models\Order;
use App\Repositories\BaseRepository;
use Log;
class OrderRepository extends BaseRepository
{
......@@ -24,9 +23,12 @@ public function getFulfilledOrder()
$this->model->where('is_fulfilled', true);
}
public function getListOrder(array $params)
public function getListOrder(array $params, $id = 0)
{
$query = $this->model;
if (!$id){
$query = $query->where('user_id', $id);
}
if (isset($params['status'])) {
$query = $query->where('status', $params['status']);
}
......@@ -42,10 +44,6 @@ public function getListOrder(array $params)
});
});
}
return $query;
}
public function getListOrderOfUser($id, array $params = [])
{
return $this->getListOrder($params)->where('user_id', $id)->paginate();
return $query->paginate();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment