more docs

This commit is contained in:
philipp 2023-11-04 00:22:57 +01:00
parent fd47a62c60
commit 62b0e1e69d
2 changed files with 19 additions and 14 deletions

View File

@ -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")

View File

@ -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 {