diff --git a/crates/oswilno-parking-space/src/lib.rs b/crates/oswilno-parking-space/src/lib.rs index e9d6dfe..03d18b7 100644 --- a/crates/oswilno-parking-space/src/lib.rs +++ b/crates/oswilno-parking-space/src/lib.rs @@ -28,6 +28,9 @@ pub fn mount(config: &mut ServiceConfig) { config.service(root).service( scope("/parking-spaces") .service(parking_space_rent_form) + .service(parking_space_rent_edit) + .service(parking_space_rent_create) + .service(parking_space_rent_update) .service(form_show) .service(all_parking_spaces) .service(create) @@ -459,6 +462,7 @@ async fn update( struct ParkingSpaceRentForm { pub id: Option, pub price: Option, + pub price_f: Option, } #[derive(Debug, Template)] @@ -557,11 +561,39 @@ async fn parking_space_rent_form( async fn parking_space_rent_edit(_id: Path) -> HttpResponse { todo!() } -#[post("/parking-space-rents/create")] -async fn parking_space_rent_create(_form: Form) -> HttpResponse { +#[post("/{parking_space_id}/parking-space-rents/create")] +async fn parking_space_rent_create(form: Form) -> HttpResponse { + let mut form = form.into_inner(); + form.price = form.price_f.map(|n| n * 100.0).map(|n| n as i32); todo!() } -#[put("/parking-space-rents/update")] -async fn parking_space_rent_update(_form: Form) -> HttpResponse { +#[put("/{parking_space_id}/parking-space-rents/update")] +async fn parking_space_rent_update(form: Form) -> HttpResponse { + let mut form = form.into_inner(); + form.price = form.price_f.map(|n| n * 100.0).map(|n| n as i32); todo!() } + +fn render_rent_form(form: ParkingSpaceRentForm, req: &HttpRequest) -> String { + let body = ParkingSpaceRentFormTemplate { + parking_space, + location, + form, + lang, + t: t.into_inner(), + }; + let main = Main { + body, + title: Blank, + opts: MainOpts { + show: true, + search: None, + session, + }, + }; + if is_partial(&req) { + main.render() + } else { + Layout { main }.render() + } +} diff --git a/crates/oswilno-parking-space/templates/parking-space-rents/form.html b/crates/oswilno-parking-space/templates/parking-space-rents/form.html index a7c2649..cfff142 100644 --- a/crates/oswilno-parking-space/templates/parking-space-rents/form.html +++ b/crates/oswilno-parking-space/templates/parking-space-rents/form.html @@ -6,12 +6,12 @@
+ > {% if let Some(id) = form.id %} {% endif %} @@ -22,39 +22,33 @@
- . - PLN
diff --git a/crates/oswilno-view/src/filters.rs b/crates/oswilno-view/src/filters.rs index e5c479d..e52d489 100644 --- a/crates/oswilno-view/src/filters.rs +++ b/crates/oswilno-view/src/filters.rs @@ -14,3 +14,9 @@ pub fn skip_if(n: &T, skip: T) -> Resul n.to_string() }) } + +#[tracing::instrument] +pub fn display_price(n: &&i32) -> Result { + let n: i32 = **n; + Ok(format!("{}.{}", n / 100, n % 100)) +}