33namespace Pterodactyl \Http \Controllers \Api \Application \Nodes ;
44
55use Pterodactyl \Models \Node ;
6- use Illuminate \Http \Response ;
6+ use Illuminate \Http \JsonResponse ;
77use Pterodactyl \Models \Allocation ;
88use Pterodactyl \Services \Allocations \AssignmentService ;
99use Pterodactyl \Services \Allocations \AllocationDeletionService ;
10- use Pterodactyl \Contracts \Repository \AllocationRepositoryInterface ;
1110use Pterodactyl \Transformers \Api \Application \AllocationTransformer ;
1211use Pterodactyl \Http \Controllers \Api \Application \ApplicationApiController ;
1312use Pterodactyl \Http \Requests \Api \Application \Allocations \GetAllocationsRequest ;
@@ -26,41 +25,32 @@ class AllocationController extends ApplicationApiController
2625 */
2726 private $ deletionService ;
2827
29- /**
30- * @var \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface
31- */
32- private $ repository ;
33-
3428 /**
3529 * AllocationController constructor.
3630 *
3731 * @param \Pterodactyl\Services\Allocations\AssignmentService $assignmentService
3832 * @param \Pterodactyl\Services\Allocations\AllocationDeletionService $deletionService
39- * @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $repository
4033 */
4134 public function __construct (
4235 AssignmentService $ assignmentService ,
43- AllocationDeletionService $ deletionService ,
44- AllocationRepositoryInterface $ repository
36+ AllocationDeletionService $ deletionService
4537 ) {
4638 parent ::__construct ();
4739
4840 $ this ->assignmentService = $ assignmentService ;
4941 $ this ->deletionService = $ deletionService ;
50- $ this ->repository = $ repository ;
5142 }
5243
5344 /**
5445 * Return all of the allocations that exist for a given node.
5546 *
5647 * @param \Pterodactyl\Http\Requests\Api\Application\Allocations\GetAllocationsRequest $request
48+ * @param \Pterodactyl\Models\Node $node
5749 * @return array
5850 */
59- public function index (GetAllocationsRequest $ request ): array
51+ public function index (GetAllocationsRequest $ request, Node $ node ): array
6052 {
61- $ allocations = $ this ->repository ->getPaginatedAllocationsForNode (
62- $ request ->getModel (Node::class)->id , 50
63- );
53+ $ allocations = $ node ->allocations ()->paginate (50 );
6454
6555 return $ this ->fractal ->collection ($ allocations )
6656 ->transformWith ($ this ->getTransformer (AllocationTransformer::class))
@@ -71,32 +61,35 @@ public function index(GetAllocationsRequest $request): array
7161 * Store new allocations for a given node.
7262 *
7363 * @param \Pterodactyl\Http\Requests\Api\Application\Allocations\StoreAllocationRequest $request
74- * @return \Illuminate\Http\Response
64+ * @param \Pterodactyl\Models\Node $node
65+ * @return \Illuminate\Http\JsonResponse
7566 *
7667 * @throws \Pterodactyl\Exceptions\Service\Allocation\CidrOutOfRangeException
7768 * @throws \Pterodactyl\Exceptions\Service\Allocation\InvalidPortMappingException
7869 * @throws \Pterodactyl\Exceptions\Service\Allocation\PortOutOfRangeException
7970 * @throws \Pterodactyl\Exceptions\Service\Allocation\TooManyPortsInRangeException
8071 */
81- public function store (StoreAllocationRequest $ request ): Response
72+ public function store (StoreAllocationRequest $ request, Node $ node ): JsonResponse
8273 {
83- $ this ->assignmentService ->handle ($ request -> getModel (Node::class) , $ request ->validated ());
74+ $ this ->assignmentService ->handle ($ node , $ request ->validated ());
8475
85- return response ( '' , 204 );
76+ return new JsonResponse ([], JsonResponse:: HTTP_NO_CONTENT );
8677 }
8778
8879 /**
8980 * Delete a specific allocation from the Panel.
9081 *
9182 * @param \Pterodactyl\Http\Requests\Api\Application\Allocations\DeleteAllocationRequest $request
92- * @return \Illuminate\Http\Response
83+ * @param \Pterodactyl\Models\Node $node
84+ * @param \Pterodactyl\Models\Allocation $allocation
85+ * @return \Illuminate\Http\JsonResponse
9386 *
9487 * @throws \Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException
9588 */
96- public function delete (DeleteAllocationRequest $ request ): Response
89+ public function delete (DeleteAllocationRequest $ request, Node $ node , Allocation $ allocation ): JsonResponse
9790 {
98- $ this ->deletionService ->handle ($ request -> getModel (Allocation::class) );
91+ $ this ->deletionService ->handle ($ allocation );
9992
100- return response ( '' , 204 );
93+ return new JsonResponse ([], JsonResponse:: HTTP_NO_CONTENT );
10194 }
10295}
0 commit comments