Is legal endpoint to check if expression is legal.
Moved endpoints to own dir
This commit is contained in:
@ -6,7 +6,7 @@ use tower_http::trace;
|
||||
use tower_http::trace::TraceLayer;
|
||||
use tracing::Level;
|
||||
|
||||
use crate::routing::{index, simplify, table};
|
||||
use crate::routing::routes::*;
|
||||
|
||||
mod expressions;
|
||||
mod parsing;
|
||||
@ -28,7 +28,8 @@ async fn main() {
|
||||
|
||||
let routes = simplify::router()
|
||||
.merge(table::router())
|
||||
.merge(index::router());
|
||||
.merge(index::router())
|
||||
.merge(util::router());
|
||||
|
||||
let app = routes
|
||||
.layer(CorsLayer::new().allow_origin(Any))
|
||||
|
@ -1,5 +1,3 @@
|
||||
pub(crate) mod simplify;
|
||||
pub(crate) mod table;
|
||||
pub(crate) mod index;
|
||||
pub(crate) mod response;
|
||||
mod error;
|
||||
mod error;
|
||||
pub(crate) mod routes;
|
@ -1,6 +1,6 @@
|
||||
use axum::Json;
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::expressions::expression::Expression;
|
||||
use crate::expressions::simplify::Law;
|
||||
@ -60,4 +60,16 @@ impl IntoResponse for SimplifyResponse {
|
||||
fn into_response(self) -> Response {
|
||||
BaseResponse::create(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct IsLegalResponse {
|
||||
pub is_legal: bool,
|
||||
}
|
||||
|
||||
impl IntoResponse for IsLegalResponse {
|
||||
fn into_response(self) -> Response {
|
||||
BaseResponse::create(self)
|
||||
}
|
||||
}
|
7
src/routing/routes/mod.rs
Normal file
7
src/routing/routes/mod.rs
Normal file
@ -0,0 +1,7 @@
|
||||
pub(crate) mod index;
|
||||
|
||||
pub(crate) mod simplify;
|
||||
|
||||
pub(crate) mod table;
|
||||
|
||||
pub(crate) mod util;
|
@ -1,3 +1,4 @@
|
||||
use axum::body::Body;
|
||||
use axum::response::Response;
|
||||
use axum::Router;
|
||||
use axum::routing::post;
|
||||
@ -9,6 +10,7 @@ pub fn router() -> Router<()> {
|
||||
)
|
||||
}
|
||||
|
||||
async fn table() -> Response {
|
||||
// TODO Json Deserialize not working on Axum? Manually parse the body?
|
||||
async fn table(body: Body) -> Response {
|
||||
unimplemented!()
|
||||
}
|
20
src/routing/routes/util.rs
Normal file
20
src/routing/routes/util.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use axum::extract::Path;
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use axum::Router;
|
||||
use axum::routing::get;
|
||||
|
||||
use crate::expressions::expression::Expression;
|
||||
use crate::routing::error::{Error, ErrorKind};
|
||||
use crate::routing::response::IsLegalResponse;
|
||||
|
||||
pub fn router() -> Router<()> {
|
||||
Router::new()
|
||||
.route("/is-legal/:exp", get(is_legal))
|
||||
}
|
||||
|
||||
async fn is_legal(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()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user