mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 20:32:09 +00:00
feat: some fixes to the ui, imlemented user and guest user, ans used the dahboard
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Models\Room;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
class JoinRoomRequest extends FormRequest
|
||||
{
|
||||
@@ -37,9 +38,54 @@ class JoinRoomRequest extends FormRequest
|
||||
->where('join_code', $this->input('join_code'))
|
||||
->value('id');
|
||||
|
||||
$existingPlayerId = null;
|
||||
|
||||
if ($roomId !== null && $this->user() !== null) {
|
||||
$existingPlayerId = Player::query()
|
||||
->where('room_id', $roomId)
|
||||
->where('user_id', $this->user()->id)
|
||||
->value('id');
|
||||
} elseif ($roomId !== null) {
|
||||
$sessionPlayerId = $this->session()->get("room_players.{$roomId}");
|
||||
$existingPlayerId = is_numeric($sessionPlayerId)
|
||||
? Player::query()
|
||||
->where('room_id', $roomId)
|
||||
->whereKey((int) $sessionPlayerId)
|
||||
->value('id')
|
||||
: null;
|
||||
}
|
||||
|
||||
$playerNameRules = ['required', 'string', 'max:50'];
|
||||
|
||||
if ($existingPlayerId === null) {
|
||||
$playerNameRules[] = Rule::unique(Player::class, 'name')->where('room_id', $roomId);
|
||||
}
|
||||
|
||||
return [
|
||||
'join_code' => ['bail', 'string', 'required', 'size:6', Rule::exists(Room::class, 'join_code')],
|
||||
'player_name' => ['required', 'string', 'max:50', Rule::unique(Player::class, 'name')->where('room_id', $roomId)],
|
||||
'join_code' => [
|
||||
'bail',
|
||||
'string',
|
||||
'required',
|
||||
'size:6',
|
||||
Rule::exists(Room::class, 'join_code')->whereNull('deleted_at'),
|
||||
],
|
||||
'player_name' => $playerNameRules,
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array<callable(Validator): void> */
|
||||
public function after(): array
|
||||
{
|
||||
return [
|
||||
function (Validator $validator): void {
|
||||
$room = Room::query()
|
||||
->where('join_code', $this->input('join_code'))
|
||||
->first();
|
||||
|
||||
if ($room?->isClosed()) {
|
||||
$validator->errors()->add('join_code', 'Dieser Raum ist geschlossen.');
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user