commit melhorias sgf
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace App\Modules\Workshop\Http;
|
||||
use App\Modules\Workshop\WorkshopEquipment;use Illuminate\Http\Request;
|
||||
final class WorkshopEquipmentController
|
||||
{
|
||||
public function index(Request $r,WorkshopEquipment $w){return response()->json($w->listing($r->user()->id,$r->query()))->header('Cache-Control','no-store, private');}
|
||||
public function preview(Request $r,WorkshopEquipment $w){return response()->json($w->preview($r->user()->id,$r->all(),strtolower((string)$r->header('Idempotency-Key'))))->header('Cache-Control','no-store');}
|
||||
public function confirm(Request $r,WorkshopEquipment $w){$d=$r->validate(['preview'=>'required|string|max:65536']);abort_if(array_diff(array_keys($r->all()),['preview']),422);try{return response()->json($w->confirm($r->user()->id,$d['preview']))->header('Cache-Control','no-store');}catch(\Illuminate\Database\QueryException $e){if(!in_array($e->errorInfo[0]??null,['55P03','57014'],true))throw $e;return response()->json(['message'=>'Registo ocupado. Recupere a mesma confirmação.'],503)->header('Retry-After','5');}}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace App\Modules\Workshop\Http;
|
||||
use App\Modules\Workshop\WorkshopOrderRead;
|
||||
use Illuminate\Http\Request;
|
||||
final class WorkshopOrderReadController
|
||||
{
|
||||
public function index(Request $request,WorkshopOrderRead $reader){return response()->json($reader->listing($request->user()->id,$request->query()))->header('Cache-Control','private, no-store');}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?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)));}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ final class WorkshopStockController
|
||||
{
|
||||
private function response(callable $read)
|
||||
{
|
||||
try{return response()->json($read())->header('Cache-Control','no-store');}
|
||||
try{return config('workshop_stock.composed_enabled')===true?app(\App\Modules\Workshop\ComposedWorkshopStockBook::class)->run(fn()=>response()->json($read())->header('Cache-Control','no-store')):response()->json($read())->header('Cache-Control','no-store');}
|
||||
catch(\Illuminate\Database\QueryException $e){
|
||||
$code=$e->errorInfo[0]??null;
|
||||
if($code==='55P03')return response()->json(['code'=>'workshop_stock_busy','message'=>'Consumo ocupado por outra operação. Aguarde e repita manualmente; o estado será revalidado.'],423)->header('Cache-Control','no-store');
|
||||
@@ -15,7 +15,7 @@ final class WorkshopStockController
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
public function index(Request $r,WorkshopStock $stock){$d=$r->validate(['page'=>'sometimes|integer|min:1|max:100000','proposal_page'=>'sometimes|integer|min:1|max:100000','status'=>'sometimes|in:all,pending,confirmed,withdrawn,rejected']);abort_if(array_diff(array_keys($r->query()),array_keys($d)),422);return $this->response(fn()=>\Illuminate\Support\Facades\DB::transaction(function()use($stock,$d){\Illuminate\Support\Facades\DB::statement('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ READ ONLY');return $stock->listing((int)($d['page']??1),(int)($d['proposal_page']??1),$d['status']??'all');}));}
|
||||
public function index(Request $r,WorkshopStock $stock){$d=$r->validate(['page'=>'sometimes|integer|min:1|max:100000','proposal_page'=>'sometimes|integer|min:1|max:100000','status'=>'sometimes|in:all,pending,confirmed,withdrawn,rejected']);abort_if(array_diff(array_keys($r->query()),array_keys($d)),422);return $this->response(fn()=>\Illuminate\Support\Facades\DB::transaction(function()use($stock,$d){if(!\App\Modules\Workshop\ComposedWorkshopStockBook::active())\Illuminate\Support\Facades\DB::statement('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ READ ONLY');return $stock->listing((int)($d['page']??1),(int)($d['proposal_page']??1),$d['status']??'all');}));}
|
||||
public function withdraw(Request $r,int $id,WorkshopStock $stock){return $this->close($r,$id,$stock,'withdrawn');}
|
||||
public function reject(Request $r,int $id,WorkshopStock $stock){return $this->close($r,$id,$stock,'rejected');}
|
||||
private function close(Request $r,int $id,WorkshopStock $stock,string $state){$d=$r->validate(['state_version'=>'required|integer|min:1|max:100000','source_hash'=>'required|string|regex:/^[a-f0-9]{64}$/D','reason'=>'required|string|min:10|max:1000']);abort_if(array_diff(array_keys($r->all()),array_keys($d)),422);return $this->response(fn()=>$stock->close($id,$state,(int)$d['state_version'],$d['source_hash'],$d['reason']));}
|
||||
@@ -26,3 +26,4 @@ final class WorkshopStockController
|
||||
public function prepareReturn(Request $r,WorkshopStock $stock){return $this->delivery($r,$stock,false,true);}
|
||||
private function delivery(Request $r,WorkshopStock $stock,bool $partial,bool $returning=false){$d=$r->validate(['entry_id'=>'required|integer|min:1','version'=>'required|integer|min:1','warehouse_id'=>'required|integer|min:1','movement_id'=>'required|integer|min:1','reason'=>'required|string|min:10|max:1000','evidence'=>'required|string|min:3|max:500']);abort_if(array_diff(array_keys($r->all()),array_keys($d)),422);$key=(string)$r->header('Idempotency-Key');abort_unless(\Illuminate\Support\Str::isUuid($key),422,'Chave de repetição obrigatória.');return $this->response(fn()=>$stock->prepareDelivery($d,$key,$partial,$returning));}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user