mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-14 19:35:28 +00:00
Added inern app integration
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Models\Player;
|
||||
use App\Models\Room;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class ShowEmbeddedRoomRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'join_code' => $this->string('join_code')->trim()->upper()->toString(),
|
||||
'player_name' => $this->string('player_name')->trim()->toString(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'join_code' => [
|
||||
'bail',
|
||||
'required',
|
||||
'string',
|
||||
'size:6',
|
||||
Rule::exists(Room::class, 'join_code')->whereNull('deleted_at'),
|
||||
],
|
||||
'player_name' => ['required', 'string', 'max:50'],
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array<callable(Validator): void> */
|
||||
public function after(): array
|
||||
{
|
||||
return [
|
||||
function (Validator $validator): void {
|
||||
if ($validator->errors()->has('join_code')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$room = Room::query()
|
||||
->where('join_code', $this->input('join_code'))
|
||||
->first();
|
||||
|
||||
if ($room?->isClosed()) {
|
||||
$validator->errors()->add('join_code', 'Dieser Raum ist geschlossen.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($room === null || $this->user() === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$nameIsTaken = Player::query()
|
||||
->where('room_id', $room->id)
|
||||
->where('name', $this->input('player_name'))
|
||||
->where(function ($query): void {
|
||||
$query->whereNull('user_id')
|
||||
->orWhere('user_id', '!=', $this->user()->id);
|
||||
})
|
||||
->exists();
|
||||
|
||||
if ($nameIsTaken) {
|
||||
$validator->errors()->add(
|
||||
'player_name',
|
||||
'Dieser Anzeigename ist in dem Raum bereits vorhanden.',
|
||||
);
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'join_code.exists' => 'Dieser Raumcode existiert nicht.',
|
||||
'join_code.size' => 'Der Raumcode muss aus sechs Zeichen bestehen.',
|
||||
'player_name.required' => 'Bitte hinterlege in der Hub-App einen Anzeigenamen.',
|
||||
];
|
||||
}
|
||||
|
||||
protected function failedValidation(Validator $validator): never
|
||||
{
|
||||
throw new HttpResponseException(
|
||||
Inertia::render('embedded/Error', [
|
||||
'message' => $validator->errors()->first(),
|
||||
])->toResponse($this)->setStatusCode(422),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Models\Room;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateRoomSettingsRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
$room = $this->route('room');
|
||||
|
||||
return $room instanceof Room
|
||||
&& $this->user()?->id === $room->owner_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, array<int, string>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'allow_participants_to_manage_rounds' => ['required', 'boolean'],
|
||||
'is_persistent' => ['required', 'boolean'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user