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
fd057283
Commit
fd057283
authored
Sep 20, 2022
by
20194288-huannh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update code OrderController after review
parent
2057d743
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
52 deletions
+72
-52
OrderController.php
app/Http/Controllers/Api/OrderController.php
+19
-19
OrderController.php
app/Http/Controllers/OrderController.php
+21
-20
OrderDetailController.php
app/Http/Controllers/OrderDetailController.php
+0
-10
GetOrderRequest.php
app/Http/Requests/GetOrderRequest.php
+30
-0
OrderRepository.php
app/Repositories/OrderRepository.php
+2
-3
No files found.
app/Http/Controllers/Api/OrderController.php
View file @
fd057283
...
...
@@ -2,35 +2,38 @@
namespace
App\Http\Controllers\Api
;
use
Illuminate\Http\Request
;
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
;
class
OrderController
extends
Controller
{
private
OrderRepository
$orderRepository
;
private
UserRepository
$userRepository
;
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public
function
__construct
(
OrderRepository
$orderRepository
,
UserRepository
$userRepository
)
public
function
__construct
(
OrderRepository
$orderRepository
)
{
$this
->
orderRepository
=
$orderRepository
;
$this
->
userRepository
=
$userRepository
;
}
public
function
index
(
Request
$request
)
public
function
index
(
GetOrder
Request
$request
)
{
$id
=
$request
->
id
;
$user
=
auth
(
'api'
)
->
user
()
->
id
;
if
(
$user
->
role
==
User
::
ROLE_ADMIN
)
{
$order
=
$this
->
orderRepository
->
getListOrderOfAdmin
(
$request
);
}
elseif
(
$user
->
role
==
User
::
ROLE_EDITOR
)
{
$order
=
$this
->
orderRepository
->
getListOrderOfUser
(
$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
([]);
}
return
response
()
->
json
([
'success'
=>
true
,
...
...
@@ -102,14 +105,13 @@ public function edit(Request $request)
*/
public
function
update
(
Request
$request
,
$id
)
{
$
order
=
$this
->
orderRepository
->
update
(
$
is_update
=
$this
->
orderRepository
->
update
(
$request
->
id
,
$request
->
only
([
'id'
,
'details'
,
'client'
,
'is_fulfilled'
])
);
return
response
()
->
json
([
'success'
=>
true
,
'message'
=>
''
,
'data'
=>
$order
'success'
=>
$is_update
?
true
:
false
,
'message'
=>
''
]);
}
...
...
@@ -121,12 +123,10 @@ public function update(Request $request, $id)
*/
public
function
destroy
(
Request
$request
)
{
$
order
=
$this
->
orderRepository
->
deleteById
(
$request
->
id
);
$
is_deleted
=
$this
->
orderRepository
->
deleteById
(
$request
->
id
);
return
response
()
->
json
([
'success'
=>
true
,
'message'
=>
''
,
'data'
=>
$order
'success'
=>
$is_deleted
?
true
:
false
,
'message'
=>
''
]);
}
}
app/Http/Controllers/OrderController.php
View file @
fd057283
<?php
namespace
App\Http\Controllers
;
namespace
App\Http\Controllers
\Api
;
use
Illuminate\Http\Request
;
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
;
class
OrderController
extends
Controller
{
private
OrderRepository
$orderRepository
;
private
UserRepository
$userRepository
;
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public
function
__construct
(
OrderRepository
$orderRepository
,
UserRepository
$userRepository
)
public
function
__construct
(
OrderRepository
$orderRepository
)
{
$this
->
orderRepository
=
$orderRepository
;
$this
->
userRepository
=
$userRepository
;
}
public
function
index
(
Request
$request
)
public
function
index
(
GetOrder
Request
$request
)
{
$id
=
$request
->
id
;
$user
=
$this
->
userRepository
->
getByid
(
$id
);
if
(
$user
->
role
==
User
::
ROLE_ADMIN
)
{
$order
=
$this
->
orderRepository
->
paginate
(
$request
->
page
);
}
elseif
(
$user
->
role
==
User
::
ROLE_EDITOR
)
{
$order
=
$this
->
orderRepository
->
getListOrderOfUser
(
$id
);
$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
([]);
}
return
response
()
->
json
([
'success'
=>
true
,
...
...
@@ -102,14 +105,13 @@ public function edit(Request $request)
*/
public
function
update
(
Request
$request
,
$id
)
{
$
order
=
$this
->
orderRepository
->
update
(
$
is_update
=
$this
->
orderRepository
->
update
(
$request
->
id
,
$request
->
only
([
'id'
,
'details'
,
'client'
,
'is_fulfilled'
])
);
return
response
()
->
json
([
'success'
=>
true
,
'message'
=>
''
,
'data'
=>
$order
'success'
=>
$is_update
?
true
:
false
,
'message'
=>
''
]);
}
...
...
@@ -121,11 +123,10 @@ public function update(Request $request, $id)
*/
public
function
destroy
(
Request
$request
)
{
$
order
=
$this
->
orderRepository
->
deleteById
(
$request
->
id
);
$
is_deleted
=
$this
->
orderRepository
->
deleteById
(
$request
->
id
);
return
response
()
->
json
([
'success'
=>
true
,
'message'
=>
''
,
'data'
=>
$order
'success'
=>
$is_deleted
?
true
:
false
,
'message'
=>
''
]);
}
}
app/Http/Controllers/OrderDetailController.php
deleted
100644 → 0
View file @
2057d743
<?php
namespace
App\Http\Controllers
;
use
Illuminate\Http\Request
;
class
OrderDetailController
extends
Controller
{
//
}
app/Http/Requests/GetOrderRequest.php
0 → 100644
View file @
fd057283
<?php
namespace
App\Http\Requests
;
use
Illuminate\Foundation\Http\FormRequest
;
class
GetOrderRequest
extends
FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public
function
authorize
()
{
return
true
;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public
function
rules
()
{
return
[
'status'
=>
'required|integer'
];
}
}
app/Repositories/OrderRepository.php
View file @
fd057283
...
...
@@ -4,7 +4,6 @@
use
App\Models\Order
;
use
App\Repositories\BaseRepository
;
use
Illuminate\Http\Request
;
class
OrderRepository
extends
BaseRepository
{
...
...
@@ -24,9 +23,9 @@ public function getFulfilledOrder()
$this
->
model
->
where
(
'is_fulfilled'
,
true
);
}
public
function
getListOrderOfAdmin
(
Request
$request
)
public
function
getListOrderOfAdmin
(
$status
)
{
return
$this
->
model
->
latest
()
->
where
(
'status'
,
$
request
->
status
)
->
paginate
();
return
$this
->
model
->
latest
()
->
where
(
'status'
,
$status
)
->
paginate
();
}
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