Using library and removed common functions (#3)

* Added lib from git and removed code which is in lib now

* NormalizePathLayer to remove trailing slash
This commit is contained in:
Martin Berg Alstad
2024-06-22 17:33:33 +02:00
committed by GitHub
parent e7f1ae156d
commit 4b6608fd4f
20 changed files with 41 additions and 426 deletions

View File

@ -9,8 +9,6 @@ pub enum ErrorKind {
InvalidExpression,
/// The expression is too long.
LimitExceeded,
/// The expression is missing a character to be considered valid.
MissingCharacter,
/// Unexpected error.
#[default]
Unexpected,

View File

@ -1,34 +1,11 @@
use axum::Json;
use axum::response::{IntoResponse, Response};
use lib::derive::IntoResponse;
use serde::Serialize;
use derive::IntoResponse;
use crate::expressions::expression::Expression;
use crate::expressions::simplify::Law;
use crate::expressions::truth_table::TruthTable;
#[derive(Serialize)]
struct BaseResponse<T: Serialize> {
version: String,
#[serde(flatten)]
result: T,
}
impl<T: Serialize> BaseResponse<T> {
fn create(result: T) -> Response {
Self {
version: env!("CARGO_PKG_VERSION").to_string(),
result,
}.into_response()
}
}
impl<T: Serialize> IntoResponse for BaseResponse<T> {
fn into_response(self) -> Response {
Json(self).into_response()
}
}
#[derive(Debug, PartialEq, Serialize)]
pub struct Operation {
pub before: String,
@ -38,7 +15,7 @@ pub struct Operation {
impl Operation {
pub fn new(before: &Expression, after: &Expression, law: Law) -> Option<Self> {
if *before != *after {
if before != after {
Some(Self { before: before.to_string(), after: after.to_string(), law })
} else {
None
@ -67,9 +44,6 @@ impl IsValidResponse {
pub const fn valid() -> Self {
Self { is_valid: true }
}
pub const fn invalid() -> Self {
Self { is_valid: false }
}
}
#[derive(Serialize, IntoResponse)]

View File

@ -2,10 +2,11 @@ use axum::extract::Path;
use axum::http::StatusCode;
use axum::Json;
use axum::response::{IntoResponse, Response};
use lib::router;
use serde::Serialize;
use crate::{load_html, router};
use crate::expressions::expression::Expression;
use crate::load_html;
use crate::routing::error::{Error, ErrorKind};
use crate::routing::response::IsValidResponse;

View File

@ -1,10 +1,10 @@
use axum::extract::{Path, Query};
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use lib::{router, routes};
use crate::expressions::expression::Expression;
use crate::expressions::truth_table::TruthTable;
use crate::{router, routes};
use crate::routing::error::{Error, ErrorKind};
use crate::routing::options::{SimplifyAndTableOptions, SimplifyOptions};
use crate::routing::response::SimplifyResponse;

View File

@ -1,8 +1,8 @@
use axum::extract::{Path, Query};
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use lib::{router, routes};
use crate::{router, routes};
use crate::expressions::expression::Expression;
use crate::expressions::truth_table::TruthTable;
use crate::routing::error::{Error, ErrorKind};