mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-03-17 02:20:58 -05:00
Separate requests into cruddy routes. Use route model binding. Allow forfeit of award if request approval is revoked. Use form requests.
95 lines
3.2 KiB
PHP
95 lines
3.2 KiB
PHP
<?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 HDVinnie <hdinnovations@protonmail.com>
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
|
*/
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Requests\StoreTorrentRequestBountyRequest;
|
|
use App\Models\BonTransactions;
|
|
use App\Models\TorrentRequest;
|
|
use App\Notifications\NewRequestBounty;
|
|
use App\Repositories\ChatRepository;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
/**
|
|
* @see \Tests\Todo\Feature\Http\Controllers\RequestControllerTest
|
|
*/
|
|
class BountyController extends Controller
|
|
{
|
|
/**
|
|
* RequestController Constructor.
|
|
*/
|
|
public function __construct(private readonly ChatRepository $chatRepository)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Add Bounty To A Torrent Request.
|
|
*/
|
|
public function store(StoreTorrentRequestBountyRequest $request, TorrentRequest $torrentRequest): \Illuminate\Http\RedirectResponse
|
|
{
|
|
abort_unless($torrentRequest->approved_by === null, 403);
|
|
|
|
$user = $request->user();
|
|
|
|
$torrentRequest->bounties()->create(['user_id' => $user->id] + $request->validated());
|
|
|
|
$torrentRequest->votes++;
|
|
$torrentRequest->bounty += $request->float('seedbonus');
|
|
$torrentRequest->created_at = Carbon::now();
|
|
$torrentRequest->save();
|
|
|
|
BonTransactions::create([
|
|
'itemID' => 0,
|
|
'name' => 'request',
|
|
'cost' => $request->float('seedbonus'),
|
|
'sender' => $user->id,
|
|
'comment' => sprintf('adding bonus to %s', $torrentRequest->name),
|
|
]);
|
|
|
|
$user->decrement('seedbonus', $request->float('seedbonus'));
|
|
|
|
if ($request->boolean('anon') == 0) {
|
|
$this->chatRepository->systemMessage(
|
|
sprintf(
|
|
'[url=%s]%s[/url] has added %s BON bounty to request [url=%s]%s[/url]',
|
|
href_profile($user),
|
|
$user->username,
|
|
$request->input('seedbonus'),
|
|
href_request($torrentRequest),
|
|
$torrentRequest->name
|
|
)
|
|
);
|
|
} else {
|
|
$this->chatRepository->systemMessage(
|
|
sprintf(
|
|
'An anonymous user added %s BON bounty to request [url=%s]%s[/url]',
|
|
$request->input('seedbonus'),
|
|
href_request($torrentRequest),
|
|
$torrentRequest->name
|
|
)
|
|
);
|
|
}
|
|
|
|
$sender = $request->boolean('anon') ? 'Anonymous' : $request->user()->username;
|
|
$requester = $torrentRequest->user;
|
|
|
|
if ($requester->acceptsNotification($request->user(), $requester, 'request', 'show_request_bounty')) {
|
|
$requester->notify(new NewRequestBounty('torrent', $sender, $request->float('seedbonus'), $torrentRequest));
|
|
}
|
|
|
|
return to_route('requests.show', ['torrentRequest' => $torrentRequest])
|
|
->withSuccess(trans('request.added-bonus'));
|
|
}
|
|
}
|