From d623b2db831a0f613b2d4416b73b006186cbb102 Mon Sep 17 00:00:00 2001 From: Nikolay Gagarinov Date: Thu, 28 Mar 2024 00:45:38 +0500 Subject: [PATCH] refactor rating views --- app/Helpers/helpers.php | 7 ------- app/Http/Controllers/HomeController.php | 2 -- app/Http/Controllers/Rating/TopController.php | 17 +++++++++++++++++ app/Http/Controllers/Rating/UserController.php | 16 ---------------- app/Http/Controllers/UserController.php | 5 +++-- app/Services/PointsCalculator.php | 11 ----------- .../RatingCalculator.php} | 6 +++--- resources/views/home/index.blade.php | 4 ---- .../rating/{menu.blade.php => _menu.blade.php} | 0 resources/views/rating/comments.blade.php | 2 +- .../rating/{index.blade.php => top.blade.php} | 2 +- routes/web.php | 2 +- ...ControllerTest.php => TopControllerTest.php} | 2 +- 13 files changed, 27 insertions(+), 49 deletions(-) create mode 100644 app/Http/Controllers/Rating/TopController.php delete mode 100644 app/Http/Controllers/Rating/UserController.php delete mode 100644 app/Services/PointsCalculator.php rename app/{Helpers/RatingHelper.php => Services/RatingCalculator.php} (77%) rename resources/views/rating/{menu.blade.php => _menu.blade.php} (100%) rename resources/views/rating/{index.blade.php => top.blade.php} (97%) rename tests/Feature/Http/Controllers/Rating/{UserControllerTest.php => TopControllerTest.php} (95%) diff --git a/app/Helpers/helpers.php b/app/Helpers/helpers.php index 142c8f6bc..406925123 100644 --- a/app/Helpers/helpers.php +++ b/app/Helpers/helpers.php @@ -50,10 +50,3 @@ function getExerciseOriginLink(Exercise $exercise): ?string return ExerciseHelper::getExerciseOriginLink($exercise); } } - -if (!function_exists('getCalculatedRating')) { - function getCalculatedRating(): Collection - { - return RatingHelper::getCalculatedRating(); - } -} diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 8028c3ebb..4092f1cdb 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -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; @@ -67,7 +66,6 @@ private function getStatisticTable(string $filter): array return [ 'countChapterMember' => $countChapterMember, 'countCompletedExercise' => $countCompletedExercise, - 'countPoints' => PointsCalculator::calculate($countChapterMember, $countCompletedExercise), 'filterForQuery' => $filter, ]; } diff --git a/app/Http/Controllers/Rating/TopController.php b/app/Http/Controllers/Rating/TopController.php new file mode 100644 index 000000000..31e914632 --- /dev/null +++ b/app/Http/Controllers/Rating/TopController.php @@ -0,0 +1,17 @@ +calculate(); + + return view('rating.top', compact('rating')); + } +} diff --git a/app/Http/Controllers/Rating/UserController.php b/app/Http/Controllers/Rating/UserController.php deleted file mode 100644 index a65d6a09c..000000000 --- a/app/Http/Controllers/Rating/UserController.php +++ /dev/null @@ -1,16 +0,0 @@ -calculate(); $userInRating = $rating->get($user->id); if ($userInRating) { $points = $userInRating->points; diff --git a/app/Services/PointsCalculator.php b/app/Services/PointsCalculator.php deleted file mode 100644 index f1f375635..000000000 --- a/app/Services/PointsCalculator.php +++ /dev/null @@ -1,11 +0,0 @@ -selectRaw('DENSE_RANK() OVER (ORDER BY points desc, created_at) AS position') diff --git a/resources/views/home/index.blade.php b/resources/views/home/index.blade.php index 59ca31f12..d2362d1e2 100644 --- a/resources/views/home/index.blade.php +++ b/resources/views/home/index.blade.php @@ -47,10 +47,6 @@
-
-

{{ __('welcome.statistic.table.count_points') }}:

-

{{ $statisticTable['countPoints'] }}

-

{{ __('welcome.statistic.table.count_read_chapter') }}:

{{ $statisticTable['countChapterMember'] }}

diff --git a/resources/views/rating/menu.blade.php b/resources/views/rating/_menu.blade.php similarity index 100% rename from resources/views/rating/menu.blade.php rename to resources/views/rating/_menu.blade.php diff --git a/resources/views/rating/comments.blade.php b/resources/views/rating/comments.blade.php index dba6150b1..44b0316e4 100644 --- a/resources/views/rating/comments.blade.php +++ b/resources/views/rating/comments.blade.php @@ -4,7 +4,7 @@ @endsection @section('content')
- @include('rating.menu') + @include('rating._menu')

{{ __('rating.comments.title') }}

diff --git a/resources/views/rating/index.blade.php b/resources/views/rating/top.blade.php similarity index 97% rename from resources/views/rating/index.blade.php rename to resources/views/rating/top.blade.php index ca916e9e0..f99e91b7d 100644 --- a/resources/views/rating/index.blade.php +++ b/resources/views/rating/top.blade.php @@ -7,7 +7,7 @@ @endsection @section('content')
- @include('rating.menu') + @include('rating._menu')

{{ __('rating.index.title') }}

diff --git a/routes/web.php b/routes/web.php index e7e1ff513..b920bc4f6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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'); }); diff --git a/tests/Feature/Http/Controllers/Rating/UserControllerTest.php b/tests/Feature/Http/Controllers/Rating/TopControllerTest.php similarity index 95% rename from tests/Feature/Http/Controllers/Rating/UserControllerTest.php rename to tests/Feature/Http/Controllers/Rating/TopControllerTest.php index ad86384aa..aa7d994ea 100644 --- a/tests/Feature/Http/Controllers/Rating/UserControllerTest.php +++ b/tests/Feature/Http/Controllers/Rating/TopControllerTest.php @@ -8,7 +8,7 @@ use Tests\TestCase; use Illuminate\Support\Collection; -class UserControllerTest extends TestCase +class TopControllerTest extends TestCase { public function testIndex(): void {