Skip to content

Commit efd6ca6

Browse files
committed
style:simplify Account and Directive creation in route handlers
1 parent 6456b2d commit efd6ca6

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

zhang-server/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,12 @@ pub async fn start_server(
326326
}
327327

328328
pub fn create_server_app(opts: ServeConfig, ledger: Arc<RwLock<Ledger>>, broadcaster: Arc<Broadcaster>, reload_sender: Arc<ReloadSender>) -> ServerApp {
329-
let app = ServerApp {
329+
ServerApp {
330330
opts,
331331
ledger,
332332
broadcaster,
333333
reload_sender,
334-
};
335-
app
334+
}
336335
}
337336

338337
async fn version_report_task() -> ServerResult<()> {

zhang-server/src/routes/account.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::collections::HashMap;
21
use std::str::FromStr;
32

43
use axum::extract::{Multipart, Path, State};
@@ -9,7 +8,7 @@ use itertools::Itertools;
98
use log::info;
109
use uuid::Uuid;
1110
use zhang_ast::amount::Amount;
12-
use zhang_ast::{Account, BalanceCheck, BalancePad, Currency, Date, Directive, Document, ZhangString};
11+
use zhang_ast::{Account, BalanceCheck, BalancePad, Date, Directive, Document, ZhangString};
1312
use zhang_core::utils::calculable::Calculable;
1413

1514
use crate::request::AccountBalanceRequest;
@@ -108,7 +107,7 @@ pub async fn upload_account_document(
108107

109108
documents.push(Directive::Document(Document {
110109
date: Date::now(&ledger_stage.options.timezone),
111-
account: Account::from_str(&account_name)?.into(),
110+
account: Account::from_str(&account_name)?,
112111
filename: ZhangString::QuoteString(striped_path_string),
113112
tags: None,
114113
links: None,
@@ -195,7 +194,7 @@ pub async fn create_account_balance(
195194
let balance = match payload {
196195
AccountBalanceRequest::Check { amount, .. } => Directive::BalanceCheck(BalanceCheck {
197196
date: Date::now(&ledger.options.timezone),
198-
account: Account::from_str(&target_account)?.into(),
197+
account: Account::from_str(&target_account)?,
199198
amount: Amount {
200199
number: amount.number,
201200
currency: amount.commodity,
@@ -204,13 +203,13 @@ pub async fn create_account_balance(
204203
}),
205204
AccountBalanceRequest::Pad { amount, pad, .. } => Directive::BalancePad(BalancePad {
206205
date: Date::now(&ledger.options.timezone),
207-
account: Account::from_str(&target_account)?.into(),
206+
account: Account::from_str(&target_account)?,
208207
amount: Amount {
209208
number: amount.number,
210209
currency: amount.commodity,
211210
},
212211
meta: Default::default(),
213-
pad: Account::from_str(&pad)?.into(),
212+
pad: Account::from_str(&pad)?,
214213
}),
215214
};
216215

@@ -229,7 +228,7 @@ pub async fn create_batch_account_balances(
229228
let balance = match balance {
230229
AccountBalanceRequest::Check { account_name, amount } => Directive::BalanceCheck(BalanceCheck {
231230
date: Date::now(&ledger.options.timezone),
232-
account: Account::from_str(&account_name)?.into(),
231+
account: Account::from_str(&account_name)?,
233232
amount: Amount {
234233
number: amount.number,
235234
currency: amount.commodity,
@@ -238,13 +237,13 @@ pub async fn create_batch_account_balances(
238237
}),
239238
AccountBalanceRequest::Pad { account_name, amount, pad } => Directive::BalancePad(BalancePad {
240239
date: Date::now(&ledger.options.timezone),
241-
account: Account::from_str(&account_name)?.into(),
240+
account: Account::from_str(&account_name)?,
242241
amount: Amount {
243242
number: amount.number,
244243
currency: amount.commodity,
245244
},
246245
meta: Default::default(),
247-
pad: Account::from_str(&pad)?.into(),
246+
pad: Account::from_str(&pad)?,
248247
}),
249248
};
250249
directives.push(balance);

0 commit comments

Comments
 (0)