45 lines
1.5 KiB
PHP
45 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\StoreRegistrationRequest;
|
|
use App\Models\Event;
|
|
use App\Models\Player;
|
|
use App\Models\Registration;
|
|
use App\Services\RegistrationCodeService;
|
|
|
|
class RegistrationController extends Controller
|
|
{
|
|
public function store(Event $event, StoreRegistrationRequest $request, RegistrationCodeService $codeService)
|
|
{
|
|
$data = $request->validated();
|
|
|
|
$player = Player::create([
|
|
'name' => $data['player']['name'],
|
|
'phone' => $data['player']['phone'],
|
|
'email' => $data['player']['email'],
|
|
'club' => $data['player']['club'] ?? null,
|
|
'shirt_size' => $data['player']['shirt_size'] ?? null,
|
|
]);
|
|
|
|
$registration = Registration::create([
|
|
'event_id' => $event->id,
|
|
'player_id' => $player->id,
|
|
'type' => 'INDIVIDUAL',
|
|
'status' => 'PENDING_PAYMENT',
|
|
'handicap_type' => $data['handicap']['type'],
|
|
'handicap_value' => $data['handicap']['value'] ?? null,
|
|
'handicap_band' => $data['handicap']['band'],
|
|
'pairing_mode' => $data['preferences']['pairing_mode'],
|
|
'course_pref' => $data['preferences']['course_pref'],
|
|
'registration_code' => $codeService->make(),
|
|
]);
|
|
|
|
return response()->json([
|
|
'id' => $registration->id,
|
|
'registration_code' => $registration->registration_code,
|
|
], 201);
|
|
}
|
|
}
|