Skip to content

Commit

Permalink
Merge pull request #58 from grozwalker/user-rating
Browse files Browse the repository at this point in the history
feat(rating): add rating
  • Loading branch information
mokevnin committed Sep 24, 2019
2 parents ebe67dd + 474eb2f commit fcfeff6
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 1 deletion.
19 changes: 19 additions & 0 deletions app/Http/Controllers/RatingController.php
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,
]);
}
}
5 changes: 5 additions & 0 deletions resources/lang/en/layout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'rating_page' => 'Rating',
];
8 changes: 8 additions & 0 deletions resources/lang/en/rating.php
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'
];
5 changes: 5 additions & 0 deletions resources/lang/ru/layout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'rating_page' => 'Рейтинг',
];
8 changes: 8 additions & 0 deletions resources/lang/ru/rating.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [
'page_title' => 'Рейтинг пользователей',
'positions' => 'Позиция',
'user' => 'Пользователь',
'number_of_points' => 'Количество очков'
];
7 changes: 6 additions & 1 deletion resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<!-- Left Side Of Navbar -->
<ul class="navbar-nav mr-auto">
<a href="https://github.com/Hexlet/hexlet-sicp">Source Code</a>
<li class="nav-item">
<a class="nav-link" href="https://github.com/Hexlet/hexlet-sicp">{{ __('layout.rating_page') }}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/Hexlet/hexlet-sicp">Source Code</a>
</li>
</ul>

<!-- Right Side Of Navbar -->
Expand Down
30 changes: 30 additions & 0 deletions resources/views/rating/index.blade.php
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
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ static function () {
Route::resource('users.chapters', 'UserChapterController')->only('store');
});

Route::resource('ratings', 'RatingController')->only('index');

Route::get('/home', 'HomeController@index')->name('home');
24 changes: 24 additions & 0 deletions tests/Feature/Http/Controllers/RatingControllerTest.php
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);
}
}

0 comments on commit fcfeff6

Please sign in to comment.