use elif_http_derive::{controller, get};
pub struct ElifRequest;
pub struct ElifResponse;
pub type HttpResult<T> = Result<T, Box<dyn std::error::Error>>;
pub struct HttpError;
#[derive(Debug)]
pub struct ParamError;
impl HttpError {
pub fn bad_request(_msg: String) -> Box<dyn std::error::Error> {
Box::new(std::io::Error::new(
std::io::ErrorKind::Other,
"bad request",
))
}
}
impl ElifResponse {
pub fn ok() -> Self {
Self
}
pub fn json<T>(&self, _data: &T) -> Result<Self, Box<dyn std::error::Error>> {
Ok(Self)
}
}
impl ElifRequest {
pub fn path_param_int(&self, _name: &str) -> Result<i32, ParamError> {
Ok(42)
}
pub fn path_param_string(&self, _name: &str) -> Result<String, ParamError> {
Ok("test".to_string())
}
}
#[controller("/api/users")]
pub struct UserController;
impl UserController {
#[get("/{id}")]
#[param(id: int)]
pub async fn show(&self, id: i32, req: ElifRequest) -> String {
let _ = req; format!("User ID: {}", id)
}
#[get("/{user_id}/posts/{post_id}")]
#[param(user_id: int)]
#[param(post_id: string)]
pub async fn get_user_post(&self, user_id: i32, post_id: String, req: ElifRequest) -> String {
let _ = req; format!("User: {}, Post: {}", user_id, post_id)
}
#[get("/health")]
pub async fn health(&self, _req: ElifRequest) -> String {
"OK".to_string()
}
}
#[cfg(test)]
mod tests {
#[test]
fn test_param_injection_compiles() {
assert!(true);
}
}
fn main() {
println!("Parameter injection test compilation successful");
}