fmt. Removed some usage of macros
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
use axum::Json;
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use axum::Json;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize, Default)]
|
||||
|
@ -1,4 +1,4 @@
|
||||
pub(crate) mod response;
|
||||
pub(crate) mod error;
|
||||
pub(crate) mod options;
|
||||
pub(crate) mod response;
|
||||
pub(crate) mod routes;
|
||||
pub(crate) mod options;
|
@ -1,15 +1,12 @@
|
||||
use serde::Deserialize;
|
||||
use crate::expressions::truth_table::{Hide, Sort};
|
||||
use crate::utils::serialize::{ret_true, deserialize_bool};
|
||||
use crate::utils::serialize::{deserialize_bool, ret_true};
|
||||
use serde::Deserialize;
|
||||
|
||||
// TODO deserialize_bool should not be necessary
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SimplifyOptions {
|
||||
#[serde(
|
||||
default = "ret_true",
|
||||
deserialize_with = "deserialize_bool"
|
||||
)]
|
||||
#[serde(default = "ret_true", deserialize_with = "deserialize_bool")]
|
||||
pub simplify: bool,
|
||||
#[serde(default, deserialize_with = "deserialize_bool")]
|
||||
pub ignore_case: bool,
|
||||
|
@ -1,7 +1,7 @@
|
||||
use axum::extract::Path;
|
||||
use axum::http::StatusCode;
|
||||
use axum::Json;
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use axum::Json;
|
||||
use lib::router;
|
||||
use serde::Serialize;
|
||||
|
||||
@ -40,7 +40,7 @@ async fn open_api() -> impl IntoResponse {
|
||||
async fn is_valid(Path(path): Path<String>) -> Response {
|
||||
match Expression::try_from(path.as_str()) {
|
||||
Ok(_) => IsValidResponse::valid().into_response(),
|
||||
Err(error) => Error::new(error.to_string(), ErrorKind::InvalidExpression).into_response()
|
||||
Err(error) => Error::new(error.to_string(), ErrorKind::InvalidExpression).into_response(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
pub(crate) mod index;
|
||||
|
||||
pub(crate) mod simplify;
|
||||
|
||||
pub(crate) mod table;
|
||||
|
@ -9,10 +9,13 @@ use crate::routing::error::{Error, ErrorKind};
|
||||
use crate::routing::options::{SimplifyAndTableOptions, SimplifyOptions};
|
||||
use crate::routing::response::SimplifyResponse;
|
||||
|
||||
router!("/simplify", routes!(
|
||||
get "/:exp" => simplify,
|
||||
get "/table/:exp" => simplify_and_table
|
||||
));
|
||||
router!(
|
||||
"/simplify",
|
||||
routes!(
|
||||
get "/:exp" => simplify,
|
||||
get "/table/:exp" => simplify_and_table
|
||||
)
|
||||
);
|
||||
|
||||
async fn simplify(Path(path): Path<String>, Query(query): Query<SimplifyOptions>) -> Response {
|
||||
match Expression::try_from(path.as_str()) {
|
||||
@ -28,15 +31,21 @@ async fn simplify(Path(path): Path<String>, Query(query): Query<SimplifyOptions>
|
||||
operations,
|
||||
expression,
|
||||
truth_table: None,
|
||||
}.into_response()
|
||||
}
|
||||
Err(error) => {
|
||||
(StatusCode::BAD_REQUEST, Error::new(error.to_string(), ErrorKind::InvalidExpression)).into_response()
|
||||
}
|
||||
.into_response()
|
||||
}
|
||||
Err(error) => (
|
||||
StatusCode::BAD_REQUEST,
|
||||
Error::new(error.to_string(), ErrorKind::InvalidExpression),
|
||||
)
|
||||
.into_response(),
|
||||
}
|
||||
}
|
||||
|
||||
async fn simplify_and_table(Path(path): Path<String>, Query(query): Query<SimplifyAndTableOptions>) -> Response {
|
||||
async fn simplify_and_table(
|
||||
Path(path): Path<String>,
|
||||
Query(query): Query<SimplifyAndTableOptions>,
|
||||
) -> Response {
|
||||
match Expression::try_from(path.as_str()) {
|
||||
Ok(mut expression) => {
|
||||
let before = expression.to_string();
|
||||
@ -51,10 +60,13 @@ async fn simplify_and_table(Path(path): Path<String>, Query(query): Query<Simpli
|
||||
operations,
|
||||
expression,
|
||||
truth_table: Some(truth_table),
|
||||
}.into_response()
|
||||
}
|
||||
Err(error) => {
|
||||
(StatusCode::BAD_REQUEST, Error::new(error.to_string(), ErrorKind::InvalidExpression)).into_response()
|
||||
}
|
||||
.into_response()
|
||||
}
|
||||
Err(error) => (
|
||||
StatusCode::BAD_REQUEST,
|
||||
Error::new(error.to_string(), ErrorKind::InvalidExpression),
|
||||
)
|
||||
.into_response(),
|
||||
}
|
||||
}
|
||||
|
@ -9,16 +9,24 @@ use crate::routing::error::{Error, ErrorKind};
|
||||
use crate::routing::options::TruthTableOptions;
|
||||
use crate::routing::response::TruthTableResponse;
|
||||
|
||||
router!("/table", routes!(
|
||||
get "/:exp" => table
|
||||
));
|
||||
router!(
|
||||
"/table",
|
||||
routes!(
|
||||
get "/:exp" => table
|
||||
)
|
||||
);
|
||||
|
||||
// TODO Expression as input in body
|
||||
async fn table(Path(value): Path<String>, Query(query): Query<TruthTableOptions>) -> Response {
|
||||
match Expression::try_from(value) {
|
||||
Ok(expression) => {
|
||||
TruthTableResponse { truth_table: TruthTable::new(&expression, query) }.into_response()
|
||||
Ok(expression) => TruthTableResponse {
|
||||
truth_table: TruthTable::new(&expression, query),
|
||||
}
|
||||
Err(e) => (StatusCode::BAD_REQUEST, Error::new(e.to_string(), ErrorKind::InvalidExpression)).into_response(),
|
||||
.into_response(),
|
||||
Err(e) => (
|
||||
StatusCode::BAD_REQUEST,
|
||||
Error::new(e.to_string(), ErrorKind::InvalidExpression),
|
||||
)
|
||||
.into_response(),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user