2024-06-20 13:13:26 +02:00
|
|
|
use axum::extract::Path;
|
2024-06-16 12:54:53 +02:00
|
|
|
use axum::http::StatusCode;
|
2024-06-20 13:13:26 +02:00
|
|
|
use axum::response::{IntoResponse, Response};
|
2024-06-13 14:42:42 +02:00
|
|
|
|
2024-06-20 18:00:12 +02:00
|
|
|
use crate::{load_html, router};
|
2024-06-20 13:13:26 +02:00
|
|
|
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,
|
2024-06-20 13:13:26 +02:00
|
|
|
get "/openapi" => open_api,
|
|
|
|
get "/is-valid/:exp" => is_valid
|
2024-06-17 12:18:53 +02:00
|
|
|
);
|
2024-06-13 14:42:42 +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 {
|
2024-06-20 18:00:12 +02:00
|
|
|
load_html!("openapi.html").into_response()
|
2024-06-20 13:13:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2024-06-20 13:13:26 +02:00
|
|
|
pub(crate) async fn not_found() -> Response {
|
2024-06-20 18:00:12 +02:00
|
|
|
(StatusCode::NOT_FOUND, load_html!("not-found.html")).into_response()
|
2024-06-16 01:24:29 +02:00
|
|
|
}
|