Files
SGF/app/Modules/Workshop/Http/WorkshopScheduleController.php
2026-11-11 09:00:17 +02:00

14 lines
1.5 KiB
PHP

<?php
namespace App\Modules\Workshop\Http;
use App\Modules\Workshop\WorkshopSchedule;
use Illuminate\Http\Request;
final class WorkshopScheduleController
{
private function response(\Closure $fn){try{return response()->json($fn())->header('Cache-Control','no-store, private');}catch(\Illuminate\Database\QueryException $e){if(!in_array($e->errorInfo[0]??null,['55P03','57014'],true))throw $e;return response()->json(['message'=>'Agenda ocupada. Recupere a mesma confirmação.'],503)->header('Retry-After','5');}}
public function index(Request $r,WorkshopSchedule $w){return $this->response(fn()=>$w->listing($r->user()->id,$r->query()));}
public function options(Request $r,WorkshopSchedule $w){return $this->response(fn()=>$w->options($r->user()->id,$r->query()));}
public function preview(Request $r,WorkshopSchedule $w){return $this->response(fn()=>$w->preview($r->user()->id,$r->all(),strtolower((string)$r->header('Idempotency-Key'))));}
public function confirm(Request $r,WorkshopSchedule $w){$d=$r->validate(['preview'=>'required|string|max:65536']);abort_if(array_diff(array_keys($r->all()),['preview']),422);return $this->response(fn()=>$w->confirm($r->user()->id,$d['preview']));}
public function history(Request $r,WorkshopSchedule $w,string $key){$d=$r->validate(['page'=>'sometimes|integer|min:1|max:100000']);abort_if(array_diff(array_keys($r->query()),['page']),422);return $this->response(fn()=>$w->history($r->user()->id,$key,(int)($d['page']??1)));}
}