-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from grozwalker/user-rating
feat(rating): add rating
- Loading branch information
Showing
9 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\User; | ||
|
||
class RatingController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
$users = User::withCount('readChapters') | ||
->orderBy('read_chapters_count', 'DESC') | ||
->get(); | ||
|
||
return view('rating.index', [ | ||
'users' => $users, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
return [ | ||
'rating_page' => 'Rating', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
return [ | ||
'page_title' => 'Users rating', | ||
'positions' => 'Positions', | ||
'user' => 'User', | ||
'number_of_points' => 'Number of points' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
return [ | ||
'rating_page' => 'Рейтинг', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
return [ | ||
'page_title' => 'Рейтинг пользователей', | ||
'positions' => 'Позиция', | ||
'user' => 'Пользователь', | ||
'number_of_points' => 'Количество очков' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
@extends('layouts.app') | ||
|
||
@section('content') | ||
<div class="row my-4"> | ||
<div class="col-12 my-4"> | ||
<h3>{{ __('rating.page_title') }}</h3> | ||
|
||
<div class="table-responsive"> | ||
<table class="table table-striped"> | ||
<thead> | ||
<tr> | ||
<th>{{ __('rating.positions') }}</th> | ||
<th>{{ __('rating.user') }}</th> | ||
<th>{{ __('rating.number_of_points') }}</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach($users as $user) | ||
<tr> | ||
<td>{{ $loop->index + 1 }}</td> | ||
<td>{{ $user->name }}</td> | ||
<td>{{ $user->read_chapters_count }}</td> | ||
</tr> | ||
@endforeach | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Http\Controllers; | ||
|
||
use App\ReadChapter; | ||
use App\User; | ||
use Tests\TestCase; | ||
|
||
class RatingControllerTest extends TestCase | ||
{ | ||
public function testIndex() | ||
{ | ||
factory(User::class, 10) | ||
->create() | ||
->each(function ($user) { | ||
factory(ReadChapter::class, mt_rand(0, 10))->create([ | ||
'user_id' => $user->id, | ||
]); | ||
}); | ||
|
||
$this->get(route('ratings.index')) | ||
->assertStatus(200); | ||
} | ||
} |