Skip to content

Commit

Permalink
refactor rating views
Browse files Browse the repository at this point in the history
  • Loading branch information
fey committed Mar 27, 2024
1 parent 2052a0f commit d623b2d
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 49 deletions.
7 changes: 0 additions & 7 deletions app/Helpers/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,3 @@ function getExerciseOriginLink(Exercise $exercise): ?string
return ExerciseHelper::getExerciseOriginLink($exercise);
}
}

if (!function_exists('getCalculatedRating')) {
function getCalculatedRating(): Collection
{
return RatingHelper::getCalculatedRating();
}
}
2 changes: 0 additions & 2 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use App\Models\Exercise;
use App\Models\ChapterMember;
use App\Models\User;
use App\Services\PointsCalculator;
use Illuminate\Support\Carbon;
use Illuminate\View\View;
use Request;
Expand Down Expand Up @@ -67,7 +66,6 @@ private function getStatisticTable(string $filter): array
return [
'countChapterMember' => $countChapterMember,
'countCompletedExercise' => $countCompletedExercise,
'countPoints' => PointsCalculator::calculate($countChapterMember, $countCompletedExercise),
'filterForQuery' => $filter,
];
}
Expand Down
17 changes: 17 additions & 0 deletions app/Http/Controllers/Rating/TopController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Http\Controllers\Rating;

use App\Http\Controllers\Controller;
use App\Services\RatingCalculator;
use Illuminate\View\View;

class TopController extends Controller
{
public function index(RatingCalculator $ratingCalculator): View
{
$rating = $ratingCalculator->calculate();

return view('rating.top', compact('rating'));
}
}
16 changes: 0 additions & 16 deletions app/Http/Controllers/Rating/UserController.php

This file was deleted.

5 changes: 3 additions & 2 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

use App\Helpers\ChartHelper;
use App\Models\User;
use App\Services\RatingCalculator;
use Illuminate\View\View;

class UserController extends Controller
{
public function show(User $user): View
public function show(User $user, RatingCalculator $ratingCalculator): View
{
$rating = getCalculatedRating();
$rating = $ratingCalculator->calculate();
$userInRating = $rating->get($user->id);
if ($userInRating) {
$points = $userInRating->points;
Expand Down
11 changes: 0 additions & 11 deletions app/Services/PointsCalculator.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace App\Helpers;
namespace App\Services;

use App\Models\User;
use Illuminate\Support\Collection;

class RatingHelper
class RatingCalculator
{
public static function getCalculatedRating(): Collection
public static function calculate(): Collection
{
$ratings = User::select('users.*')
->selectRaw('DENSE_RANK() OVER (ORDER BY points desc, created_at) AS position')
Expand Down
4 changes: 0 additions & 4 deletions resources/views/home/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
</ul>
<div class="container m-0 p-0 mt-2">
<div class="row m-0 p-0 text-center">
<div class="col mt-4">
<p>{{ __('welcome.statistic.table.count_points') }}:</p>
<h3>{{ $statisticTable['countPoints'] }}</h3>
</div>
<div class="col mt-4">
<p>{{ __('welcome.statistic.table.count_read_chapter') }}:</p>
<h3>{{ $statisticTable['countChapterMember'] }}</h3>
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion resources/views/rating/comments.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@endsection
@section('content')
<div class="my-4">
@include('rating.menu')
@include('rating._menu')

<h1 class="h3">{{ __('rating.comments.title') }}</h1>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@endsection
@section('content')
<div class="my-4">
@include('rating.menu')
@include('rating._menu')

<section>
<h1 class="h3">{{ __('rating.index.title') }}</h1>
Expand Down
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
});

Route::namespace('Rating')->prefix('ratings')->group(function (): void {
Route::resource('top', 'UserController')->only('index');
Route::resource('top', 'TopController')->only('index');
Route::resource('comments_top', 'CommentController')->only('index');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Tests\TestCase;
use Illuminate\Support\Collection;

class UserControllerTest extends TestCase
class TopControllerTest extends TestCase
{
public function testIndex(): void
{
Expand Down

0 comments on commit d623b2d

Please sign in to comment.