diff --git a/cala-ledger/src/tx_template/entity.rs b/cala-ledger/src/tx_template/entity.rs index 89b0c8f7..d04ea3e7 100644 --- a/cala-ledger/src/tx_template/entity.rs +++ b/cala-ledger/src/tx_template/entity.rs @@ -372,7 +372,7 @@ mod tests { .code("CODE") .tx_input( NewTxInput::builder() - .effective("date('2022-11-01')") + .effective("DATE('2022-11-01')") .journal_id(format!("'{journal_id}'")) .build() .unwrap(), diff --git a/cala-server/src/graphql/convert.rs b/cala-server/src/graphql/convert.rs index 83925cf3..2b319b2b 100644 --- a/cala-server/src/graphql/convert.rs +++ b/cala-server/src/graphql/convert.rs @@ -174,14 +174,14 @@ impl From for ParamDefinition { impl From for ParamDataType { fn from(value: cala_ledger::tx_template::ParamDataType) -> Self { match value { - cala_ledger::tx_template::ParamDataType::STRING => ParamDataType::STRING, - cala_ledger::tx_template::ParamDataType::INTEGER => ParamDataType::INTEGER, - cala_ledger::tx_template::ParamDataType::DECIMAL => ParamDataType::DECIMAL, - cala_ledger::tx_template::ParamDataType::BOOLEAN => ParamDataType::BOOLEAN, - cala_ledger::tx_template::ParamDataType::UUID => ParamDataType::UUID, - cala_ledger::tx_template::ParamDataType::DATE => ParamDataType::DATE, - cala_ledger::tx_template::ParamDataType::TIMESTAMP => ParamDataType::TIMESTAMP, - cala_ledger::tx_template::ParamDataType::JSON => ParamDataType::JSON, + cala_ledger::tx_template::ParamDataType::STRING => ParamDataType::String, + cala_ledger::tx_template::ParamDataType::INTEGER => ParamDataType::Integer, + cala_ledger::tx_template::ParamDataType::DECIMAL => ParamDataType::Decimal, + cala_ledger::tx_template::ParamDataType::BOOLEAN => ParamDataType::Boolean, + cala_ledger::tx_template::ParamDataType::UUID => ParamDataType::Uuid, + cala_ledger::tx_template::ParamDataType::DATE => ParamDataType::Date, + cala_ledger::tx_template::ParamDataType::TIMESTAMP => ParamDataType::Timestamp, + cala_ledger::tx_template::ParamDataType::JSON => ParamDataType::Json, } } } @@ -189,14 +189,14 @@ impl From for ParamDataType { impl From for cala_ledger::tx_template::ParamDataType { fn from(value: ParamDataType) -> Self { match value { - ParamDataType::STRING => cala_ledger::tx_template::ParamDataType::STRING, - ParamDataType::INTEGER => cala_ledger::tx_template::ParamDataType::INTEGER, - ParamDataType::DECIMAL => cala_ledger::tx_template::ParamDataType::DECIMAL, - ParamDataType::BOOLEAN => cala_ledger::tx_template::ParamDataType::BOOLEAN, - ParamDataType::UUID => cala_ledger::tx_template::ParamDataType::UUID, - ParamDataType::DATE => cala_ledger::tx_template::ParamDataType::DATE, - ParamDataType::TIMESTAMP => cala_ledger::tx_template::ParamDataType::TIMESTAMP, - ParamDataType::JSON => cala_ledger::tx_template::ParamDataType::JSON, + ParamDataType::String => cala_ledger::tx_template::ParamDataType::STRING, + ParamDataType::Integer => cala_ledger::tx_template::ParamDataType::INTEGER, + ParamDataType::Decimal => cala_ledger::tx_template::ParamDataType::DECIMAL, + ParamDataType::Boolean => cala_ledger::tx_template::ParamDataType::BOOLEAN, + ParamDataType::Uuid => cala_ledger::tx_template::ParamDataType::UUID, + ParamDataType::Date => cala_ledger::tx_template::ParamDataType::DATE, + ParamDataType::Timestamp => cala_ledger::tx_template::ParamDataType::TIMESTAMP, + ParamDataType::Json => cala_ledger::tx_template::ParamDataType::JSON, } } } diff --git a/cala-server/src/graphql/tx_template.rs b/cala-server/src/graphql/tx_template.rs index 52ed3a14..be26dd51 100644 --- a/cala-server/src/graphql/tx_template.rs +++ b/cala-server/src/graphql/tx_template.rs @@ -1,5 +1,4 @@ use async_graphql::*; -use serde::{Deserialize, Serialize}; use super::primitives::*; @@ -23,16 +22,16 @@ pub(super) struct ParamDefinition { pub description: Option, } -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Enum, Copy)] +#[derive(Clone, Debug, PartialEq, Eq, Enum, Copy)] pub enum ParamDataType { - STRING, - INTEGER, - DECIMAL, - BOOLEAN, - UUID, - DATE, - TIMESTAMP, - JSON, + String, + Integer, + Decimal, + Boolean, + Uuid, + Date, + Timestamp, + Json, } #[derive(SimpleObject)] diff --git a/examples/rust/src/main.rs b/examples/rust/src/main.rs index 28389788..f3bd5325 100644 --- a/examples/rust/src/main.rs +++ b/examples/rust/src/main.rs @@ -1,7 +1,9 @@ use anyhow::Context; use std::fs; -use cala_ledger::{account::*, journal::*, migrate::IncludeMigrations, query::*, *}; +use cala_ledger::{ + account::*, journal::*, migrate::IncludeMigrations, query::*, tx_template::*, *, +}; pub fn store_server_pid(cala_home: &str, pid: u32) -> anyhow::Result<()> { create_cala_dir(cala_home)?; @@ -52,7 +54,46 @@ async fn main() -> anyhow::Result<()> { .description("description") .build()?; let journal = cala.journals().create(new_journal).await?; - println!("journal_id: {}", journal.id()); + let journal_id = journal.id(); + println!("journal_id: {}", journal_id); + + let tx_input = NewTxInput::builder() + .journal_id(format!("UUID('{}')", journal_id)) + .effective("DATE('2022-11-01')") + .build()?; + let entries = vec![ + NewEntryInput::builder() + .entry_type("'TEST_DR'") + .account_id("param.recipient") + .layer("'SETTLED'") + .direction("'DEBIT'") + .units("1290") + .currency("'BTC'") + .build() + .unwrap(), + NewEntryInput::builder() + .entry_type("'TEST_CR'") + .account_id("param.sender") + .layer("'SETTLED'") + .direction("'CREDIT'") + .units("1290") + .currency("'BTC'") + .build() + .unwrap(), + ]; + let tx_template_id = TxTemplateId::new(); + + let new_tx_template = NewTxTemplate::builder() + .id(tx_template_id) + .code("CODE") + .tx_input(tx_input) + .entries(entries) + .build() + .unwrap(); + let tx_template = cala.tx_templates().create(new_tx_template).await?; + println!("tx_template_id: {}", tx_template.id()); + let code = tx_template.into_values().code; + println!("tx_template_code: {}", code); loop { tokio::time::sleep(std::time::Duration::from_secs(5)).await;