From f1a809c5d2e0efae410a71f8da359543e439432a Mon Sep 17 00:00:00 2001 From: Arnaud Mimart <33665250+amimart@users.noreply.github.com> Date: Wed, 21 Feb 2024 23:27:24 +0100 Subject: [PATCH] feat(logic-bindings): make Answer match logic module format --- packages/okp4-logic-bindings/src/lib.rs | 2 +- packages/okp4-logic-bindings/src/query.rs | 24 +++++++++-------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/packages/okp4-logic-bindings/src/lib.rs b/packages/okp4-logic-bindings/src/lib.rs index 0c578597..28117b26 100644 --- a/packages/okp4-logic-bindings/src/lib.rs +++ b/packages/okp4-logic-bindings/src/lib.rs @@ -3,7 +3,7 @@ mod query; mod term_parser; pub mod uri; -pub use query::{Answer, AskResponse, LogicCustomQuery, Result, Substitution, Term}; +pub use query::{Answer, AskResponse, LogicCustomQuery, Result, Substitution}; pub use term_parser::TermValue; // Exposed for testing only diff --git a/packages/okp4-logic-bindings/src/query.rs b/packages/okp4-logic-bindings/src/query.rs index b271cbfd..b678e984 100644 --- a/packages/okp4-logic-bindings/src/query.rs +++ b/packages/okp4-logic-bindings/src/query.rs @@ -24,6 +24,7 @@ pub struct AskResponse { #[serde(rename_all = "snake_case")] pub struct Answer { pub success: bool, + pub error: Option, pub has_more: bool, pub variables: Vec, pub results: Vec, @@ -39,19 +40,12 @@ pub struct Result { #[serde(rename_all = "snake_case")] pub struct Substitution { pub variable: String, - pub term: Term, + pub expression: String, } -#[derive(Serialize, Deserialize, Default, Clone, PartialEq, Eq, JsonSchema, Debug)] -#[serde(rename_all = "snake_case")] -pub struct Term { - pub name: String, - pub arguments: Vec, -} - -impl Term { - pub fn parse(self) -> std::result::Result { - from_str(self.name.as_str()) +impl Substitution { + pub fn parse_expression(self) -> std::result::Result { + from_str(self.expression.as_str()) } } @@ -62,11 +56,11 @@ mod tests { #[test] fn term_parse() { assert_eq!( - Term { - name: "'hello'".to_string(), - arguments: vec![], + Substitution { + variable: "X".to_string(), + expression: "'hello'".to_string(), } - .parse(), + .parse_expression(), Ok(TermValue::Value("hello".to_string())) ); }