1use forms::{Form, FormValues};
4use uuid::Uuid;
5
6use super::Failure;
7use super::account_edit_load::load_account_edit;
8use super::commodity_edit_load::load_commodity_edit;
9use super::handler::{Handler, unknown};
10use super::script_edit_load::load_script_edit;
11use super::tag_edit_load::load_tag_edit;
12use super::template_edit_load::load_template_edit;
13use super::transaction_create_load::load_transaction_create;
14use super::transaction_edit_load::load_transaction_edit;
15
16pub async fn load(user_id: Uuid, form: &Form, id: &str) -> Result<FormValues, Failure> {
18 match Handler::of(form)? {
19 Handler::TransactionEdit => load_transaction_edit(user_id, id).await,
20 Handler::TransactionCreate => load_transaction_create(user_id, id).await,
21 Handler::AccountEdit => load_account_edit(user_id, id).await,
22 Handler::CommodityEdit => load_commodity_edit(user_id, id).await,
23 Handler::TagEdit => load_tag_edit(user_id, id).await,
24 Handler::TemplateEdit => load_template_edit(user_id, id).await,
25 Handler::ScriptEdit => load_script_edit(user_id, id)
26 .await
27 .map(|(values, _)| values),
28 Handler::TransactionQuery
29 | Handler::ReportBalance
30 | Handler::ReportActivity
31 | Handler::ReportCategory
32 | Handler::AccountMerge
33 | Handler::AccountCreate
34 | Handler::CommodityCreate
35 | Handler::TagCreate
36 | Handler::TemplateCreate
37 | Handler::ScriptCreate
38 | Handler::SshKeyAdd
39 | Handler::TemplateTest
40 | Handler::ConfigSet
41 | Handler::Convert => Err(unknown(form.name)),
42 }
43}