Compare commits

..

6 Commits

Author SHA1 Message Date
sandigmacorp-boop dab7d5a625 Merge branch 'production' of https://git.smgdev.top/SMG_DEV/PXG_2026_API into production
WMS API/PXG_2026_API/pipeline/head This commit looks good Details
2026-02-20 16:10:17 +07:00
sandigmacorp-boop ef989121ba updategroup 2026-02-20 16:10:13 +07:00
Husnu Setiawan d30f34d433 add envoy
WMS API/PXG_2026_API/pipeline/head This commit looks good Details
2026-02-20 14:40:49 +07:00
Husnu Setiawan 4c1fa6cf21 update pairing engine
WMS API/PXG_2026_API/pipeline/head There was a failure building this commit Details
2026-02-20 14:31:46 +07:00
Husnu Setiawan 62f96023e9 add composer envoy
WMS API/PXG_2026_API/pipeline/head This commit looks good Details
2026-02-18 14:32:52 +07:00
Husnu Setiawan 2cb7e44930 add envoy and jenkinsfile
WMS API/PXG_2026_API/pipeline/head There was a failure building this commit Details
2026-02-18 14:28:48 +07:00
9 changed files with 1752 additions and 7 deletions

75
Envoy.blade.php Normal file
View File

@ -0,0 +1,75 @@
@servers(['prod' => 'ubuntu@172.26.12.217', 'dev' => 'ubuntu@smgdev.top'])
@setup
$repository = 'git@172.26.1.255:SMG_DEV/PXG_2026_API.git';
$folder = isset($folder) ? $folder : 'tournament/api';
$releases_dir = '/var/www/'.$folder.'/releases';
$app_dir = '/var/www/'.$folder;
$release = date('YmdHis');
$branch = isset($branch) ? $branch : 'production';
$new_release_dir = $releases_dir .'/'. $release;
@endsetup
@task('clone_repository')
echo 'Cloning repository'
[ -d {{ $releases_dir }} ] || mkdir {{ $releases_dir }}
git clone --depth 1 --single-branch --branch {{ $branch }} {{ $repository }} {{ $new_release_dir }}
cd {{ $new_release_dir }}
@endtask
@task('run_composer')
echo "Starting deployment ({{ $release }})"
cd {{ $new_release_dir }}
composer install --prefer-dist --no-scripts -q -o
@endtask
@task('update_symlinks')
echo "Linking storage directory"
rm -rf {{ $new_release_dir }}/storage
ln -nfs {{ $app_dir }}/storage {{ $new_release_dir }}/storage
echo 'Linking .env file'
ln -nfs {{ $app_dir }}/.env {{ $new_release_dir }}/.env
echo 'Linking current release'
ln -nfs {{ $new_release_dir }} {{ $app_dir }}/current
@endtask
@task('setup_laravel')
cd {{ $app_dir }}/current
php artisan migrate --force
php artisan storage:link
@endtask
@task('clean_old_releases')
# This lists our releases by modification time and delete all but the 3 most recent.
purging=$(ls -dt {{ $releases_dir }}/* | tail -n +5);
if [ "{{ $releases_dir }}" != "" ]; then
if [ "$purging" != "" ]; then
echo Purging old releases: $purging;
rm -rf $purging;
else
echo "No releases found for purging at this time";
fi
fi
@endtask
@story('deploy',["on" => "prod"])
clone_repository
run_composer
update_symlinks
setup_laravel
clean_old_releases
@endstory
@story('deploy-dev',["on" => "dev"])
clone_repository
run_composer
update_symlinks
setup_laravel
clean_old_releases
@endstory

29
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,29 @@
pipeline {
agent any
stages
{
stage("Deploy Dev"){
when {
branch 'development'
}
steps {
sshagent(credentials: ['dev-id_rsa']) {
sh "composer install"
sh "./vendor/bin/envoy run deploy-dev --branch=development"
}
}
}
stage("Deploy Prod"){
when {
branch 'production'
}
steps {
sshagent(credentials: ['dev-id_rsa']) {
sh "composer install"
sh "./vendor/bin/envoy run deploy --branch=production"
}
}
}
}
}

View File

@ -0,0 +1,48 @@
<?php
namespace App\Http\Controllers\Api\V1\Admin;
use App\Http\Controllers\Controller;
use App\Models\Group;
use Illuminate\Http\Request;
class GroupsController extends Controller
{
public function index(Request $request, int $eventId)
{
$q = Group::where('event_id', $eventId)
->withCount('registrations')
->with(['registrations.player' => function($q){ $q->select('id','name','phone','email'); }])
->orderByDesc('id');
if ($request->filled('search')) {
$s = trim($request->get('search'));
$q->where('group_code', 'ilike', "%{$s}%");
}
$items = $q->paginate((int)($request->get('per_page', 25)));
// Normalize response
$items->getCollection()->transform(function($g){
return [
'id' => $g->id,
'group_code' => $g->group_code,
'size_target' => (int)$g->size_target,
'status' => $g->status,
'registrations_count' => (int)$g->registrations_count,
'members' => $g->registrations->map(function($r){
return [
'registration_id' => $r->id,
'type' => $r->type,
'status' => $r->status,
'name' => $r->player?->name,
'phone' => $r->player?->phone,
'email' => $r->player?->email,
];
})->values(),
];
});
return response()->json($items);
}
}

View File

@ -17,18 +17,51 @@ class PairingController extends Controller
{ {
$code = $request->validated()['registration_code']; $code = $request->validated()['registration_code'];
$registration = Registration::where('registration_code', $code)->with('player')->firstOrFail(); $registration = Registration::where('registration_code', $code)
->with('player', 'flightMember.flight.members.registration.player')
->firstOrFail();
// Mask phone for UI: +62***1234 $flightMember = $registration->flightMember;
$phone = $registration->player->phone; $flight = $flightMember?->flight;
$masked = $this->maskPhone($phone);
$members = [];
if ($flight) {
foreach ($flight->members as $m) {
$members[] = [
'seat' => (int) $m->seat_no,
'name' => $m->registration?->player?->name,
'band' => $m->registration?->handicap_band,
'hcp' => $m->registration?->handicap_value,
'is_you' => $m->registration_id === $registration->id,
];
}
}
return response()->json([ return response()->json([
'registration_id' => $registration->id, 'registration' => [
'masked_phone' => $masked, 'status' => $registration->status,
'player' => [
'name' => $registration->player->name,
'band' => $registration->handicap_band,
'handicap' => $registration->handicap_value,
],
'preferences' => [
'pairing_mode' => $registration->pairing_mode,
'pairing_mode_label' => strtolower($registration->pairing_mode) === 'LEVEL' ? 'level' : (strtolower($registration->pairing_mode) === 'RANDOM' ? 'random' : 'balanced'),
],
],
'flight' => $flight ? [
'code' => $flight->code,
'course' => $flight->course,
'start_hole' => (int) $flight->start_hole,
'start_tee' => $flight->start_tee,
'is_final' => $flight->status === 'FINAL',
] : null,
'members' => $members,
]); ]);
} }
public function requestOtp(PairingOtpRequest $request, OtpService $otpService) public function requestOtp(PairingOtpRequest $request, OtpService $otpService)
{ {
$registrationId = $request->validated()['registration_id']; $registrationId = $request->validated()['registration_id'];

View File

@ -102,6 +102,108 @@ class PairingEngine
} }
} }
// 1b) Group-of-2/3 placement (keep same course; prefer same flight)
if ($groupIds->isNotEmpty()) {
$groups23 = Group::whereIn('id', $groupIds)->whereIn('size_target', [2,3])->get();
foreach ($groups23 as $g) {
$need = (int) $g->size_target;
$groupRegs = Registration::where('group_id', $g->id)
->where('status', 'CONFIRMED')
->whereDoesntHave('flightMember')
->with('player')
->get();
// Only place when exact members exist (2 or 3)
if ($groupRegs->count() !== $need) continue;
// derive coursePref from leader if any
$coursePref = 'ANY';
$leader = $groupRegs->firstWhere('type', 'GROUP_LEADER') ?? $groupRegs->first();
if ($leader && in_array($leader->course_pref, ['A','B'])) $coursePref = $leader->course_pref;
// 1) Try same flight with enough seats
$flightId = $this->findFlightWithAtLeastSeats($flights, $flightSeats, $courseLoad, $coursePref, $need);
if (!$flightId && $coursePref !== 'ANY') {
$flightId = $this->findFlightWithAtLeastSeats($flights, $flightSeats, $courseLoad, 'ANY', $need);
}
if ($flightId) {
$seats = array_slice($flightSeats[$flightId], 0, $need);
for ($i=0; $i<$need; $i++) {
$r = $groupRegs[$i];
FlightMember::create([
'flight_id' => $flightId,
'registration_id' => $r->id,
'seat_no' => $seats[$i],
'lock_flag' => false,
]);
$assigned++;
$courseLoad[$flights[$flightId]->course] = ($courseLoad[$flights[$flightId]->course] ?? 0) + 1;
if ($this->isHighLike($r->handicap_band)) {
$h = (int)$flights[$flightId]->start_hole;
$holeHighLikeLoad[$h] = ($holeHighLikeLoad[$h] ?? 0) + 1;
}
}
// consume seats + status
$flightSeats[$flightId] = array_values(array_slice($flightSeats[$flightId], $need));
$this->refreshFlightStatus($flightId);
$notes[] = "group {$g->group_code} -> flight {$flights[$flightId]->code}";
continue;
}
// 2) If no single flight can fit, split but keep SAME COURSE
$course = $this->pickCourseForGroupSplit($flights, $flightSeats, $courseLoad, $coursePref, $need);
if (!$course) {
$notes[] = "no seats available to place group {$g->group_code}";
continue;
}
$placed = 0;
foreach ($flights as $f) {
if ($f->course !== $course) continue;
if (empty($flightSeats[$f->id] ?? [])) continue;
while (!empty($flightSeats[$f->id]) && $placed < $need) {
$seat = array_shift($flightSeats[$f->id]);
$r = $groupRegs[$placed];
FlightMember::create([
'flight_id' => $f->id,
'registration_id' => $r->id,
'seat_no' => $seat,
'lock_flag' => false,
]);
$assigned++;
$courseLoad[$course] = ($courseLoad[$course] ?? 0) + 1;
if ($this->isHighLike($r->handicap_band)) {
$h = (int)$f->start_hole;
$holeHighLikeLoad[$h] = ($holeHighLikeLoad[$h] ?? 0) + 1;
}
$this->refreshFlightStatus($f->id);
$placed++;
}
if ($placed >= $need) break;
}
if ($placed >= $need) {
$notes[] = "group {$g->group_code} -> split in course {$course}";
} else {
$notes[] = "group {$g->group_code} placement incomplete (placed {$placed}/{$need})";
}
}
}
// refresh remaining regs // refresh remaining regs
$regs = $getPendingRegs(); $regs = $getPendingRegs();
@ -481,4 +583,64 @@ class PairingEngine
foreach (['LOW','MID'] as $b) if (!empty($pool[$b])) return array_shift($pool[$b]); foreach (['LOW','MID'] as $b) if (!empty($pool[$b])) return array_shift($pool[$b]);
return null; return null;
} }
private function findFlightWithAtLeastSeats($flights, array $flightSeats, array $courseLoad, string $coursePref, int $need): ?int
{
$candidates = [];
foreach ($flights as $f) {
$avail = count($flightSeats[$f->id] ?? []);
if ($avail < $need) continue;
if (in_array($coursePref, ['A','B']) && $f->course !== $coursePref) continue;
// prefer less-filled flights; if ANY, keep course balanced
$count = $f->members->count();
$score = (4 - $count) * 40;
if (config('pxg.pairing.course_balance', true) && $coursePref === 'ANY') {
$score += (200 - ($courseLoad[$f->course] ?? 0));
}
$candidates[] = [$f->id, $score];
}
if (empty($candidates)) return null;
usort($candidates, fn($x,$y) => $y[1] <=> $x[1]);
return $candidates[0][0];
}
private function pickCourseForGroupSplit($flights, array $flightSeats, array $courseLoad, string $coursePref, int $need): ?string
{
// if preferred course has enough total seats, choose it
if (in_array($coursePref, ['A','B'])) {
$total = 0;
foreach ($flights as $f) {
if ($f->course !== $coursePref) continue;
$total += count($flightSeats[$f->id] ?? []);
}
if ($total >= $need) return $coursePref;
}
// else choose course with more available seats (and/or lower load)
$seatA = 0; $seatB = 0;
foreach ($flights as $f) {
$cnt = count($flightSeats[$f->id] ?? []);
if ($f->course === 'A') $seatA += $cnt;
if ($f->course === 'B') $seatB += $cnt;
}
if ($seatA === 0 && $seatB === 0) return null;
if ($seatA >= $need && $seatB < $need) return 'A';
if ($seatB >= $need && $seatA < $need) return 'B';
// both can fit or neither fully fits -> keep balance (lower load), else more seats
if (config('pxg.pairing.course_balance', true)) {
$loadA = $courseLoad['A'] ?? 0;
$loadB = $courseLoad['B'] ?? 0;
return $loadA <= $loadB ? 'A' : 'B';
}
return $seatA >= $seatB ? 'A' : 'B';
}
} }

View File

@ -13,6 +13,7 @@
}, },
"require-dev": { "require-dev": {
"fakerphp/faker": "^1.9.1", "fakerphp/faker": "^1.9.1",
"laravel/envoy": "^2.10",
"laravel/pint": "^1.0", "laravel/pint": "^1.0",
"laravel/sail": "^1.18", "laravel/sail": "^1.18",
"mockery/mockery": "^1.4.4", "mockery/mockery": "^1.4.4",

65
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "9c491b8531eec05ba41a11d9276a5749", "content-hash": "1c9becfc91324d2c5f77f109db0ebbab",
"packages": [ "packages": [
{ {
"name": "brick/math", "name": "brick/math",
@ -5816,6 +5816,69 @@
}, },
"time": "2025-04-30T06:54:44+00:00" "time": "2025-04-30T06:54:44+00:00"
}, },
{
"name": "laravel/envoy",
"version": "v2.10.2",
"source": {
"type": "git",
"url": "https://github.com/laravel/envoy.git",
"reference": "819a519e3d86b056c7aa3bd5d0801952a6fc14fd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/envoy/zipball/819a519e3d86b056c7aa3bd5d0801952a6fc14fd",
"reference": "819a519e3d86b056c7aa3bd5d0801952a6fc14fd",
"shasum": ""
},
"require": {
"guzzlehttp/guzzle": "^6.0|^7.0",
"illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0",
"php": "^7.2|^8.0",
"symfony/console": "^4.3|^5.0|^6.0|^7.0",
"symfony/process": "^4.3|^5.0|^6.0|^7.0"
},
"require-dev": {
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^8.0|^9.0|^10.4"
},
"suggest": {
"ext-posix": "Required to determine the System user on Unix systems."
},
"bin": [
"bin/envoy"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.x-dev"
}
},
"autoload": {
"psr-4": {
"Laravel\\Envoy\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Taylor Otwell",
"email": "taylor@laravel.com"
}
],
"description": "Elegant SSH tasks for PHP.",
"keywords": [
"laravel",
"ssh"
],
"support": {
"issues": "https://github.com/laravel/envoy/issues",
"source": "https://github.com/laravel/envoy/tree/v2.10.2"
},
"time": "2025-01-28T15:47:18+00:00"
},
{ {
"name": "laravel/pint", "name": "laravel/pint",
"version": "v1.20.0", "version": "v1.20.0",

1332
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -15,6 +15,7 @@ use App\Http\Controllers\Api\V1\Admin\PaymentsController as AdminPaymentsControl
use App\Http\Controllers\Api\V1\Admin\PairingAdminController; use App\Http\Controllers\Api\V1\Admin\PairingAdminController;
use App\Http\Controllers\Api\V1\Admin\EventAdminController; use App\Http\Controllers\Api\V1\Admin\EventAdminController;
use App\Http\Controllers\Api\V1\Admin\ImportController; use App\Http\Controllers\Api\V1\Admin\ImportController;
use App\Http\Controllers\Api\V1\Admin\GroupsController as AdminGroupsController;
@ -43,6 +44,7 @@ Route::middleware('auth:sanctum')->group(function () {
Route::get('/admin/events/{event}/dashboard', [DashboardController::class, 'show']); Route::get('/admin/events/{event}/dashboard', [DashboardController::class, 'show']);
Route::get('/admin/events/{event}/registrations', [AdminRegistrationsController::class, 'index']); Route::get('/admin/events/{event}/registrations', [AdminRegistrationsController::class, 'index']);
Route::get('/admin/events/{event}/groups', [AdminGroupsController::class, 'index']);
Route::patch('/admin/registrations/{registration}', [AdminRegistrationsController::class, 'update']); Route::patch('/admin/registrations/{registration}', [AdminRegistrationsController::class, 'update']);
Route::get('/admin/events/{event}/flights', [AdminFlightsController::class, 'index']); Route::get('/admin/events/{event}/flights', [AdminFlightsController::class, 'index']);