more docs
This commit is contained in:
		| @@ -5,12 +5,17 @@ use time::{format_description, OffsetDateTime}; | ||||
|  | ||||
| use crate::{law::parser::OgdSearchResult, Error}; | ||||
|  | ||||
| /// Returns the current date in YYYY-MM-DD format. Needed for RIS API query to get current version of the law. | ||||
| fn current_date() -> String { | ||||
|     let local_date = OffsetDateTime::now_utc(); | ||||
|     let format = format_description::parse("[year]-[month]-[day]").unwrap(); //OK | ||||
|     let format = format_description::parse("[year]-[month]-[day]").unwrap(); //unwrap okay, supplied format is fine | ||||
|     local_date.format(&format).expect("Failed to format date") | ||||
| } | ||||
|  | ||||
| /// Fetches the json content of the given law (`law_id`) from the RIS API. | ||||
| ///  | ||||
| /// # Errors | ||||
| /// Fails if `ureq` can't create a connection, probably because there's no internet connection? (Or RIS is not online.) | ||||
| fn fetch_page(law_id: usize) -> Result<String, Error> { | ||||
|     Ok( | ||||
|         ureq::post("https://data.bka.gv.at/ris/api/v2.6/Bundesrecht") | ||||
|   | ||||
| @@ -2,19 +2,6 @@ use std::collections::HashMap; | ||||
|  | ||||
| use serde::Deserialize; | ||||
|  | ||||
| #[derive(Deserialize)] | ||||
| pub(crate) struct Hits { | ||||
|     #[serde( | ||||
|         rename = "@pageNumber", | ||||
|         deserialize_with = "deserialize_string_to_usize" | ||||
|     )] | ||||
|     page_number: usize, | ||||
|     #[serde(rename = "@pageSize", deserialize_with = "deserialize_string_to_usize")] | ||||
|     page_size: usize, | ||||
|     #[serde(rename = "#text", deserialize_with = "deserialize_string_to_usize")] | ||||
|     text: usize, | ||||
| } | ||||
|  | ||||
| fn deserialize_string_to_usize<'de, D>(deserializer: D) -> Result<usize, D::Error> | ||||
| where | ||||
|     D: serde::Deserializer<'de>, | ||||
| @@ -42,6 +29,19 @@ pub(crate) struct OgdDocumentResults { | ||||
|     ogd_document_reference: Vec<OgdDocumentReference>, | ||||
| } | ||||
|  | ||||
| #[derive(Deserialize)] | ||||
| pub(crate) struct Hits { | ||||
|     #[serde( | ||||
|         rename = "@pageNumber", | ||||
|         deserialize_with = "deserialize_string_to_usize" | ||||
|     )] | ||||
|     page_number: usize, | ||||
|     #[serde(rename = "@pageSize", deserialize_with = "deserialize_string_to_usize")] | ||||
|     page_size: usize, | ||||
|     #[serde(rename = "#text", deserialize_with = "deserialize_string_to_usize")] | ||||
|     text: usize, | ||||
| } | ||||
|  | ||||
| #[derive(Deserialize)] | ||||
| #[serde(rename_all = "PascalCase")] | ||||
| pub(crate) struct OgdDocumentReference { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user