日本API
このコミットが含まれているのは:
コミット
799af8ba2a
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use App\Http\Controllers\AuthController;
|
||||
|
||||
class NihonController extends Controller {
|
||||
public function __construct() {}
|
||||
|
||||
public function getGeoRegion () {
|
||||
$get = DB::table('nhn_region')->get();
|
||||
|
||||
foreach ($get as $g) {
|
||||
$i = DB::table('nhn_island')->where('id', $g->island_id)->first();
|
||||
$g->island = $i;
|
||||
|
||||
unset($i->id); unset($g->island_id);
|
||||
}
|
||||
|
||||
return $get;
|
||||
}
|
||||
|
||||
public function getGeoPrefecture () {
|
||||
$get = DB::table('nhn_prefecture')->get();
|
||||
|
||||
foreach ($get as $g) {
|
||||
$r = DB::table('nhn_region')->where('id', $g->region_id)->first();
|
||||
$i = DB::table('nhn_island')->where('id', $r->island_id)->first();
|
||||
|
||||
$g->prefcode = 'JP-'.sprintf("%02d", $g->id);
|
||||
$g->region = $r;
|
||||
$g->island = $i;
|
||||
|
||||
unset($r->id); unset($i->id);
|
||||
unset($g->region_id); unset($r->island_id);
|
||||
}
|
||||
|
||||
return $get;
|
||||
}
|
||||
|
||||
public function getGeoIsland () {
|
||||
$get = DB::table('nhn_island')->get();
|
||||
return $get;
|
||||
}
|
||||
|
||||
public function getGeoCity ($id) {
|
||||
$get = DB::table('nhn_city')->where('prefecture_id', $id)->get();
|
||||
|
||||
foreach ($get as $g) {
|
||||
$p = DB::table('nhn_prefecture')->where('id', $g->prefecture_id)->first();
|
||||
$r = DB::table('nhn_region')->where('id', $p->region_id)->first();
|
||||
$i = DB::table('nhn_island')->where('id', $r->island_id)->first();
|
||||
|
||||
$dc = DB::table('nhn_city_district')->where('city_id', $g->id)->count();
|
||||
|
||||
if ($dc > 0) {
|
||||
$district = DB::table('nhn_city_district')->where('city_id', $g->id)->get();
|
||||
foreach ($district as $d) { unset($d->id); unset($d->city_id); }
|
||||
$g->district = $district;
|
||||
}
|
||||
|
||||
$g->prefecture = $p;
|
||||
$g->region = $r;
|
||||
$g->island = $i;
|
||||
|
||||
unset($p->id); unset($r->id); unset($i->id);
|
||||
unset($g->prefecture_id); unset($p->region_id); unset($r->island_id);
|
||||
}
|
||||
|
||||
return $get;
|
||||
}
|
||||
|
||||
public function getGeoDistrict ($id) {
|
||||
$get = DB::table('nhn_city_district')->where('city_id', $id)->get();
|
||||
foreach ($get as $g) { unset($g->city_id); }
|
||||
return $get;
|
||||
}
|
||||
|
||||
public function getRailCompany () {
|
||||
$get = DB::table('nhn_company')->get();
|
||||
foreach ($get as $g) { unset($g->id); }
|
||||
|
||||
return $get;
|
||||
}
|
||||
|
||||
public function getRailLine () {
|
||||
$get = DB::table('nhn_line')->get();
|
||||
|
||||
return $get;
|
||||
}
|
||||
|
||||
public function getRailStation () {
|
||||
$get = DB::table('nhn_station')->get();
|
||||
|
||||
return $get;
|
||||
}
|
||||
|
||||
public function getHistoryPeriod () {
|
||||
$get = DB::table('nhn_jidai')->get();
|
||||
|
||||
foreach ($get as $g) {
|
||||
$g->current = ($g->current == 1 ?? false);
|
||||
$g->years = ($g->years != 999 ?: '現在');
|
||||
$g->finish_date = ($g->finish_date != '2099-12-31' ?: '未定');
|
||||
|
||||
unset($g->id);
|
||||
}
|
||||
|
||||
return $get;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
Route::get('/api/rpc/japan/geo/region', 'NihonController@getGeoRegion');
|
||||
Route::get('/api/rpc/japan/geo/prefecture', 'NihonController@getGeoPrefecture');
|
||||
Route::get('/api/rpc/japan/geo/island', 'NihonController@getGeoIsland');
|
||||
Route::get('/api/rpc/japan/geo/city/{id}', 'NihonController@getGeoCity');
|
||||
Route::get('/api/rpc/japan/geo/district/{id}', 'NihonController@getGeoDistrict');
|
||||
Route::get('/api/rpc/japan/rail/company', 'NihonController@getRailCompany');
|
||||
Route::get('/api/rpc/japan/rail/line', 'NihonController@getRailLine');
|
||||
Route::get('/api/rpc/japan/rail/station', 'NihonController@getRailStation');
|
||||
Route::get('/api/rpc/japan/history/period', 'NihonController@getHistoryPeriod');
|
|
@ -15,6 +15,7 @@ require(__DIR__.'/api/bash.php');
|
|||
require(__DIR__.'/api/board.php');
|
||||
require(__DIR__.'/api/image.php');
|
||||
require(__DIR__.'/api/invoice.php');
|
||||
require(__DIR__.'/api/nihon.php');
|
||||
require(__DIR__.'/api/pack.php');
|
||||
require(__DIR__.'/api/site.php');
|
||||
require(__DIR__.'/api/store.php');
|
||||
|
|
新しいイシューから参照