-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chimei-ruiju.orgへの対応: repository
にchimei-ruiju用の構造体を定義
#428
Changes from all commits
616cdea
4fb79ed
9bdb92f
70195dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,17 +13,17 @@ pub struct PrefectureMaster { | |
#[derive(Deserialize, Debug)] | ||
pub struct CityMaster { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 現時点で使用箇所がないのは問題ない |
||
/// 市区町村名 | ||
name: String, | ||
pub(crate) name: String, | ||
/// 町名リスト | ||
towns: Vec<String>, | ||
pub(crate) towns: Vec<String>, | ||
/// 緯度経度 | ||
coordinate: Coordinate, | ||
} | ||
|
||
#[derive(Deserialize, Debug)] | ||
pub struct TownMaster { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 現時点で使用箇所がないのは問題ない |
||
/// 町名 | ||
name: String, | ||
pub(crate) name: String, | ||
/// 街区リスト | ||
blocks: Vec<Block>, | ||
/// 緯度経度 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod chimei_ruiju; | ||
pub mod geolonia; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod city; | ||
pub mod prefecture; | ||
mod town; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
use crate::domain::chimei_ruiju::entity::CityMaster; | ||
use crate::domain::chimei_ruiju::error::ApiError; | ||
use crate::service::chimei_ruiju::ChimeiRuijuApiService; | ||
use jisx0401::Prefecture; | ||
|
||
pub struct CityMasterRepository { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 現時点で使用箇所がないのは問題ない |
||
api_service: ChimeiRuijuApiService, | ||
} | ||
|
||
impl CityMasterRepository { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 現時点で使用箇所がないのは問題ない |
||
pub async fn get( | ||
&self, | ||
prefecture: &Prefecture, | ||
city_name: &str, | ||
) -> Result<CityMaster, ApiError> { | ||
let url = format!( | ||
"https://{}.chimei-ruiju.org/{}/master.json", | ||
prefecture.name_en(), | ||
city_name | ||
); | ||
self.api_service.get::<CityMaster>(&url).await | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod async_tests { | ||
use crate::repository::chimei_ruiju::city::CityMasterRepository; | ||
use crate::service::chimei_ruiju::ChimeiRuijuApiService; | ||
use jisx0401::Prefecture; | ||
|
||
#[tokio::test] | ||
async fn 神奈川県愛甲郡清川村() { | ||
let repository = CityMasterRepository { | ||
api_service: ChimeiRuijuApiService {}, | ||
}; | ||
let result = repository.get(&Prefecture::KANAGAWA, "愛甲郡清川村").await; | ||
assert!(result.is_ok()); | ||
let entity = result.unwrap(); | ||
assert_eq!(entity.name, "愛甲郡清川村"); | ||
assert_eq!(entity.towns, vec!["煤ヶ谷", "宮ヶ瀬"]); | ||
} | ||
|
||
#[tokio::test] | ||
async fn 京都府乙訓郡大山崎町() { | ||
let repository = CityMasterRepository { | ||
api_service: ChimeiRuijuApiService {}, | ||
}; | ||
let result = repository.get(&Prefecture::KYOTO, "乙訓郡大山崎町").await; | ||
assert!(result.is_ok()); | ||
let entity = result.unwrap(); | ||
assert_eq!(entity.name, "乙訓郡大山崎町"); | ||
assert_eq!(entity.towns, vec!["字円明寺", "字大山崎", "字下植野"]); | ||
} | ||
} | ||
|
||
#[cfg(feature = "blocking")] | ||
impl CityMasterRepository { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
pub fn get_blocking( | ||
&self, | ||
prefecture: &Prefecture, | ||
city_name: &str, | ||
) -> Result<CityMaster, ApiError> { | ||
let url = format!( | ||
"https://{}.chimei-ruiju.org/{}/master.json", | ||
prefecture.name_en(), | ||
city_name | ||
); | ||
self.api_service.get_blocking::<CityMaster>(&url) | ||
} | ||
} | ||
|
||
#[cfg(all(test, feature = "blocking"))] | ||
mod blocking_tests { | ||
use crate::repository::chimei_ruiju::city::CityMasterRepository; | ||
use crate::service::chimei_ruiju::ChimeiRuijuApiService; | ||
use jisx0401::Prefecture; | ||
|
||
#[test] | ||
fn 埼玉県比企郡嵐山町() { | ||
let repository = CityMasterRepository { | ||
api_service: ChimeiRuijuApiService {}, | ||
}; | ||
let result = repository.get_blocking(&Prefecture::SAITAMA, "比企郡嵐山町"); | ||
assert!(result.is_ok()); | ||
let entity = result.unwrap(); | ||
assert_eq!(entity.name, "比企郡嵐山町"); | ||
assert_eq!( | ||
entity.towns, | ||
vec![ | ||
"むさし台一丁目", | ||
"むさし台二丁目", | ||
"むさし台三丁目", | ||
"大字根岸", | ||
"大字勝田", | ||
"大字太郎丸", | ||
"大字川島", | ||
"花見台", | ||
"大字遠山", | ||
"大字大蔵", | ||
"大字菅谷", | ||
"大字千手堂", | ||
"大字廣野", | ||
"大字杉山", | ||
"大字平澤", | ||
"大字将軍澤", | ||
"大字志賀", | ||
"大字吉田", | ||
"大字古里", | ||
"大字越畑", | ||
"大字鎌形" | ||
] | ||
); | ||
} | ||
|
||
#[test] | ||
fn 岐阜県不破郡関ケ原町() { | ||
let repository = CityMasterRepository { | ||
api_service: ChimeiRuijuApiService {}, | ||
}; | ||
let result = repository.get_blocking(&Prefecture::GIFU, "不破郡関ケ原町"); | ||
assert!(result.is_ok()); | ||
let entity = result.unwrap(); | ||
assert_eq!(entity.name, "不破郡関ケ原町"); | ||
assert_eq!( | ||
entity.towns, | ||
vec![ | ||
"大字今須", | ||
"大字大高", | ||
"大字関ケ原", | ||
"大字玉", | ||
"大字藤下", | ||
"大字野上", | ||
"大字松尾", | ||
"大字山中" | ||
] | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
japanese-address-parser/core/src/domain/chimei_ruiju/entity.rs
Line 4 in 70195dc