22
33namespace Pterodactyl \Http \Controllers \Api \Application \Locations ;
44
5- use Spatie \Fractal \Fractal ;
65use Illuminate \Http \Response ;
76use Pterodactyl \Models \Location ;
87use Illuminate \Http \JsonResponse ;
9- use Pterodactyl \Http \Controllers \Controller ;
10- use League \Fractal \Pagination \IlluminatePaginatorAdapter ;
118use Pterodactyl \Services \Locations \LocationUpdateService ;
129use Pterodactyl \Services \Locations \LocationCreationService ;
1310use Pterodactyl \Services \Locations \LocationDeletionService ;
1411use Pterodactyl \Contracts \Repository \LocationRepositoryInterface ;
1512use Pterodactyl \Transformers \Api \Application \LocationTransformer ;
13+ use Pterodactyl \Http \Controllers \Api \Application \ApplicationApiController ;
1614use Pterodactyl \Http \Requests \Api \Application \Locations \GetLocationsRequest ;
1715use Pterodactyl \Http \Requests \Api \Application \Locations \DeleteLocationRequest ;
1816use Pterodactyl \Http \Requests \Api \Application \Locations \UpdateLocationRequest ;
1917
20- class LocationController extends Controller
18+ class LocationController extends ApplicationApiController
2119{
2220 /**
2321 * @var \Pterodactyl\Services\Locations\LocationCreationService
@@ -29,11 +27,6 @@ class LocationController extends Controller
2927 */
3028 private $ deletionService ;
3129
32- /**
33- * @var \Spatie\Fractal\Fractal
34- */
35- private $ fractal ;
36-
3730 /**
3831 * @var \Pterodactyl\Contracts\Repository\LocationRepositoryInterface
3932 */
@@ -47,22 +40,21 @@ class LocationController extends Controller
4740 /**
4841 * LocationController constructor.
4942 *
50- * @param \Spatie\Fractal\Fractal $fractal
5143 * @param \Pterodactyl\Services\Locations\LocationCreationService $creationService
5244 * @param \Pterodactyl\Services\Locations\LocationDeletionService $deletionService
5345 * @param \Pterodactyl\Contracts\Repository\LocationRepositoryInterface $repository
5446 * @param \Pterodactyl\Services\Locations\LocationUpdateService $updateService
5547 */
5648 public function __construct (
57- Fractal $ fractal ,
5849 LocationCreationService $ creationService ,
5950 LocationDeletionService $ deletionService ,
6051 LocationRepositoryInterface $ repository ,
6152 LocationUpdateService $ updateService
6253 ) {
54+ parent ::__construct ();
55+
6356 $ this ->creationService = $ creationService ;
6457 $ this ->deletionService = $ deletionService ;
65- $ this ->fractal = $ fractal ;
6658 $ this ->repository = $ repository ;
6759 $ this ->updateService = $ updateService ;
6860 }
@@ -78,24 +70,20 @@ public function index(GetLocationsRequest $request): array
7870 $ locations = $ this ->repository ->paginated (100 );
7971
8072 return $ this ->fractal ->collection ($ locations )
81- ->transformWith ((new LocationTransformer )->setKey ($ request ->key ()))
82- ->withResourceName ('location ' )
83- ->paginateWith (new IlluminatePaginatorAdapter ($ locations ))
73+ ->transformWith ($ this ->getTransformer (LocationTransformer::class))
8474 ->toArray ();
8575 }
8676
8777 /**
8878 * Return a single location.
8979 *
9080 * @param \Pterodactyl\Http\Controllers\Api\Application\Locations\GetLocationRequest $request
91- * @param \Pterodactyl\Models\Location $location
9281 * @return array
9382 */
94- public function view (GetLocationRequest $ request, Location $ location ): array
83+ public function view (GetLocationRequest $ request ): array
9584 {
96- return $ this ->fractal ->item ($ location )
97- ->transformWith ((new LocationTransformer )->setKey ($ request ->key ()))
98- ->withResourceName ('location ' )
85+ return $ this ->fractal ->item ($ request ->getModel (Location::class))
86+ ->transformWith ($ this ->getTransformer (LocationTransformer::class))
9987 ->toArray ();
10088 }
10189
@@ -113,43 +101,44 @@ public function store(StoreLocationRequest $request): JsonResponse
113101 $ location = $ this ->creationService ->handle ($ request ->validated ());
114102
115103 return $ this ->fractal ->item ($ location )
116- ->transformWith ((new LocationTransformer )->setKey ($ request ->key ()))
117- ->withResourceName ('location ' )
104+ ->transformWith ($ this ->getTransformer (LocationTransformer::class))
105+ ->addMeta ([
106+ 'resource ' => route ('api.application.locations.view ' , [
107+ 'location ' => $ location ->id ,
108+ ]),
109+ ])
118110 ->respond (201 );
119111 }
120112
121113 /**
122114 * Update a location on the Panel and return the updated record to the user.
123115 *
124116 * @param \Pterodactyl\Http\Requests\Api\Application\Locations\UpdateLocationRequest $request
125- * @param \Pterodactyl\Models\Location $location
126117 * @return array
127118 *
128119 * @throws \Pterodactyl\Exceptions\Model\DataValidationException
129120 * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
130121 */
131- public function update (UpdateLocationRequest $ request, Location $ location ): array
122+ public function update (UpdateLocationRequest $ request ): array
132123 {
133- $ location = $ this ->updateService ->handle ($ location , $ request ->validated ());
124+ $ location = $ this ->updateService ->handle ($ request -> getModel (Location::class) , $ request ->validated ());
134125
135126 return $ this ->fractal ->item ($ location )
136- ->transformWith ((new LocationTransformer )->setKey ($ request ->key ()))
137- ->withResourceName ('location ' )
127+ ->transformWith ($ this ->getTransformer (LocationTransformer::class))
138128 ->toArray ();
139129 }
140130
141131 /**
142132 * Delete a location from the Panel.
143133 *
144134 * @param \Pterodactyl\Http\Requests\Api\Application\Locations\DeleteLocationRequest $request
145- * @param \Pterodactyl\Models\Location $location
146135 * @return \Illuminate\Http\Response
147136 *
148137 * @throws \Pterodactyl\Exceptions\Service\Location\HasActiveNodesException
149138 */
150- public function delete (DeleteLocationRequest $ request, Location $ location ): Response
139+ public function delete (DeleteLocationRequest $ request ): Response
151140 {
152- $ this ->deletionService ->handle ($ location );
141+ $ this ->deletionService ->handle ($ request -> getModel (Location::class) );
153142
154143 return response ('' , 204 );
155144 }
0 commit comments