Files
hotel_api/src/rooms/extractor.rs
Romain Mallard e5a1d36654
Some checks failed
Deploy API / build-and-deploy (push) Failing after 5s
rust fmt and some cleaning
2026-03-11 14:22:46 +01:00

38 lines
836 B
Rust

use axum::{
Json, Router,
body::Body,
extract::{FromRequest, Path, Request},
http::StatusCode,
};
use serde::Deserialize;
#[derive(Deserialize, Debug)]
pub struct UpdateRoomValues {
pub status: String,
}
pub struct UpdateRoomPayload(pub UpdateRoomValues);
//#[async_trait]
impl<S> FromRequest<S> for UpdateRoomPayload
where
S: Send + Sync,
{
type Rejection = (StatusCode, String);
async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection> {
let Json(payload) = Json::<UpdateRoomValues>::from_request(req, state)
.await
.map_err(|err| (StatusCode::BAD_REQUEST, format!("Invalid body: {}", err)))?;
Ok(UpdateRoomPayload(payload))
}
}
#[derive(Debug)]
pub struct RoomIdValue {
pub room_id: i32,
}
pub type RoomIdPath = Path<i32>;