Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
crawler.vmusicchart.vn
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
Phạm Văn Đoan
crawler.vmusicchart.vn
Commits
9f7d8336
Commit
9f7d8336
authored
May 20, 2020
by
Phạm Văn Đoan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tạo api lấy lịch sử lượt nghe theo từng ngày
parent
671f3ebb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
138 additions
and
0 deletions
+138
-0
Functions.php
app/Helpers/Functions.php
+10
-0
ListenHistoryController.php
app/Http/Controllers/Api/ListenHistoryController.php
+96
-0
ListenRepository.php
app/Repositories/ListenRepository.php
+31
-0
api.php
routes/api.php
+1
-0
No files found.
app/Helpers/Functions.php
View file @
9f7d8336
...
...
@@ -399,3 +399,13 @@ if (!function_exists('getWeekDateRange')) {
return
$ret
;
}
}
if
(
!
function_exists
(
'dataResponse'
))
{
function
dataResponse
(
$code
,
$message
,
$data
)
{
return
[
'code'
=>
$code
,
'message'
=>
$message
,
'data'
=>
$data
];
}
}
app/Http/Controllers/Api/ListenHistoryController.php
0 → 100644
View file @
9f7d8336
<?php
namespace
App\Http\Controllers\Api
;
use
App\Repositories\ListenRepository
;
use
Illuminate\Http\Request
;
use
App\Http\Controllers\Controller
;
use
Illuminate\Support\Facades\Validator
;
class
ListenHistoryController
extends
Controller
{
protected
$listenRepository
;
public
function
__construct
(
ListenRepository
$listenRepository
)
{
$this
->
listenRepository
=
$listenRepository
;
}
public
function
getListenHistoryByDateBk
(
Request
$request
)
{
$rules
=
[
'date'
=>
[
'required'
,
function
(
$attibute
,
$value
,
$fail
){
die
(
$value
);
$array_date
=
explode
(
'-'
,
$value
);
if
(
is_array
(
$array_date
)
&&
count
(
$array_date
)
==
3
)
{
if
(
!
checkdate
(
trim
(
$array_date
[
1
]),
trim
(
$array_date
[
2
]),
trim
(
$array_date
[
0
])))
{
return
$fail
(
'Ngày không hợp lệ.'
);
}
}
else
{
return
$fail
(
'Ngày phải có định dạng yyyy-mm-dd.'
);
}
}
]
];
$messages
=
[
'date.required'
=>
'Truyền thiếu tham số date (yyyy-mm-dd)'
];
$validator
=
Validator
::
make
(
$request
->
all
(),
$rules
,
$messages
);
if
(
$validator
->
fails
()
){
return
[
'code'
=>
400
,
'message'
=>
$validator
->
errors
()
->
first
(),
'data'
=>
null
];
}
$date
=
request
(
'date'
);
return
response
()
->
json
(
dataResponse
(
200
,
'Lấy thông tin thành công'
,
$this
->
listenRepository
->
getListenHistoryByDate
(
$date
)
));
}
/**
* API lấy lịch sử lượt nghe theo từng ngày
* http://localhost:8000/api/get-listen-history-by-date?date=2020-03-30
* http://crawler.vmusicchart.vn/api/get-listen-history-by-date?date=2020-03-30
*
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
public
function
getListenHistoryByDate
(
Request
$request
)
{
$date
=
request
(
'date'
);
$array_date
=
explode
(
'-'
,
$date
);
if
(
is_array
(
$array_date
)
&&
count
(
$array_date
)
==
3
)
{
if
(
!
checkdate
(
trim
(
$array_date
[
1
]),
trim
(
$array_date
[
2
]),
trim
(
$array_date
[
0
])))
{
return
response
()
->
json
(
dataResponse
(
200
,
'Lấy thông tin thành công'
,
null
));
}
}
else
{
return
response
()
->
json
(
dataResponse
(
200
,
'Lấy thông tin thành công'
,
null
));
}
return
response
()
->
json
(
dataResponse
(
200
,
'Lấy thông tin thành công'
,
$this
->
listenRepository
->
getListenHistoryByDate
(
$date
)
));
}
}
app/Repositories/ListenRepository.php
0 → 100644
View file @
9f7d8336
<?php
namespace
App\Repositories
;
use
App\Models\CrawlerListenHistory
;
class
ListenRepository
extends
BaseRepository
{
public
function
__construct
()
{
}
/**
* Lấy toàn bộ log lượt nghe theo ngày để đồng bộ sang elastic
*
* @param $date
* @return array
*/
public
function
getListenHistoryByDate
(
$date
)
{
if
(
empty
(
$date
))
{
return
[];
}
$query
=
CrawlerListenHistory
::
where
(
'date_log'
,
$date
)
->
get
();
return
$query
->
toArray
();
}
}
\ No newline at end of file
routes/api.php
View file @
9f7d8336
...
...
@@ -19,3 +19,4 @@ Route::middleware('auth:api')->get('/user', function (Request $request) {
Route
::
get
(
'/get-nct-top100'
,
'Api\NctController@getNctTop100'
);
Route
::
get
(
'/get-zing-top100'
,
'Api\NctController@getZingTop100'
);
Route
::
get
(
'/get-listen-history-by-date'
,
'Api\ListenHistoryController@getListenHistoryByDate'
);
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