mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 15:52:09 +00:00
fix: refactored the codebase
This commit is contained in:
@@ -2,18 +2,19 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Events\PaperBallThrown;
|
||||
use App\Http\Requests\ThrowPaperBallRequest;
|
||||
use App\Models\Player;
|
||||
use App\Models\Room;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\Rooms\RoomEmoteService;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class RoomEmoteController extends Controller
|
||||
{
|
||||
public function store(Request $request, Room $room): Response
|
||||
public function __construct(
|
||||
private readonly RoomEmoteService $roomEmotes,
|
||||
) {}
|
||||
|
||||
public function store(ThrowPaperBallRequest $request, Room $room): Response
|
||||
{
|
||||
$player = $request->attributes->get('currentPlayer');
|
||||
|
||||
@@ -22,42 +23,10 @@ class RoomEmoteController extends Controller
|
||||
403,
|
||||
);
|
||||
|
||||
$validated = $request->validate([
|
||||
'target_player_id' => ['required', 'integer'],
|
||||
]);
|
||||
$targetPlayerId = (int) $validated['target_player_id'];
|
||||
|
||||
if ($targetPlayerId === $player->id) {
|
||||
throw ValidationException::withMessages([
|
||||
'target_player_id' => 'Du kannst dich nicht selbst abwerfen.',
|
||||
]);
|
||||
}
|
||||
|
||||
$targetExists = $room->players()
|
||||
->whereKey($targetPlayerId)
|
||||
->exists();
|
||||
|
||||
if (! $targetExists) {
|
||||
throw ValidationException::withMessages([
|
||||
'target_player_id' => 'Dieser Spieler sitzt nicht an diesem Tisch.',
|
||||
]);
|
||||
}
|
||||
|
||||
$rateLimitKey = "room-emote:{$room->id}:{$player->id}";
|
||||
|
||||
abort_if(
|
||||
RateLimiter::tooManyAttempts($rateLimitKey, 10),
|
||||
429,
|
||||
'Bitte warte kurz, bevor du erneut wirfst.',
|
||||
);
|
||||
|
||||
RateLimiter::hit($rateLimitKey, 10);
|
||||
|
||||
PaperBallThrown::dispatch(
|
||||
Str::uuid()->toString(),
|
||||
$room->id,
|
||||
$player->id,
|
||||
$targetPlayerId,
|
||||
$this->roomEmotes->throwPaperBall(
|
||||
$room,
|
||||
$player,
|
||||
(int) $request->validated('target_player_id'),
|
||||
);
|
||||
|
||||
return response()->noContent();
|
||||
|
||||
Reference in New Issue
Block a user