refactor: cruddify user torrent history

This commit is contained in:
Roardom
2022-12-25 01:35:40 -06:00
parent d4adb901d1
commit dd633d585f
7 changed files with 65 additions and 16 deletions
@@ -0,0 +1,46 @@
<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author Roardom <roardom@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class HistoryController extends Controller
{
/**
* Show user torrent history.
*/
public function index(Request $request, string $username): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$user = User::where('username', '=', $username)->sole();
\abort_unless($request->user()->group->is_modo || $request->user()->id == $user->id, 403);
$history = DB::table('history')
->where('user_id', '=', $user->id)
->where('created_at', '>', $user->created_at)
->selectRaw('sum(actual_uploaded) as upload')
->selectRaw('sum(uploaded) as credited_upload')
->selectRaw('sum(actual_downloaded) as download')
->selectRaw('sum(downloaded) as credited_download')
->first();
return \view('user.history.index', [
'user' => $user,
'history' => $history,
]);
}
}
+4 -4
View File
@@ -237,7 +237,7 @@
</a>
</li>
<li class="ratio-bar__downloaded" title="{{ __('common.download') }}">
<a href="{{ route('user_torrents', ['username' => auth()->user()->username, 'downloaded' => 'include']) }}">
<a href="{{ route('users.history.index', ['username' => auth()->user()->username, 'downloaded' => 'include']) }}">
<i class="{{ config('other.font-awesome') }} fa-arrow-down"></i>
{{ auth()->user()->getDownloaded() }}
</a>
@@ -249,13 +249,13 @@
</a>
</li>
<li class="ratio-bar__leeching" title="{{ __('torrent.leeching') }}">
<a href="{{ route('user_torrents', ['username' => auth()->user()->username, 'unsatisfied' => 'include']) }}">
<a href="{{ route('users.history.index', ['username' => auth()->user()->username, 'unsatisfied' => 'include']) }}">
<i class="{{ config('other.font-awesome') }} fa-download"></i>
{{ auth()->user()->leechingTorrents()->count() }}
</a>
</li>
<li class="ratio-bar__buffer" title="{{ __('common.buffer') }}">
<a href="{{ route('user_torrents', ['username' => auth()->user()->username]) }}">
<a href="{{ route('users.history.index', ['username' => auth()->user()->username]) }}">
<i class="{{ config('other.font-awesome') }} fa-exchange"></i>
{{ auth()->user()->untilRatio(config('other.ratio')) }}
</a>
@@ -267,7 +267,7 @@
</a>
</li>
<li class="ratio-bar__ratio" title="{{ __('common.ratio') }}">
<a href="{{ route('user_torrents', ['username' => auth()->user()->username]) }}">
<a href="{{ route('users.history.index', ['username' => auth()->user()->username]) }}">
<i class="{{ config('other.font-awesome') }} fa-sync-alt"></i>
{{ auth()->user()->getRatioString() }}
</a>
+5 -5
View File
@@ -179,8 +179,8 @@
<li class="nav-tab-menu">
@if ($isProfileOwner || $isModo)
<a
class="{{ Route::is('user_torrents', 'users.torrents.index', 'users.peers.index', 'user_resurrections', 'user_requested') ? 'nav-tab--active__link' : 'nav-tab__link' }}"
href="{{ route('user_torrents', ['username' => $user->username]) }}"
class="{{ Route::is('users.history.index', 'users.torrents.index', 'users.peers.index', 'user_resurrections', 'user_requested') ? 'nav-tab--active__link' : 'nav-tab__link' }}"
href="{{ route('users.history.index', ['username' => $user->username]) }}"
>
{{ __('torrent.torrents') }}
</a>
@@ -191,10 +191,10 @@
@endif
<ul class="nav-tab-menu__items">
@if ($isProfileOwner || $isModo)
<li class="{{ Route::is('user_torrents') ? 'nav-tab--active' : 'nav-tavV2' }}">
<li class="{{ Route::is('users.history.index') ? 'nav-tab--active' : 'nav-tavV2' }}">
<a
class="{{ Route::is('user_torrents') ? 'nav-tab--active__link' : 'nav-tab__link' }}"
href="{{ route('user_torrents', ['username' => $user->username]) }}"
class="{{ Route::is('users.history.index') ? 'nav-tab--active__link' : 'nav-tab__link' }}"
href="{{ route('users.history.index', ['username' => $user->username]) }}"
>
{{ __('torrent.history') }}
</a>
+1 -1
View File
@@ -185,7 +185,7 @@
</dl>
<div class="panel__body">
<a
href="{{ route('user_torrents', ['username' => $user->username, 'completed' => 'include', 'active' => 'include']) }}"
href="{{ route('users.history.index', ['username' => $user->username, 'completed' => 'include', 'active' => 'include']) }}"
class="form__button form__button--filled"
>
{{ __('bon.review-seeds') }}
+4 -4
View File
@@ -28,14 +28,14 @@
</div>
<div class="button-right">
<span class="badge-user"><strong>{{ __('user.total-download') }}:</strong>
<span class="badge-extra text-red">{{ App\Helpers\StringHelper::formatBytes($his_downl, 2) }}</span>
<span class="badge-extra text-red">{{ App\Helpers\StringHelper::formatBytes($history->download, 2) }}</span>
<span class="badge-extra text-orange" data-toggle="tooltip"
data-original-title="{{ __('user.credited-download') }}">{{ App\Helpers\StringHelper::formatBytes($his_downl_cre, 2) }}</span>
data-original-title="{{ __('user.credited-download') }}">{{ App\Helpers\StringHelper::formatBytes($history->credited_download, 2) }}</span>
</span>
<span class="badge-user"><strong>{{ __('user.total-upload') }}:</strong>
<span class="badge-extra text-green">{{ App\Helpers\StringHelper::formatBytes($his_upl, 2) }}</span>
<span class="badge-extra text-green">{{ App\Helpers\StringHelper::formatBytes($history->upload, 2) }}</span>
<span class="badge-extra text-blue" data-toggle="tooltip"
data-original-title="{{ __('user.credited-upload') }}">{{ App\Helpers\StringHelper::formatBytes($his_upl_cre, 2) }}</span>
data-original-title="{{ __('user.credited-upload') }}">{{ App\Helpers\StringHelper::formatBytes($history->credited_upload, 2) }}</span>
</span>
</div>
</div>
+4 -1
View File
@@ -419,6 +419,10 @@ Route::group(['middleware' => 'language'], function () {
Route::get('/', [App\Http\Controllers\User\BanController::class, 'index'])->name('index');
});
Route::group(['prefix' => 'torrents', 'as' => 'history.'], function () {
Route::get('/', [App\Http\Controllers\User\HistoryController::class, 'index'])->name('index');
});
// Peers
Route::group(['prefix' => 'active', 'as' => 'peers.'], function () {
Route::get('/', [App\Http\Controllers\User\PeerController::class, 'index'])->name('index');
@@ -471,7 +475,6 @@ Route::group(['middleware' => 'language'], function () {
// History
Route::group(['prefix' => 'users'], function () {
Route::get('/{username}/torrents', [App\Http\Controllers\User\UserController::class, 'torrents'])->name('user_torrents');
Route::get('/{username}/downloadHistoryTorrents', [App\Http\Controllers\User\UserController::class, 'downloadHistoryTorrents'])->name('download_history_torrents');
});
@@ -555,7 +555,7 @@ class UserControllerTest extends TestCase
$user = User::factory()->create();
$user = User::factory()->create();
$response = $this->actingAs($user)->get(route('user_torrents', ['username' => $user->username]));
$response = $this->actingAs($user)->get(route('users.history.index', ['username' => $user->username]));
$response->assertOk();
$response->assertViewIs('user.history.index');