Skip to content

Commit

Permalink
chore: postTransaction -> transactionPost (#137)
Browse files Browse the repository at this point in the history
* chore: postTransaction -> transactionPost

* docs: postTransaction -> transactionPost
  • Loading branch information
thevaibhav-dixit authored Jun 26, 2024
1 parent 9b99dfa commit 7a3c306
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion bats/account-set.bats
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ teardown_file() {
}
}'
)
exec_graphql 'post-transaction' "$variables"
exec_graphql 'transaction-post' "$variables"

variables=$(jq -n \
--arg journalId "$journal_id" \
Expand Down
2 changes: 1 addition & 1 deletion bats/add-to-account-set.bats
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ teardown_file() {
}
}'
)
exec_graphql 'post-transaction' "$variables"
exec_graphql 'transaction-post' "$variables"

# create an account set
account_set_id=$(random_uuid)
Expand Down
4 changes: 2 additions & 2 deletions bats/e2e.bats
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ teardown_file() {
}
}'
)
exec_graphql 'post-transaction' "$variables"
correlation_id=$(graphql_output '.data.postTransaction.transaction.correlationId')
exec_graphql 'transaction-post' "$variables"
correlation_id=$(graphql_output '.data.transactionPost.transaction.correlationId')
[[ $correlation_id == $transaction_id ]] || exit 1

# check balance
Expand Down
8 changes: 0 additions & 8 deletions bats/gql/post-transaction.gql

This file was deleted.

8 changes: 8 additions & 0 deletions bats/gql/transaction-post.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mutation transactionPost($input: TransactionInput!) {
transactionPost(input: $input) {
transaction {
transactionId
correlationId
}
}
}
8 changes: 4 additions & 4 deletions cala-ledger/src/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,27 @@ impl CalaLedger {
&self.transactions
}

pub async fn post_transaction(
pub async fn transaction_post(
&self,
tx_id: TransactionId,
tx_template_code: &str,
params: impl Into<TxParams> + std::fmt::Debug,
) -> Result<Transaction, LedgerError> {
let mut op = AtomicOperation::init(&self.pool, &self.outbox).await?;
let transaction = self
.post_transaction_in_op(&mut op, tx_id, tx_template_code, params)
.transaction_post_in_op(&mut op, tx_id, tx_template_code, params)
.await?;
op.commit().await?;
Ok(transaction)
}

#[instrument(
name = "cala_ledger.post_transaction",
name = "cala_ledger.transaction_post",
skip(self, op)
fields(transaction_id, external_id)
err
)]
pub async fn post_transaction_in_op(
pub async fn transaction_post_in_op(
&self,
op: &mut AtomicOperation<'_>,
tx_id: TransactionId,
Expand Down
2 changes: 1 addition & 1 deletion cala-ledger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
//! params.insert("sender_account_id", sender_account_id);
//! params.insert("units", Decimal::ONE);
//! // Create the transaction via the template
//! cala.post_transaction(TransactionId::new(), "GENERAL_INCOME", params)
//! cala.transaction_post(TransactionId::new(), "GENERAL_INCOME", params)
//! .await?;
//!
//! let account_balance = cala
Expand Down
2 changes: 1 addition & 1 deletion cala-ledger/tests/account_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ async fn balances() -> anyhow::Result<()> {
params.insert("journal_id", journal.id().to_string());
params.insert("sender", sender_account.id());
params.insert("recipient", recipient_account.id());
cala.post_transaction(TransactionId::new(), &tx_code, params)
cala.transaction_post(TransactionId::new(), &tx_code, params)
.await
.unwrap();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cala_ledger::{tx_template::*, *};
use rand::distributions::{Alphanumeric, DistString};

#[tokio::test]
async fn post_transaction() -> anyhow::Result<()> {
async fn transaction_post() -> anyhow::Result<()> {
let pool = helpers::init_pool().await?;
let cala_config = CalaLedgerConfig::builder()
.pool(pool)
Expand All @@ -31,7 +31,7 @@ async fn post_transaction() -> anyhow::Result<()> {
params.insert("sender", sender_account.id());
params.insert("recipient", recipient_account.id());

cala.post_transaction(TransactionId::new(), &tx_code, params)
cala.transaction_post(TransactionId::new(), &tx_code, params)
.await
.unwrap();

Expand All @@ -40,7 +40,7 @@ async fn post_transaction() -> anyhow::Result<()> {
params.insert("journal_id", journal.id());
params.insert("sender", sender_account.id());
params.insert("recipient", recipient_account.id());
cala.post_transaction(TransactionId::new(), &tx_code, params)
cala.transaction_post(TransactionId::new(), &tx_code, params)
.await
.unwrap();
let recipient_balance = cala
Expand Down
10 changes: 5 additions & 5 deletions cala-server/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ type Mutation {
journalCreate(input: JournalCreateInput!): JournalCreatePayload!
journalUpdate(id: UUID!, input: JournalUpdateInput!): JournalUpdatePayload!
txTemplateCreate(input: TxTemplateCreateInput!): TxTemplateCreatePayload!
postTransaction(input: TransactionInput!): PostTransactionPayload!
transactionPost(input: TransactionInput!): TransactionPostPayload!
}

"""
Expand Down Expand Up @@ -382,10 +382,6 @@ input ParamDefinitionInput {
description: String
}

type PostTransactionPayload {
transaction: Transaction!
}

type Query {
serverVersion: String!
account(id: UUID!): Account
Expand Down Expand Up @@ -441,6 +437,10 @@ input TransactionInput {
params: JSON
}

type TransactionPostPayload {
transaction: Transaction!
}

type TxInput {
effective: Expression!
journalId: Expression!
Expand Down
6 changes: 3 additions & 3 deletions cala-server/src/graphql/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,11 +588,11 @@ impl<E: MutationExtensionMarker> CoreMutation<E> {
Ok(tx_template.into())
}

async fn post_transaction(
async fn transaction_post(
&self,
ctx: &Context<'_>,
input: TransactionInput,
) -> Result<PostTransactionPayload> {
) -> Result<TransactionPostPayload> {
let app = ctx.data_unchecked::<CalaApp>();
let mut op = ctx
.data_unchecked::<DbOp>()
Expand All @@ -601,7 +601,7 @@ impl<E: MutationExtensionMarker> CoreMutation<E> {
let params = input.params.map(cala_ledger::tx_template::TxParams::from);
let transaction = app
.ledger()
.post_transaction_in_op(
.transaction_post_in_op(
&mut op,
input.transaction_id.into(),
&input.tx_template_code,
Expand Down
4 changes: 2 additions & 2 deletions cala-server/src/graphql/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct Transaction {
}

#[derive(SimpleObject)]
pub struct PostTransactionPayload {
pub struct TransactionPostPayload {
pub transaction: Transaction,
}

Expand Down Expand Up @@ -63,7 +63,7 @@ impl From<cala_ledger::transaction::Transaction> for Transaction {
}
}

impl From<cala_ledger::transaction::Transaction> for PostTransactionPayload {
impl From<cala_ledger::transaction::Transaction> for TransactionPostPayload {
fn from(value: cala_ledger::transaction::Transaction) -> Self {
Self {
transaction: Transaction::from(value),
Expand Down
2 changes: 1 addition & 1 deletion website/docs/accounting/step-by-step.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ slug: /docs/step-by-step

2. [**Define Transaction Templates**](/docs/tx-template-create): Create templates for common transactions like deposits and withdrawals. This ensures that each transaction follows a consistent structure.

3. [**Post Transactions**](/docs/post-transaction): Use the transaction templates to post transactions. This involves specifying the necessary parameters and ensuring that the correct accounts are debited or credited.
3. [**Post Transactions**](/docs/transaction-post): Use the transaction templates to post transactions. This involves specifying the necessary parameters and ensuring that the correct accounts are debited or credited.

4. [**Check Account Balances**](/docs/check-account-balance): Regularly query the balances of accounts to monitor the financial status. This helps in maintaining accurate and up-to-date financial records.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
id: post-transaction
id: transaction-post
title: Post a Transaction
slug: /docs//post-transaction
slug: /docs/transaction-post
---

This functionality allows to execute financial transactions based on predefined parameters and templates. The specific transaction being posted here is based on a deposit template, which facilitates adding funds to a user's account.
Expand Down Expand Up @@ -30,11 +30,11 @@ This functionality allows to execute financial transactions based on predefined

### GraphQL Request Body

The `postTransaction` mutation is called with the inputs below. This mutation processes the transaction based on the provided template and parameters.
The `transactionPost` mutation is called with the inputs below. This mutation processes the transaction based on the provided template and parameters.

```graphql
mutation postTransaction($input: TransactionInput!) {
postTransaction(input: $input) {
mutation transactionPost($input: TransactionInput!) {
transactionPost(input: $input) {
transaction {
transactionId
correlationId
Expand All @@ -52,7 +52,7 @@ Upon successful processing of the mutation, the system returns the transaction I
```json
{
"data": {
"postTransaction": {
"transactionPost": {
"transaction": {
"transactionId": "204d087b-5b6d-4544-9203-6674d54528d3",
"correlationId": "204d087b-5b6d-4544-9203-6674d54528d3"
Expand Down
6 changes: 3 additions & 3 deletions website/sidebars.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type {SidebarsConfig} from '@docusaurus/plugin-content-docs';
import type { SidebarsConfig } from '@docusaurus/plugin-content-docs';

const sidebars: SidebarsConfig = {
demoSidebar: [
'intro',
'intro',
{
type: 'category',
label: 'GraphQL API demo',
collapsed: false,
items: [
'demo/create-journal-and-accounts',
'demo/tx-template-create',
'demo/post-transaction',
'demo/transaction-post',
'demo/check-account-balance',
]
},
Expand Down
14 changes: 7 additions & 7 deletions website/static/api-reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ <h5 class="nav-group-section-title">
<li><a href="#mutation-calaOutboxImportJobCreate">calaOutboxImportJobCreate</a></li>
<li><a href="#mutation-journalCreate">journalCreate</a></li>
<li><a href="#mutation-journalUpdate">journalUpdate</a></li>
<li><a href="#mutation-postTransaction">postTransaction</a></li>
<li><a href="#mutation-transactionPost">transactionPost</a></li>
<li><a href="#mutation-removeFromAccountSet">removeFromAccountSet</a></li>
<li><a href="#mutation-txTemplateCreate">txTemplateCreate</a></li>
</ul>
Expand Down Expand Up @@ -2086,12 +2086,12 @@ <h5>Response</h5>
</div>
</div>
</section>
<section id="mutation-postTransaction" class="operation operation-mutation" data-traverse-target="mutation-postTransaction">
<section id="mutation-transactionPost" class="operation operation-mutation" data-traverse-target="mutation-transactionPost">
<div class="operation-group-name">
<a href="#group-Operations-Mutations">Mutations</a>
</div>
<h2 class="operation-heading ">
<code>postTransaction</code>
<code>transactionPost</code>
</h2>
<div class="doc-row">
<div class="doc-copy">
Expand Down Expand Up @@ -2127,8 +2127,8 @@ <h4 class="example-heading">Example</h4>
<h5>Query</h5>
<html>
<head></head>
<body><pre><code class="hljs language-gql"><span class="hljs-symbol"><span class="hljs-keyword">mutation</span> postTransaction<span class="hljs-tag">(<span class="hljs-code">$input</span>:<span class="hljs-type"> TransactionInput!</span>)</span> <span class="hljs-tag">{
<span class="hljs-symbol">postTransaction<span class="hljs-tag">(input: <span class="hljs-code">$input</span>)</span> <span class="hljs-tag">{
<body><pre><code class="hljs language-gql"><span class="hljs-symbol"><span class="hljs-keyword">mutation</span> transactionPost<span class="hljs-tag">(<span class="hljs-code">$input</span>:<span class="hljs-type"> TransactionInput!</span>)</span> <span class="hljs-tag">{
<span class="hljs-symbol">transactionPost<span class="hljs-tag">(input: <span class="hljs-code">$input</span>)</span> <span class="hljs-tag">{
<span class="hljs-symbol">transaction <span class="hljs-tag">{
<span class="hljs-type">...TransactionFragment</span>
}</span></span>
Expand All @@ -2153,7 +2153,7 @@ <h5>Response</h5>
<head></head>
<body><pre><code class="hljs language-json"><span class="hljs-punctuation">{</span>
<span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>
<span class="hljs-attr">"postTransaction"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span><span class="hljs-attr">"transaction"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">Transaction</span><span class="hljs-punctuation">}</span>
<span class="hljs-attr">"transactionPost"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span><span class="hljs-attr">"transaction"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">Transaction</span><span class="hljs-punctuation">}</span>
<span class="hljs-punctuation">}</span>
<span class="hljs-punctuation">}</span>
</code></pre>
Expand Down Expand Up @@ -5966,4 +5966,4 @@ <h5>Example</h5>
</div>
</div>
</body>
</html>
</html>

0 comments on commit 7a3c306

Please sign in to comment.