diff --git a/app/Http/Controllers/Admin/LocationsController.php b/app/Http/Controllers/Admin/LocationsController.php index dbf108f2d..e914c9753 100644 --- a/app/Http/Controllers/Admin/LocationsController.php +++ b/app/Http/Controllers/Admin/LocationsController.php @@ -5,7 +5,11 @@ namespace Pterodactyl\Http\Controllers\Admin; use DB; use Pterodactyl\Models; +use Pterodactyl\Repositories\LocationRepository; use Pterodactyl\Http\Controllers\Controller; + +use Pterodactyl\Exceptions\DisplayValidationException; + use Illuminate\Http\Request; class LocationsController extends Controller @@ -51,4 +55,25 @@ class LocationsController extends Controller return response('', 204); } + public function patchLocation(Request $request, $id) + { + try { + $location = new LocationRepository; + $location->edit($id, $request->all()); + return response('', 204); + } catch (DisplayValidationException $ex) { + return response()->json([ + 'error' => 'There was a validation error while processing this request. Location descriptions must be between 1 and 255 characters, and the location code must be between 1 and 10 characters with no spaces or special characters.' + ], 422); + } catch (\Exception $ex) { + // This gets caught and processed into JSON anyways. + throw $ex; + } + } + + public function postLocation(Request $request) + { + // + } + } diff --git a/app/Http/Routes/AdminRoutes.php b/app/Http/Routes/AdminRoutes.php index cc32e31d8..392220952 100644 --- a/app/Http/Routes/AdminRoutes.php +++ b/app/Http/Routes/AdminRoutes.php @@ -219,6 +219,12 @@ class AdminRoutes { $router->delete('/{id}', [ 'uses' => 'Admin\LocationsController@deleteLocation' ]); + $router->patch('/{id}', [ + 'uses' => 'Admin\LocationsController@patchLocation' + ]); + $router->post('/', [ + 'uses' => 'Admin\LocationsController@postLocation' + ]); }); // API Routes diff --git a/app/Repositories/LocationRepository.php b/app/Repositories/LocationRepository.php new file mode 100644 index 000000000..3f4a16fb5 --- /dev/null +++ b/app/Repositories/LocationRepository.php @@ -0,0 +1,44 @@ + 'regex:/^[a-z0-9_.-]{1,10}$/i', + 'long' => 'string|min:1|max:255' + ]); + + // Run validator, throw catchable and displayable exception if it fails. + // Exception includes a JSON result of failed validation rules. + if ($validator->fails()) { + throw new DisplayValidationException($validator->errors()); + } + + $location = Models\Location::findOrFail($id); + + if (isset($data['short'])) { + $location->short = $data['short']; + } + + if (isset($data['long'])) { + $location->long = $data['long']; + } + + return $location->save(); + } +} diff --git a/resources/views/admin/locations/index.blade.php b/resources/views/admin/locations/index.blade.php index 643c55be1..2ea3338b1 100644 --- a/resources/views/admin/locations/index.blade.php +++ b/resources/views/admin/locations/index.blade.php @@ -29,7 +29,7 @@ {{ $location->long }} {{ $location->a_nodeCount }} {{ $location->a_serverCount }} - + @endforeach @@ -46,9 +46,78 @@ +