Skip to content

Commit

Permalink
add: user like bangumi list
Browse files Browse the repository at this point in the history
  • Loading branch information
falstack committed Jan 7, 2020
1 parent 76cc37e commit b7721d6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/v1/BangumiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function liker(Request $request)

$bangumiRepository = new BangumiRepository();
$idsObj = $bangumiRepository->likeUsers($slug, $page - 1, $take);
if (!$idsObj['total'])
if (empty($idsObj['result']))
{
return $this->resOK($idsObj);
}
Expand Down
23 changes: 22 additions & 1 deletion app/Http/Controllers/v1/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Http\Modules\DailyRecord\UserActivity;
use App\Http\Modules\DailyRecord\UserDailySign;
use App\Http\Modules\DailyRecord\UserExposure;
use App\Http\Repositories\BangumiRepository;
use App\Http\Repositories\IdolRepository;
use App\Http\Repositories\PinRepository;
use App\Http\Repositories\TagRepository;
Expand Down Expand Up @@ -100,6 +101,26 @@ public function batchPatch(Request $request)
return $this->resOK($result);
}

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

$userRepository = new UserRepository();

$idsObj = $userRepository->likeBangumi($slug, $page - 1, $take);
if (empty($idsObj['result']))
{
return $this->resOK($idsObj);
}

$bangumiRepository = new BangumiRepository();
$idsObj['result'] = $bangumiRepository->list($idsObj['result']);

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

public function timeline(Request $request)
{
$validator = Validator::make($request->all(), [
Expand Down Expand Up @@ -272,7 +293,7 @@ public function dailySign(Request $request)
/**
* 用户关系
*/
public function getUserRelation(Request $request)
public function getUserRelations(Request $request)
{
$slug = $request->get('slug');
$take = $request->get('count') ?: 15;
Expand Down
11 changes: 7 additions & 4 deletions app/Http/Repositories/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,14 @@ public function likeBangumi($slug, $page, $take, $refresh = false)
return [];
}

$user
->likers(Bangumi::class)
->pluck('slug')
return $user
->likes(Bangumi::class)
->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
4 changes: 3 additions & 1 deletion routes/route-v1.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@
{
$route->get('show', 'UserController@show');

$route->get('relation', 'UserController@getUserRelation');
$route->get('relation', 'UserController@getUserRelations');

$route->get('timeline', 'UserController@timeline');

$route->get('managers', 'UserController@managers');

$route->get('like_bangumi', 'UserController@likeBangumi');

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

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

0 comments on commit b7721d6

Please sign in to comment.