diff --git a/app/DotsAPI/API/v2/AbstractItemAPI.php b/app/DotsAPI/API/v2/AbstractItemAPI.php new file mode 100644 index 0000000..7119614 --- /dev/null +++ b/app/DotsAPI/API/v2/AbstractItemAPI.php @@ -0,0 +1,20 @@ +fetcher = $fetcher; + } + + abstract public function getMap($context = null); + + abstract public function saveMap($map); +} + diff --git a/app/DotsAPI/API/v2/CityAPI.php b/app/DotsAPI/API/v2/CityAPI.php new file mode 100644 index 0000000..0e7f6e5 --- /dev/null +++ b/app/DotsAPI/API/v2/CityAPI.php @@ -0,0 +1,32 @@ +fetcher->get($endpoint); + + return $citiesMap; + } + + public function saveMap($cities) { + foreach ($cities as $city) { + $uuid = $city['id']; + $name = $city['name']; + $url = $city['url']; + + City::firstOrCreate([ + 'uuid' => $uuid, + 'name' => $name, + 'url' => $url + ]); + } + } +} + diff --git a/app/DotsAPI/API/v2/CompanyAPI.php b/app/DotsAPI/API/v2/CompanyAPI.php new file mode 100644 index 0000000..5feb350 --- /dev/null +++ b/app/DotsAPI/API/v2/CompanyAPI.php @@ -0,0 +1,33 @@ +fetcher->get($endpoint); + + return $companiesMap; + } + + public function saveMap($companies) { + foreach ($companies as $company) { + $uuid = $company['id']; + $name = $company['name']; + $image = $company['image'] ?? ''; + $description = $company['description'] ?? ''; + + Company::firstOrCreate([ + 'uuid' => $uuid, + 'name' => $name, + 'image' => $image, + 'description' => $description, + ]); + } + } +}