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) ...@@ -26,8 +26,8 @@ public function index(GetOrderRequest $request)
{ {
$user = auth('api')->user(); $user = auth('api')->user();
$order = $user->role == User::ROLE_ADMIN ? $order = $user->role == User::ROLE_ADMIN ?
$this->orderRepository->getListOrder($request->all())->paginate() $this->orderRepository->getListOrder($request->all())
: $this->orderRepository->getListOrderOfUser($user->id, $request->all()); : $this->orderRepository->getListOrder($request->all(), $user->id);
return response()->json([ return response()->json([
'success' => true, 'success' => true,
'meta' => [ 'meta' => [
...@@ -96,7 +96,7 @@ public function edit(Request $request) ...@@ -96,7 +96,7 @@ public function edit(Request $request)
* @param int $id * @param int $id
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function update(Request $request, $id) public function update(Request $request)
{ {
$is_update = $this->orderRepository->update( $is_update = $this->orderRepository->update(
$request->id, $request->id,
......
<?php <?php
namespace App\Http\Controllers\Api; namespace App\Http\Controllers;
use App\Http\Resources\OrderResource; use App\Http\Resources\OrderResource;
use App\Repositories\OrderRepository; use App\Repositories\OrderRepository;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Repositories\UserRepository;
use App\Http\Requests\GetOrderRequest; use App\Http\Requests\GetOrderRequest;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\User; use App\Models\User;
...@@ -26,8 +25,8 @@ public function index(GetOrderRequest $request) ...@@ -26,8 +25,8 @@ public function index(GetOrderRequest $request)
{ {
$user = auth('api')->user(); $user = auth('api')->user();
$order = $user->role == User::ROLE_ADMIN ? $order = $user->role == User::ROLE_ADMIN ?
$this->orderRepository->getListOrder($request->all())->paginate() $this->orderRepository->getListOrder($request->all())
: $this->orderRepository->getListOrderOfUser($user->id, $request->all()); : $this->orderRepository->getListOrder($request->all(), $user->id);
return response()->json([ return response()->json([
'success' => true, 'success' => true,
'meta' => [ 'meta' => [
......
...@@ -24,7 +24,8 @@ public function authorize() ...@@ -24,7 +24,8 @@ public function authorize()
public function rules() public function rules()
{ {
return [ return [
'status' => 'integer' 'status' => 'integer',
'keyword' => 'max:255'
]; ];
} }
} }
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
use App\Models\Order; use App\Models\Order;
use App\Repositories\BaseRepository; use App\Repositories\BaseRepository;
use Log;
class OrderRepository extends BaseRepository class OrderRepository extends BaseRepository
{ {
...@@ -24,9 +23,12 @@ public function getFulfilledOrder() ...@@ -24,9 +23,12 @@ public function getFulfilledOrder()
$this->model->where('is_fulfilled', true); $this->model->where('is_fulfilled', true);
} }
public function getListOrder(array $params) public function getListOrder(array $params, $id = 0)
{ {
$query = $this->model; $query = $this->model;
if (!$id){
$query = $query->where('user_id', $id);
}
if (isset($params['status'])) { if (isset($params['status'])) {
$query = $query->where('status', $params['status']); $query = $query->where('status', $params['status']);
} }
...@@ -42,10 +44,6 @@ public function getListOrder(array $params) ...@@ -42,10 +44,6 @@ public function getListOrder(array $params)
}); });
}); });
} }
return $query; return $query->paginate();
}
public function getListOrderOfUser($id, array $params = [])
{
return $this->getListOrder($params)->where('user_id', $id)->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