Massively simplify API binding logic

Changes the API internals to use normal Laravel binding which automatically supports nested-models and can determine their relationships. This removes a lot of confusingly complex internal logic and replaces it with standard Laravel code.

This also removes a deprecated "getModel" method and fully replaces it with a "parameter" method that does stricter type-checking.
This commit is contained in:
DaneEveritt 2022-05-22 14:10:01 -04:00
parent f1235c7f88
commit e313dff674
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
53 changed files with 290 additions and 604 deletions

View file

@ -75,9 +75,9 @@ class LocationController extends ApplicationApiController
/**
* Return a single location.
*/
public function view(GetLocationRequest $request): array
public function view(GetLocationRequest $request, Location $location): array
{
return $this->fractal->item($request->getModel(Location::class))
return $this->fractal->item($location)
->transformWith($this->getTransformer(LocationTransformer::class))
->toArray();
}
@ -108,9 +108,9 @@ class LocationController extends ApplicationApiController
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function update(UpdateLocationRequest $request): array
public function update(UpdateLocationRequest $request, Location $location): array
{
$location = $this->updateService->handle($request->getModel(Location::class), $request->validated());
$location = $this->updateService->handle($location, $request->validated());
return $this->fractal->item($location)
->transformWith($this->getTransformer(LocationTransformer::class))
@ -122,9 +122,9 @@ class LocationController extends ApplicationApiController
*
* @throws \Pterodactyl\Exceptions\Service\Location\HasActiveNodesException
*/
public function delete(DeleteLocationRequest $request): Response
public function delete(DeleteLocationRequest $request, Location $location): Response
{
$this->deletionService->handle($request->getModel(Location::class));
$this->deletionService->handle($location);
return response('', 204);
}