From 138297654971fecdd363d26b9a45c19b0062b61d Mon Sep 17 00:00:00 2001 From: ro Date: Fri, 16 Feb 2024 15:34:09 -0600 Subject: [PATCH] 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 --- app/Providers/AppServiceProvider.php | 2 +- app/Repositories/LocationRepository.php | 8 ++++++-- app/Services/UpdateService.php | 10 ++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 6e4f77f..3930631 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -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) { diff --git a/app/Repositories/LocationRepository.php b/app/Repositories/LocationRepository.php index 6d846c3..8545691 100644 --- a/app/Repositories/LocationRepository.php +++ b/app/Repositories/LocationRepository.php @@ -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() diff --git a/app/Services/UpdateService.php b/app/Services/UpdateService.php index 3072753..5f93e7c 100644 --- a/app/Services/UpdateService.php +++ b/app/Services/UpdateService.php @@ -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