Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
P
Project_Laravel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TTS Nguyen Huu Huan
Project_Laravel
Commits
9891271d
Commit
9891271d
authored
Sep 20, 2022
by
20194288-huannh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update code OrderController after review part 2
parent
fd057283
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
18 deletions
+16
-18
OrderController.php
app/Http/Controllers/Api/OrderController.php
+8
-14
OrderController.php
app/Http/Controllers/OrderController.php
+1
-1
GetOrderRequest.php
app/Http/Requests/GetOrderRequest.php
+1
-1
OrderRepository.php
app/Repositories/OrderRepository.php
+6
-2
No files found.
app/Http/Controllers/Api/OrderController.php
View file @
9891271d
...
@@ -25,16 +25,8 @@ public function __construct(OrderRepository $orderRepository)
...
@@ -25,16 +25,8 @@ public function __construct(OrderRepository $orderRepository)
public
function
index
(
GetOrderRequest
$request
)
public
function
index
(
GetOrderRequest
$request
)
{
{
$user
=
auth
(
'api'
)
->
user
()
->
id
;
$user
=
auth
(
'api'
)
->
user
()
->
id
;
switch
(
$user
->
role
)
{
$order
=
$user
->
role
==
User
::
ROLE_ADMIN
?
$this
->
orderRepository
->
getListOrderOfAdmin
(
$request
->
all
())
case
User
::
ROLE_ADMIN
:
:
$this
->
orderRepository
->
getListOrderOfUser
(
$user
);
$order
=
$this
->
orderRepository
->
getListOrderOfAdmin
(
$request
->
status
);
break
;
case
User
::
ROLE_EDITOR
:
$order
=
$this
->
orderRepository
->
getListOrderOfUser
(
$user
);
break
;
default
:
$order
=
collect
([]);
}
return
response
()
->
json
([
return
response
()
->
json
([
'success'
=>
true
,
'success'
=>
true
,
'meta'
=>
[
'meta'
=>
[
...
@@ -110,8 +102,9 @@ public function update(Request $request, $id)
...
@@ -110,8 +102,9 @@ public function update(Request $request, $id)
$request
->
only
([
'id'
,
'details'
,
'client'
,
'is_fulfilled'
])
$request
->
only
([
'id'
,
'details'
,
'client'
,
'is_fulfilled'
])
);
);
return
response
()
->
json
([
return
response
()
->
json
([
'success'
=>
$is_update
?
true
:
false
,
'success'
=>
true
,
'message'
=>
''
'message'
=>
''
,
'data'
=>
$is_update
]);
]);
}
}
...
@@ -125,8 +118,9 @@ public function destroy(Request $request)
...
@@ -125,8 +118,9 @@ public function destroy(Request $request)
{
{
$is_deleted
=
$this
->
orderRepository
->
deleteById
(
$request
->
id
);
$is_deleted
=
$this
->
orderRepository
->
deleteById
(
$request
->
id
);
return
response
()
->
json
([
return
response
()
->
json
([
'success'
=>
$is_deleted
?
true
:
false
,
'success'
=>
true
,
'message'
=>
''
'message'
=>
''
,
'data'
=>
$is_deleted
]);
]);
}
}
}
}
app/Http/Controllers/OrderController.php
View file @
9891271d
...
@@ -27,7 +27,7 @@ public function index(GetOrderRequest $request)
...
@@ -27,7 +27,7 @@ public function index(GetOrderRequest $request)
$user
=
auth
(
'api'
)
->
user
()
->
id
;
$user
=
auth
(
'api'
)
->
user
()
->
id
;
switch
(
$user
->
role
)
{
switch
(
$user
->
role
)
{
case
User
::
ROLE_ADMIN
:
case
User
::
ROLE_ADMIN
:
$order
=
$this
->
orderRepository
->
getListOrderOfAdmin
(
$request
->
status
);
$order
=
$this
->
orderRepository
->
getListOrderOfAdmin
(
$request
->
all
()
);
break
;
break
;
case
User
::
ROLE_EDITOR
:
case
User
::
ROLE_EDITOR
:
$order
=
$this
->
orderRepository
->
getListOrderOfUser
(
$user
);
$order
=
$this
->
orderRepository
->
getListOrderOfUser
(
$user
);
...
...
app/Http/Requests/GetOrderRequest.php
View file @
9891271d
...
@@ -24,7 +24,7 @@ public function authorize()
...
@@ -24,7 +24,7 @@ public function authorize()
public
function
rules
()
public
function
rules
()
{
{
return
[
return
[
'status'
=>
'
required|
integer'
'status'
=>
'integer'
];
];
}
}
}
}
app/Repositories/OrderRepository.php
View file @
9891271d
...
@@ -23,9 +23,13 @@ public function getFulfilledOrder()
...
@@ -23,9 +23,13 @@ public function getFulfilledOrder()
$this
->
model
->
where
(
'is_fulfilled'
,
true
);
$this
->
model
->
where
(
'is_fulfilled'
,
true
);
}
}
public
function
getListOrderOfAdmin
(
$statu
s
)
public
function
getListOrderOfAdmin
(
array
$param
s
)
{
{
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
)
public
function
getListOrderOfUser
(
$id
)
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment