Add competition/laravel/laravel.md
This commit is contained in:
parent
f8f98f370e
commit
5f3185e2c0
257
competition/laravel/laravel.md
Normal file
257
competition/laravel/laravel.md
Normal file
@ -0,0 +1,257 @@
|
||||
Here is a complete Laravel API service implementation with all functions fully defined per your Taekwondo tournament system requirements. It covers participant filtering by WT 2025 official age, gender, and weight classes, plus a master API that accepts JSON payloads of players and returns grouped draw-ready data from A to Z.
|
||||
|
||||
***
|
||||
|
||||
### 1. Service Class: `TaekwondoService.php`
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
class TaekwondoService
|
||||
{
|
||||
public function calculateAge($dob): int
|
||||
{
|
||||
return Carbon::parse($dob)->age;
|
||||
}
|
||||
|
||||
public function getAgeCategory(int $age): string
|
||||
{
|
||||
if ($age >= 6 && $age <= 11) return "Child";
|
||||
if ($age >= 12 && $age <= 14) return "Cadet";
|
||||
if ($age >= 15 && $age <= 17) return "Junior";
|
||||
if ($age >= 18 && $age <= 32) return "Senior";
|
||||
if ($age >= 33 && $age <= 40) return "Ultra 1";
|
||||
if ($age >= 41 && $age <= 50) return "Ultra 2";
|
||||
if ($age >= 51 && $age <= 60) return "Ultra 3";
|
||||
if ($age >= 61) return "Ultra 4";
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
public function getWeightClass(string $gender, int $age, ?float $weight): string
|
||||
{
|
||||
if (is_null($weight)) return "Unknown";
|
||||
|
||||
if ($gender === 'Male') {
|
||||
if ($age >= 6 && $age <= 11) {
|
||||
if ($weight <= 22) return "-22kg";
|
||||
if ($weight <= 24) return "-24kg";
|
||||
if ($weight <= 26) return "-26kg";
|
||||
if ($weight <= 29) return "-29kg";
|
||||
if ($weight <= 32) return "-32kg";
|
||||
if ($weight <= 35) return "-35kg";
|
||||
if ($weight <= 38) return "-38kg";
|
||||
if ($weight <= 42) return "-42kg";
|
||||
if ($weight <= 45) return "-45kg";
|
||||
return "+45kg";
|
||||
}
|
||||
if ($age >= 12 && $age <= 14) {
|
||||
if ($weight <= 33) return "-33kg";
|
||||
if ($weight <= 37) return "-37kg";
|
||||
if ($weight <= 41) return "-41kg";
|
||||
if ($weight <= 45) return "-45kg";
|
||||
if ($weight <= 49) return "-49kg";
|
||||
if ($weight <= 53) return "-53kg";
|
||||
if ($weight <= 57) return "-57kg";
|
||||
if ($weight <= 61) return "-61kg";
|
||||
if ($weight <= 65) return "-65kg";
|
||||
return "+65kg";
|
||||
}
|
||||
if ($age >= 15 && $age <= 17) {
|
||||
if ($weight <= 45) return "-45kg";
|
||||
if ($weight <= 48) return "-48kg";
|
||||
if ($weight <= 51) return "-51kg";
|
||||
if ($weight <= 55) return "-55kg";
|
||||
if ($weight <= 59) return "-59kg";
|
||||
if ($weight <= 63) return "-63kg";
|
||||
if ($weight <= 68) return "-68kg";
|
||||
if ($weight <= 73) return "-73kg";
|
||||
if ($weight <= 78) return "-78kg";
|
||||
return "+78kg";
|
||||
}
|
||||
if ($age >= 18) {
|
||||
if ($weight <= 54) return "-54kg";
|
||||
if ($weight <= 58) return "-58kg";
|
||||
if ($weight <= 63) return "-63kg";
|
||||
if ($weight <= 68) return "-68kg";
|
||||
if ($weight <= 74) return "-74kg";
|
||||
if ($weight <= 80) return "-80kg";
|
||||
if ($weight <= 87) return "-87kg";
|
||||
return "+87kg";
|
||||
}
|
||||
}
|
||||
if ($gender === 'Female') {
|
||||
if ($age >= 6 && $age <= 11) {
|
||||
if ($weight <= 22) return "-22kg";
|
||||
if ($weight <= 24) return "-24kg";
|
||||
if ($weight <= 26) return "-26kg";
|
||||
if ($weight <= 29) return "-29kg";
|
||||
if ($weight <= 32) return "-32kg";
|
||||
if ($weight <= 35) return "-35kg";
|
||||
if ($weight <= 38) return "-38kg";
|
||||
if ($weight <= 42) return "-42kg";
|
||||
if ($weight <= 45) return "-45kg";
|
||||
return "+45kg";
|
||||
}
|
||||
if ($age >= 12 && $age <= 14) {
|
||||
if ($weight <= 29) return "-29kg";
|
||||
if ($weight <= 33) return "-33kg";
|
||||
if ($weight <= 37) return "-37kg";
|
||||
if ($weight <= 41) return "-41kg";
|
||||
if ($weight <= 44) return "-44kg";
|
||||
if ($weight <= 47) return "-47kg";
|
||||
if ($weight <= 51) return "-51kg";
|
||||
if ($weight <= 55) return "-55kg";
|
||||
if ($weight <= 59) return "-59kg";
|
||||
return "+59kg";
|
||||
}
|
||||
if ($age >= 15 && $age <= 17) {
|
||||
if ($weight <= 42) return "-42kg";
|
||||
if ($weight <= 44) return "-44kg";
|
||||
if ($weight <= 46) return "-46kg";
|
||||
if ($weight <= 49) return "-49kg";
|
||||
if ($weight <= 52) return "-52kg";
|
||||
if ($weight <= 55) return "-55kg";
|
||||
if ($weight <= 59) return "-59kg";
|
||||
if ($weight <= 63) return "-63kg";
|
||||
if ($weight <= 68) return "-68kg";
|
||||
return "+68kg";
|
||||
}
|
||||
if ($age >= 18) {
|
||||
if ($weight <= 46) return "-46kg";
|
||||
if ($weight <= 49) return "-49kg";
|
||||
if ($weight <= 53) return "-53kg";
|
||||
if ($weight <= 57) return "-57kg";
|
||||
if ($weight <= 62) return "-62kg";
|
||||
if ($weight <= 67) return "-67kg";
|
||||
if ($weight <= 73) return "-73kg";
|
||||
return "+73kg";
|
||||
}
|
||||
}
|
||||
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
public function groupPlayersForPredraw(array $players): array
|
||||
{
|
||||
$groups = [];
|
||||
foreach ($players as $player) {
|
||||
$age = $this->calculateAge($player['dob']);
|
||||
$gender = $player['gender'] ?? 'Unknown';
|
||||
$ageCategory = $this->getAgeCategory($age);
|
||||
$weightClass = $this->getWeightClass($gender, $age, $player['weight'] ?? null);
|
||||
|
||||
$key = "{$gender}|{$ageCategory}|{$weightClass}";
|
||||
|
||||
if (!isset($groups[$key])) {
|
||||
$groups[$key] = [
|
||||
'gender' => $gender,
|
||||
'ageCategory' => $ageCategory,
|
||||
'weightClass' => $weightClass,
|
||||
'players' => []
|
||||
];
|
||||
}
|
||||
$groups[$key]['players'][] = $player;
|
||||
}
|
||||
|
||||
return array_values($groups);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
### 2. API Controller (full process endpoint)
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\TaekwondoService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TaekwondoController extends Controller
|
||||
{
|
||||
protected $service;
|
||||
|
||||
public function __construct(TaekwondoService $service)
|
||||
{
|
||||
$this->service = $service;
|
||||
}
|
||||
|
||||
public function processAll(Request $request)
|
||||
{
|
||||
$players = $request->input('players', []);
|
||||
|
||||
if (empty($players)) {
|
||||
return response()->json(['error' => 'Players array is required'], 422);
|
||||
}
|
||||
|
||||
$groups = $this->service->groupPlayersForPredraw($players);
|
||||
|
||||
return response()->json(['groups' => $groups]);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
### 3. API Route
|
||||
|
||||
```php
|
||||
use App\Http\Controllers\Api\TaekwondoController;
|
||||
|
||||
Route::post('/taekwondo/process-all', [TaekwondoController::class, 'processAll']);
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
### Usage
|
||||
|
||||
Send a POST request to `/api/taekwondo/process-all` with JSON:
|
||||
|
||||
```json
|
||||
{
|
||||
"players": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Ali",
|
||||
"gender": "Male",
|
||||
"dob": "2012-05-10",
|
||||
"weight": 30
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Sara",
|
||||
"gender": "Female",
|
||||
"dob": "2010-08-20",
|
||||
"weight": 28
|
||||
}
|
||||
// more player records
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
The service will return the players grouped accurately by WT official categories—a full “from A to Z” client-facing API covering your filtering and classification needs.
|
||||
|
||||
***
|
||||
|
||||
This provides a robust, well-structured Laravel API service and a complete detailed filter implementation with no skipping of any essential category or weight breakpoint as you requested.
|
||||
|
||||
Let me know if you want me to build expanding bracket generation and match progression APIs next!
|
||||
|
||||
[1](https://laracasts.com/discuss/channels/code-review/tournament-system)
|
||||
[2](https://repository.cpu.edu.ph/handle/20.500.12852/1522?locale-attribute=zh)
|
||||
[3](https://smoothcomp.com/en/features/taekwondo)
|
||||
[4](https://kumitetechnology.com/docs/tournament)
|
||||
[5](https://www.scribd.com/document/579914729/Sports-Tournament-Management-System)
|
||||
[6](https://assada.github.io/laravel-achievements/)
|
||||
[7](https://web.stanford.edu/group/Taekwondo/documents/Effective%20Tournament%20Management.pdf)
|
||||
[8](https://laraveldaily.com/lesson/laravel-database-structure/tournament-with-places)
|
||||
[9](https://www.kihapp.com)
|
||||
[10](https://laravel.com/learn)
|
||||
Loading…
x
Reference in New Issue
Block a user