Commit 7d4b30ac by Phạm Văn Đoan

cập nhật thông tin nhạc sĩ cho Api/NctController.php

parent 14ae1b46
......@@ -2,6 +2,7 @@
namespace App\Http\Controllers\Api;
use App\Models\Track;
use App\Repositories\TrackRepository;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
......@@ -18,6 +19,7 @@ class NctController extends Controller
/**
* API: http://localhost:8000/api/get-nct-top100
* Deploy: https://vmusicchart.vn/crawler/api/get-nct-top100
*
* @return \Illuminate\Http\JsonResponse
*/
......@@ -28,6 +30,14 @@ class NctController extends Controller
$tracks = $this->trackRepository->processNctGetTrackInfoFromTop100($url);
$tracks_playlist = $this->trackRepository->processNctGetTrackInfoFromTop100Playlist($url_playlist_top100);
$tracks_nct = Track::select(['id', 'id_nct', 'composer_list'])
->whereNotNull('id_nct')
->where('id_nct', '<>', '')
->get();
$array_tracks_nct = [];
foreach ($tracks_nct as $track) {
$array_tracks_nct[$track['id_nct']] = $track['composer_list'];
}
$response = null;
foreach ($tracks as $key => $track) {
......@@ -42,6 +52,11 @@ class NctController extends Controller
$response[$key]['link'] = $link;
$response[$key]['duration'] = $duration;
$response[$key]['str_duration'] = gmdate('i:s', $duration);
if (array_key_exists($track['id_nct'], $array_tracks_nct)) {
$response[$key]['composer'] = $array_tracks_nct[$track['id_nct']];
} else {
$response[$key]['composer'] = '?';
}
}
return response()->json([
......
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