More API updates, better support for node config edits

This commit is contained in:
Dane Everitt 2018-01-10 23:19:03 -06:00
parent 800e2df6b2
commit cf21fd5a4b
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
21 changed files with 449 additions and 125 deletions

View file

@ -2,8 +2,10 @@
namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Models\Node;
use Illuminate\Support\Collection;
use Pterodactyl\Models\Allocation;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
class AllocationRepository extends EloquentRepository implements AllocationRepositoryInterface
@ -41,6 +43,18 @@ class AllocationRepository extends EloquentRepository implements AllocationRepos
return $this->getBuilder()->where('node_id', $node)->get($this->getColumns());
}
/**
* Return all of the allocations for a node in a paginated format.
*
* @param int $node
* @param int $perPage
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
public function getPaginatedAllocationsForNode(int $node, int $perPage = 100): LengthAwarePaginator
{
return $this->getBuilder()->where('node_id', $node)->paginate($perPage, $this->getColumns());
}
/**
* Return all of the unique IPs that exist for a given node.
*

View file

@ -7,6 +7,7 @@ use Illuminate\Support\Collection;
use Pterodactyl\Repositories\Repository;
use Illuminate\Database\Query\Expression;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Pterodactyl\Contracts\Repository\RepositoryInterface;
use Pterodactyl\Exceptions\Model\DataValidationException;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
@ -234,6 +235,22 @@ abstract class EloquentRepository extends Repository implements RepositoryInterf
return $instance->get($this->getColumns());
}
/**
* Return a paginated result set using a search term if set on the repository.
*
* @param int $perPage
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
public function paginated(int $perPage): LengthAwarePaginator
{
$instance = $this->getBuilder();
if (is_subclass_of(get_called_class(), SearchableInterface::class) && $this->hasSearchTerm()) {
$instance = $instance->search($this->getSearchTerm());
}
return $instance->paginate($perPage, $this->getColumns());
}
/**
* Insert a single or multiple records into the database at once skipping
* validation and mass assignment checking.