Commit 9891271d authored by 20194288-huannh's avatar 20194288-huannh

update code OrderController after review part 2

parent fd057283
......@@ -25,16 +25,8 @@ public function __construct(OrderRepository $orderRepository)
public function index(GetOrderRequest $request)
{
$user = auth('api')->user()->id;
switch ($user->role) {
case User::ROLE_ADMIN:
$order = $this->orderRepository->getListOrderOfAdmin($request->status);
break;
case User::ROLE_EDITOR:
$order = $this->orderRepository->getListOrderOfUser($user);
break;
default:
$order = collect([]);
}
$order = $user->role == User::ROLE_ADMIN ? $this->orderRepository->getListOrderOfAdmin($request->all())
: $this->orderRepository->getListOrderOfUser($user);
return response()->json([
'success' => true,
'meta' => [
......@@ -110,8 +102,9 @@ public function update(Request $request, $id)
$request->only(['id', 'details', 'client', 'is_fulfilled'])
);
return response()->json([
'success' => $is_update ? true : false,
'message' => ''
'success' => true,
'message' => '',
'data' => $is_update
]);
}
......@@ -125,8 +118,9 @@ public function destroy(Request $request)
{
$is_deleted = $this->orderRepository->deleteById($request->id);
return response()->json([
'success' => $is_deleted ? true : false,
'message' => ''
'success' => true,
'message' => '',
'data' => $is_deleted
]);
}
}
......@@ -27,7 +27,7 @@ public function index(GetOrderRequest $request)
$user = auth('api')->user()->id;
switch ($user->role) {
case User::ROLE_ADMIN:
$order = $this->orderRepository->getListOrderOfAdmin($request->status);
$order = $this->orderRepository->getListOrderOfAdmin($request->all());
break;
case User::ROLE_EDITOR:
$order = $this->orderRepository->getListOrderOfUser($user);
......
......@@ -24,7 +24,7 @@ public function authorize()
public function rules()
{
return [
'status' => 'required|integer'
'status' => 'integer'
];
}
}
......@@ -23,9 +23,13 @@ public function getFulfilledOrder()
$this->model->where('is_fulfilled', true);
}
public function getListOrderOfAdmin($status)
public function getListOrderOfAdmin(array $params)
{
return $this->model->latest()->where('status', $status)->paginate();
$query = $this->model;
foreach ($params as $key => $value) {
$query = $query->where($key, $value);
}
return $query->paginate();
}
public function getListOrderOfUser($id)
{
......
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