Skip to content

Commit

Permalink
Merge pull request #18 from OpenPlaceGuide/integration
Browse files Browse the repository at this point in the history
Integration
  • Loading branch information
amenk authored Jul 23, 2024
2 parents 1bc2e83 + 0077d4f commit c3c12ab
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
25 changes: 25 additions & 0 deletions app/Http/Controllers/DetailRedirectController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class DetailRedirectController extends BaseController
{
public function node(string $osmId)
{
return redirect(route('osmPlace.en', ['osmId' => $osmId, 'osmTypeLetter' => 'n']));
}

public function way(string $osmId)
{
return redirect(route('osmPlace.en', ['osmId' => $osmId, 'osmTypeLetter' => 'w']));
}

public function relation(string $osmId)
{
return redirect(route('osmPlace.en', ['osmId' => $osmId, 'osmTypeLetter' => 'r']));
}
}
12 changes: 10 additions & 2 deletions app/Services/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,18 @@ public function getAreaInfo(string $areaSlug, bool $canEnrich = true)
}

public function listTypes(): array
{
$types = $this->listTypesIncludingFallback();
unset($types['~fallback_type']);
return $types;
}

public function listTypesIncludingFallback(): array
{
return Cache::remember('types', function() {
return $this->listTypesUncached();
});

}

private function listTypesUncached(): array
Expand All @@ -120,7 +128,7 @@ private function listTypesUncached(): array
$result = [];
foreach($typeFiles as $filename) {
$slug = basename(dirname($filename));
$result[] = $this->getTypeInfo($slug);
$result[$slug] = $this->getTypeInfo($slug);
}

return $result;
Expand All @@ -129,7 +137,7 @@ private function listTypesUncached(): array

public function resolveType(OsmInfo $osmInfo): ?PoiType
{
$types = $this->listTypes();
$types = $this->listTypesIncludingFallback();

// FIXME: sort by priority
foreach($types as $type)
Expand Down
8 changes: 8 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Http\Controllers\DetailRedirectController;
use Illuminate\Support\Facades\Route;

/*
Expand Down Expand Up @@ -39,3 +40,10 @@

Route::middleware(\App\Services\Cache::getCacheMiddleware())
->group(function() use ($routes) { $routes(config('app.locale')); });

Route::get('/detail/node/{osmId}', [DetailRedirectController::class, 'node'])
->where('osmId', '[0-9]*');
Route::get('/detail/way/{osmId}', [DetailRedirectController::class, 'way'])
->where('osmId', '[0-9]*');
Route::get('/detail/relation/{osmId}', [DetailRedirectController::class, 'relation'])
->where('osmId', '[0-9]*');

0 comments on commit c3c12ab

Please sign in to comment.