Skip to content
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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ serde.workspace = true
reqwest = { version = "0.12.5", default-features = false, features = ["json", "rustls-tls"] }
js-sys = "0.3.67"
thiserror = "1.0.63"
jisx0401 = "0.1.0-beta.2"

[dev-dependencies]
tokio.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions core/src/domain/chimei_ruiju/entity.rs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [clippy] reported by reviewdog 🐶

warning: fields `name`, `cities`, and `coordinate` are never read
  --> core/src/domain/chimei_ruiju/entity.rs:6:16
   |
4  | pub struct PrefectureMaster {
   |            ---------------- fields in this struct
5  |     /// 都道府県名
6  |     pub(crate) name: String,
   |                ^^^^
7  |     /// 市区町村名リスト
8  |     pub(crate) cities: Vec,
   |                ^^^^^^
9  |     /// 代表点の緯度経度
10 |     pub(crate) coordinate: Coordinate,
   |                ^^^^^^^^^^
   |
   = note: `PrefectureMaster` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
   = note: `#[warn(dead_code)]` on by default

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [clippy] reported by reviewdog 🐶

warning: fields `koaza`, `block_number`, `residential_address_indication`, and `coordinate` are never read
  --> core/src/domain/chimei_ruiju/entity.rs:36:5
   |
34 | pub struct Block {
   |            ----- fields in this struct
35 |     /// 小字・通称名
36 |     koaza: String,
   |     ^^^^^
37 |     /// 街区符号・地番
38 |     block_number: String,
   |     ^^^^^^^^^^^^
39 |     /// 住居表示の有無
40 |     residential_address_indication: bool,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
41 |     /// 緯度経度
42 |     coordinate: Coordinate,
   |     ^^^^^^^^^^
   |
   = note: `Block` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [clippy] reported by reviewdog 🐶

warning: fields `latitude` and `longitude` are never read
  --> core/src/domain/chimei_ruiju/entity.rs:48:16
   |
46 | pub struct Coordinate {
   |            ---------- fields in this struct
47 |     /// 緯度
48 |     pub(crate) latitude: f64,
   |                ^^^^^^^^
49 |     /// 経度
50 |     pub(crate) longitude: f64,
   |                ^^^^^^^^^
   |
   = note: `Coordinate` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis

Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ pub struct PrefectureMaster {
#[derive(Deserialize, Debug)]
pub struct CityMaster {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [clippy] reported by reviewdog 🐶

warning: fields `name`, `towns`, and `coordinate` are never read
  --> core/src/domain/chimei_ruiju/entity.rs:16:16
   |
14 | pub struct CityMaster {
   |            ---------- fields in this struct
15 |     /// 市区町村名
16 |     pub(crate) name: String,
   |                ^^^^
17 |     /// 町名リスト
18 |     pub(crate) towns: Vec,
   |                ^^^^^
19 |     /// 緯度経度
20 |     coordinate: Coordinate,
   |     ^^^^^^^^^^
   |
   = note: `CityMaster` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis

Copy link
Owner Author

Choose a reason for hiding this comment

The 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [clippy] reported by reviewdog 🐶

warning: fields `name`, `blocks`, and `coordinate` are never read
  --> core/src/domain/chimei_ruiju/entity.rs:26:16
   |
24 | pub struct TownMaster {
   |            ---------- fields in this struct
25 |     /// 町名
26 |     pub(crate) name: String,
   |                ^^^^
27 |     /// 街区リスト
28 |     blocks: Vec,
   |     ^^^^^^
29 |     /// 緯度経度
30 |     coordinate: Coordinate,
   |     ^^^^^^^^^^
   |
   = note: `TownMaster` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

現時点で使用箇所がないのは問題ない

/// 町名
name: String,
pub(crate) name: String,
/// 街区リスト
blocks: Vec<Block>,
/// 緯度経度
Expand Down
1 change: 1 addition & 0 deletions core/src/repository.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod chimei_ruiju;
pub mod geolonia;
3 changes: 3 additions & 0 deletions core/src/repository/chimei_ruiju.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod city;
pub mod prefecture;
mod town;
138 changes: 138 additions & 0 deletions core/src/repository/chimei_ruiju/city.rs
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [clippy] reported by reviewdog 🐶

warning: struct `CityMasterRepository` is never constructed
 --> core/src/repository/chimei_ruiju/city.rs:6:12
  |
6 | pub struct CityMasterRepository {
  |            ^^^^^^^^^^^^^^^^^^^^

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

現時点で使用箇所がないのは問題ない

api_service: ChimeiRuijuApiService,
}

impl CityMasterRepository {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [clippy] reported by reviewdog 🐶

warning: method `get` is never used
  --> core/src/repository/chimei_ruiju/city.rs:11:18
   |
10 | impl CityMasterRepository {
   | ------------------------- method in this implementation
11 |     pub async fn get(
   |                  ^^^

Copy link
Owner Author

Choose a reason for hiding this comment

The 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [clippy] reported by reviewdog 🐶

warning: method `get_blocking` is never used
  --> core/src/repository/chimei_ruiju/city.rs:58:12
   |
57 | impl CityMasterRepository {
   | ------------------------- method in this implementation
58 |     pub fn get_blocking(
   |            ^^^^^^^^^^^^

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![
"大字今須",
"大字大高",
"大字関ケ原",
"大字玉",
"大字藤下",
"大字野上",
"大字松尾",
"大字山中"
]
);
}
}
Loading
Loading