consolidated getLocation function

changed the function that retrieves a single location to decide what to
get based on the variable type, so it doesn't need to be two seperate
functions
This commit is contained in:
ro 2024-02-16 15:34:09 -06:00
parent 573054e7d8
commit 1382976549
3 changed files with 13 additions and 7 deletions

View file

@ -20,7 +20,7 @@ class AppServiceProvider extends ServiceProvider
});
$this->app->bind(UpdateService::class, function ($app) {
return new UpdateService(new Location());
return new UpdateService(new LocationRepository(new Location()));
});
$this->app->bind(MaintenanceService::class, function ($app) {

View file

@ -34,9 +34,13 @@ class LocationRepository
return $results;
}
public function getLocation($uuid)
public function getLocation($type)
{
return $this->model::where("uuid", $uuid)->first();
if (!is_string($type) || (preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/', $type) !== 1)) {
return $this->model::where("url", $type)->first();
} else {
return $this->model::where("uuid", $type)->first();
}
}
public function getActiveLocations()

View file

@ -3,17 +3,19 @@
namespace App\Services;
use App\Models\Location;
use App\Repositories\LocationRepository;
use App\Models\Source;
use Ramsey\Uuid\Uuid;
class UpdateService
{
protected $model;
private $limit = 15;
protected $model;
protected $locationRepository;
public function __construct(Location $model)
public function __construct(LocationRepository $locationRepository)
{
$this->model = $model;
$this->locationRepository = $locationRepository;
}
public function locations()
@ -126,7 +128,7 @@ class UpdateService
//once the unified list is created, update current entries or create fresh ones
foreach ($unified as $item) {
$location = Location::where("url", $item['url'])->first();
$location = $this->locationRepository->getLocation($item['url']);
if ($location) {
++$duplicates;
//update block count for existing item