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
b1876562
Commit
b1876562
authored
Sep 22, 2022
by
TTS Nguyen Huu Huan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/order' into 'dev'
update code OrderController after review See merge request
!11
parents
a8aea4ce
5f2ed7da
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
77 additions
and
52 deletions
+77
-52
OrderController.php
app/Http/Controllers/Api/OrderController.php
+13
-18
OrderController.php
app/Http/Controllers/OrderController.php
+12
-17
OrderDetailController.php
app/Http/Controllers/OrderDetailController.php
+0
-10
GetOrderRequest.php
app/Http/Requests/GetOrderRequest.php
+31
-0
OrderRepository.php
app/Repositories/OrderRepository.php
+21
-7
No files found.
app/Http/Controllers/Api/OrderController.php
View file @
b1876562
...
@@ -2,36 +2,32 @@
...
@@ -2,36 +2,32 @@
namespace
App\Http\Controllers\Api
;
namespace
App\Http\Controllers\Api
;
use
Illuminate\Http\Request
;
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\Repositories\UserRepository
;
use
App\Http\Requests\GetOrderRequest
;
use
Illuminate\Http\Request
;
use
App\Models\User
;
use
App\Models\User
;
class
OrderController
extends
Controller
class
OrderController
extends
Controller
{
{
private
OrderRepository
$orderRepository
;
private
OrderRepository
$orderRepository
;
private
UserRepository
$userRepository
;
/**
/**
* Display a listing of the resource.
* Display a listing of the resource.
*
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\Response
*/
*/
public
function
__construct
(
OrderRepository
$orderRepository
,
UserRepository
$userRepository
)
public
function
__construct
(
OrderRepository
$orderRepository
)
{
{
$this
->
orderRepository
=
$orderRepository
;
$this
->
orderRepository
=
$orderRepository
;
$this
->
userRepository
=
$userRepository
;
}
}
public
function
index
(
Request
$request
)
public
function
index
(
GetOrder
Request
$request
)
{
{
$id
=
$request
->
id
;
$user
=
auth
()
->
user
();
$user
=
auth
(
'api'
)
->
user
()
->
id
;
$order
=
$user
->
role
==
User
::
ROLE_ADMIN
?
if
(
$user
->
role
==
User
::
ROLE_ADMIN
)
{
$this
->
orderRepository
->
getListOrder
(
$request
->
only
([
'keyword'
,
'status'
]))
$order
=
$this
->
orderRepository
->
getListOrderOfAdmin
(
$request
);
:
$this
->
orderRepository
->
getListOrder
(
$request
->
only
([
'keyword'
,
'status'
]),
$user
->
id
);
}
elseif
(
$user
->
role
==
User
::
ROLE_EDITOR
)
{
$order
=
$this
->
orderRepository
->
getListOrderOfUser
(
$id
);
}
return
response
()
->
json
([
return
response
()
->
json
([
'success'
=>
true
,
'success'
=>
true
,
'meta'
=>
[
'meta'
=>
[
...
@@ -100,16 +96,16 @@ public function edit(Request $request)
...
@@ -100,16 +96,16 @@ 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
)
{
{
$
order
=
$this
->
orderRepository
->
update
(
$
is_update
=
$this
->
orderRepository
->
update
(
$request
->
id
,
$request
->
id
,
$request
->
only
([
'id'
,
'details'
,
'client'
,
'is_fulfilled'
])
$request
->
only
([
'id'
,
'details'
,
'client'
,
'is_fulfilled'
])
);
);
return
response
()
->
json
([
return
response
()
->
json
([
'success'
=>
true
,
'success'
=>
true
,
'message'
=>
''
,
'message'
=>
''
,
'data'
=>
$
order
'data'
=>
$
is_update
]);
]);
}
}
...
@@ -121,12 +117,11 @@ public function update(Request $request, $id)
...
@@ -121,12 +117,11 @@ public function update(Request $request, $id)
*/
*/
public
function
destroy
(
Request
$request
)
public
function
destroy
(
Request
$request
)
{
{
$
order
=
$this
->
orderRepository
->
deleteById
(
$request
->
id
);
$
is_deleted
=
$this
->
orderRepository
->
deleteById
(
$request
->
id
);
return
response
()
->
json
([
return
response
()
->
json
([
'success'
=>
true
,
'success'
=>
true
,
'message'
=>
''
,
'message'
=>
''
,
'data'
=>
$
order
'data'
=>
$
is_deleted
]);
]);
}
}
}
}
app/Http/Controllers/OrderController.php
View file @
b1876562
...
@@ -2,36 +2,31 @@
...
@@ -2,36 +2,31 @@
namespace
App\Http\Controllers
;
namespace
App\Http\Controllers
;
use
Illuminate\Http\Request
;
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
Illuminate\Http\Request
;
use
App\Models\User
;
use
App\Models\User
;
class
OrderController
extends
Controller
class
OrderController
extends
Controller
{
{
private
OrderRepository
$orderRepository
;
private
OrderRepository
$orderRepository
;
private
UserRepository
$userRepository
;
/**
/**
* Display a listing of the resource.
* Display a listing of the resource.
*
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\Response
*/
*/
public
function
__construct
(
OrderRepository
$orderRepository
,
UserRepository
$userRepository
)
public
function
__construct
(
OrderRepository
$orderRepository
)
{
{
$this
->
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
();
$user
=
$this
->
userRepository
->
getByid
(
$id
);
$order
=
$user
->
role
==
User
::
ROLE_ADMIN
?
if
(
$user
->
role
==
User
::
ROLE_ADMIN
)
{
$this
->
orderRepository
->
getListOrder
(
$request
->
only
([
'status'
,
'keyword'
]))
$order
=
$this
->
orderRepository
->
paginate
(
$request
->
page
);
:
$this
->
orderRepository
->
getListOrder
(
$request
->
only
([
'status'
,
'keyword'
]),
$user
->
id
);
}
elseif
(
$user
->
role
==
User
::
ROLE_EDITOR
)
{
$order
=
$this
->
orderRepository
->
getListOrderOfUser
(
$id
);
}
return
response
()
->
json
([
return
response
()
->
json
([
'success'
=>
true
,
'success'
=>
true
,
'meta'
=>
[
'meta'
=>
[
...
@@ -102,14 +97,14 @@ public function edit(Request $request)
...
@@ -102,14 +97,14 @@ public function edit(Request $request)
*/
*/
public
function
update
(
Request
$request
,
$id
)
public
function
update
(
Request
$request
,
$id
)
{
{
$
order
=
$this
->
orderRepository
->
update
(
$
is_update
=
$this
->
orderRepository
->
update
(
$request
->
id
,
$request
->
id
,
$request
->
only
([
'id'
,
'details'
,
'client'
,
'is_fulfilled'
])
$request
->
only
([
'id'
,
'details'
,
'client'
,
'is_fulfilled'
])
);
);
return
response
()
->
json
([
return
response
()
->
json
([
'success'
=>
true
,
'success'
=>
true
,
'message'
=>
''
,
'message'
=>
''
,
'data'
=>
$
order
'data'
=>
$
is_update
]);
]);
}
}
...
@@ -121,11 +116,11 @@ public function update(Request $request, $id)
...
@@ -121,11 +116,11 @@ public function update(Request $request, $id)
*/
*/
public
function
destroy
(
Request
$request
)
public
function
destroy
(
Request
$request
)
{
{
$
order
=
$this
->
orderRepository
->
deleteById
(
$request
->
id
);
$
is_deleted
=
$this
->
orderRepository
->
deleteById
(
$request
->
id
);
return
response
()
->
json
([
return
response
()
->
json
([
'success'
=>
true
,
'success'
=>
true
,
'message'
=>
''
,
'message'
=>
''
,
'data'
=>
$
order
'data'
=>
$
is_deleted
]);
]);
}
}
}
}
app/Http/Controllers/OrderDetailController.php
deleted
100644 → 0
View file @
a8aea4ce
<?php
namespace
App\Http\Controllers
;
use
Illuminate\Http\Request
;
class
OrderDetailController
extends
Controller
{
//
}
app/Http/Requests/GetOrderRequest.php
0 → 100644
View file @
b1876562
<?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'
=>
'integer'
,
'keyword'
=>
'string|max:255'
];
}
}
app/Repositories/OrderRepository.php
View file @
b1876562
...
@@ -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
Illuminate\Http\Request
;
class
OrderRepository
extends
BaseRepository
class
OrderRepository
extends
BaseRepository
{
{
...
@@ -24,12 +23,27 @@ public function getFulfilledOrder()
...
@@ -24,12 +23,27 @@ public function getFulfilledOrder()
$this
->
model
->
where
(
'is_fulfilled'
,
true
);
$this
->
model
->
where
(
'is_fulfilled'
,
true
);
}
}
public
function
getListOrder
OfAdmin
(
Request
$request
)
public
function
getListOrder
(
array
$params
,
$id
=
0
)
{
{
return
$this
->
model
->
latest
()
->
where
(
'status'
,
$request
->
status
)
->
paginate
();
$query
=
$this
->
model
;
if
(
!
$id
){
$query
=
$query
->
where
(
'user_id'
,
$id
);
}
}
public
function
getListOrderOfUser
(
$id
)
if
(
isset
(
$params
[
'status'
]))
{
{
$query
=
$query
->
where
(
'status'
,
$params
[
'status'
]);
return
$this
->
model
->
where
(
'user_id'
,
$id
)
->
with
(
'user'
)
->
paginate
();
}
if
(
isset
(
$params
[
'keyword'
]))
{
$keyword
=
$params
[
'keyword'
];
$query
=
$query
->
where
(
function
(
$query
)
use
(
$keyword
)
{
$query
->
where
(
'details'
,
'LIKE'
,
'%'
.
$keyword
.
'%'
)
->
orWhere
(
'client'
,
'LIKE'
,
'%'
.
$keyword
.
'%'
)
->
orWhere
(
function
(
$query
)
use
(
$keyword
)
{
$query
->
whereHas
(
'user'
,
function
(
$query
)
use
(
$keyword
)
{
$query
->
where
(
'name'
,
'LIKE'
,
'%'
.
$keyword
.
'%'
);
});
});
});
}
return
$query
->
paginate
();
}
}
}
}
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