Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rating): add rating #58

Merged
merged 2 commits into from Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions app/Http/Controllers/RatingController.php
@@ -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
@@ -0,0 +1,5 @@
<?php

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

return [
'rating_page' => 'Рейтинг',
];
8 changes: 8 additions & 0 deletions resources/lang/ru/rating.php
@@ -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
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
@@ -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
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
@@ -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);
}
}