34 lines
949 B
Rust
Raw Normal View History

use axum::extract::Path;
2024-06-16 12:54:53 +02:00
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use crate::{load_html, router};
use crate::expressions::expression::Expression;
use crate::routing::error::{Error, ErrorKind};
use crate::routing::response::IsLegalResponse;
2024-06-17 12:18:53 +02:00
router!(
get "/" => index,
get "/openapi" => open_api,
get "/is-valid/:exp" => is_valid
2024-06-17 12:18:53 +02:00
);
async fn index() -> &'static str {
"Welcome to the Simplify Truths API!\n"
}
2024-06-16 01:24:29 +02:00
async fn open_api() -> Response {
load_html!("openapi.html").into_response()
}
async fn is_valid(Path(path): Path<String>) -> Response {
match Expression::try_from(path.as_str()) {
Ok(_) => IsLegalResponse { is_legal: true }.into_response(),
Err(error) => Error::new(error.to_string(), ErrorKind::InvalidExpression).into_response()
}
}
2024-06-16 01:24:29 +02:00
pub(crate) async fn not_found() -> Response {
(StatusCode::NOT_FOUND, load_html!("not-found.html")).into_response()
2024-06-16 01:24:29 +02:00
}