Move location service to match other services

This commit is contained in:
Dane Everitt 2017-09-15 00:16:03 -05:00
parent a8560b720a
commit a498bbc7d5
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
14 changed files with 414 additions and 149 deletions

View file

@ -25,7 +25,6 @@
namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Models\Location;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Repositories\Concerns\Searchable;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
@ -47,25 +46,6 @@ class LocationRepository extends EloquentRepository implements LocationRepositor
return Location::class;
}
/**
* {@inheritdoc}
* @todo remove this, do logic in service
*/
public function deleteIfNoNodes($id)
{
$location = $this->getBuilder()->with('nodes')->find($id);
if (! $location) {
throw new RecordNotFoundException();
}
if ($location->nodes_count > 0) {
throw new DisplayException('Cannot delete a location that has nodes assigned to it.');
}
return $location->delete();
}
/**
* {@inheritdoc}
*/
@ -88,9 +68,21 @@ class LocationRepository extends EloquentRepository implements LocationRepositor
public function getWithNodes($id)
{
$instance = $this->getBuilder()->with('nodes.servers')->find($id, $this->getColumns());
if (! $instance) {
throw new RecordNotFoundException();
throw new RecordNotFoundException;
}
return $instance;
}
/**
* {@inheritdoc}
*/
public function getWithNodeCount($id)
{
$instance = $this->getBuilder()->withCount('nodes')->find($id, $this->getColumns());
if (! $instance) {
throw new RecordNotFoundException;
}
return $instance;