Skip to content

Commit

Permalink
add: bangumi likers
Browse files Browse the repository at this point in the history
  • Loading branch information
falstack committed Jan 6, 2020
1 parent 175beef commit 76cc37e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
20 changes: 20 additions & 0 deletions app/Http/Controllers/v1/BangumiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Http\Modules\Counter\BangumiPatchCounter;
use App\Http\Repositories\BangumiRepository;
use App\Http\Repositories\IdolRepository;
use App\Http\Repositories\UserRepository;
use App\Models\Bangumi;
use App\Models\BangumiQuestion;
use App\Models\Search;
Expand Down Expand Up @@ -109,6 +110,25 @@ public function score(Request $request)

}

public function liker(Request $request)
{
$slug = $request->get('slug');
$page = $request->get('page') ?: 1;
$take = $request->get('take') ?: 10;

$bangumiRepository = new BangumiRepository();
$idsObj = $bangumiRepository->likeUsers($slug, $page - 1, $take);
if (!$idsObj['total'])
{
return $this->resOK($idsObj);
}

$userRepository = new UserRepository();
$idsObj['result'] = $userRepository->list($idsObj['result']);

return $this->resOK($idsObj);
}

public function relation(Request $request)
{
$slug = $request->get('slug');
Expand Down
7 changes: 5 additions & 2 deletions app/Http/Repositories/BangumiRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ public function likeUsers($slug, $page, $take, $refresh = false)

return $bangumi
->fans(User::class)
->pluck('slug')
->withPivot('created_at')
->orderBy('created_at', 'DESC')
->pluck('followables.created_at', 'slug')
->toArray();
}, ['force' => $refresh]);

}, ['force' => $refresh, 'is_time' => true]);

return $this->filterIdsByPage($list, $page, $take);
}
Expand Down
2 changes: 2 additions & 0 deletions routes/route-v1.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@

$route->get('idols', 'BangumiController@idols');

$route->get('liker', 'BangumiController@liker');

$route->get('relation', 'BangumiController@relation');

$route->group(['middleware' => 'user'], function () use ($route)
Expand Down

0 comments on commit 76cc37e

Please sign in to comment.