Added more descriptive names to account ui
This commit is contained in:
parent
b4044de503
commit
c9632b3d98
4 changed files with 175 additions and 11 deletions
|
|
@ -35,7 +35,7 @@ async fn main() {
|
|||
"/",
|
||||
Router::new()
|
||||
.route("/", get(routes::ui::index))
|
||||
.route("/accounts/id/:id", get(routes::ui::account::list))
|
||||
.route("/accounts/id/:id", get(routes::ui::account::show))
|
||||
.route(
|
||||
"/accounts/id/:id/transactions/add",
|
||||
get(routes::ui::account::add_transactions_view),
|
||||
|
|
@ -44,6 +44,10 @@ async fn main() {
|
|||
"/accounts/id/:id/transactions/add",
|
||||
post(routes::ui::account::add_transactions_action),
|
||||
)
|
||||
.route(
|
||||
"/accounts/id/:id/transactions",
|
||||
get(routes::ui::account::list_transactions),
|
||||
)
|
||||
.route("/transaction/:id", get(routes::ui::transaction::view))
|
||||
.route("/transaction/:id", post(routes::ui::transaction::update))
|
||||
.route(
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@ use accounters::models::{account::Account, categories::Category, transaction::Tr
|
|||
pub struct AccountViewParams {
|
||||
from: Option<String>,
|
||||
to: Option<String>,
|
||||
entries: Option<i32>,
|
||||
page: Option<i32>,
|
||||
}
|
||||
|
||||
fn parse_date(s: &str) -> Option<DateTime<Utc>> {
|
||||
|
|
@ -30,17 +28,12 @@ fn parse_date(s: &str) -> Option<DateTime<Utc>> {
|
|||
Utc.with_ymd_and_hms(year, month, day, 0, 0, 0).single()
|
||||
}
|
||||
|
||||
pub async fn list(
|
||||
pub async fn show(
|
||||
State(db): State<Arc<SqlitePool>>,
|
||||
State(tmpls): State<Arc<Tera>>,
|
||||
uid: UserToken,
|
||||
Path(account_id): Path<i32>,
|
||||
Query(AccountViewParams {
|
||||
from,
|
||||
to,
|
||||
entries,
|
||||
page,
|
||||
}): Query<AccountViewParams>,
|
||||
Query(AccountViewParams { from, to }): Query<AccountViewParams>,
|
||||
) -> impl IntoResponse {
|
||||
let mut ctx = Context::new();
|
||||
|
||||
|
|
@ -87,6 +80,60 @@ pub async fn list(
|
|||
.collect();
|
||||
ctx.insert("categories", &categories);
|
||||
|
||||
let txs = match Transaction::list(db.as_ref(), account.get_id(), 10, 0, false).await {
|
||||
Ok(t) => t,
|
||||
Err(e) => {
|
||||
return (
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
[(CONTENT_TYPE, "text/plain")],
|
||||
format!("Error at loading transactions: {e}"),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
ctx.insert("account", &account);
|
||||
ctx.insert("transactions", &txs);
|
||||
(
|
||||
StatusCode::OK,
|
||||
[(CONTENT_TYPE, "text/html;charset=utf-8")],
|
||||
tmpls.render("account_summary.html", &ctx).unwrap(),
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct AccountTxListParams {
|
||||
entries: Option<i32>,
|
||||
page: Option<i32>,
|
||||
}
|
||||
|
||||
pub async fn list_transactions(
|
||||
State(db): State<Arc<SqlitePool>>,
|
||||
State(tmpls): State<Arc<Tera>>,
|
||||
uid: UserToken,
|
||||
Path(account_id): Path<i32>,
|
||||
Query(AccountTxListParams { entries, page }): Query<AccountTxListParams>,
|
||||
) -> impl IntoResponse {
|
||||
let mut ctx = Context::new();
|
||||
|
||||
let account = match Account::get_by_id(db.as_ref(), account_id).await {
|
||||
Ok(a) => a,
|
||||
Err(e) => {
|
||||
return (
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
[(CONTENT_TYPE, "text/plain")],
|
||||
format!("{e}"),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
if account.get_user() != uid.user_id {
|
||||
return (
|
||||
StatusCode::UNAUTHORIZED,
|
||||
[(CONTENT_TYPE, "text/plain")],
|
||||
String::from("You cannot access this resource"),
|
||||
);
|
||||
}
|
||||
|
||||
let n_entries = entries.unwrap_or(10).max(10);
|
||||
let page = page.unwrap_or(0).max(0);
|
||||
|
||||
|
|
@ -119,7 +166,7 @@ pub async fn list(
|
|||
(
|
||||
StatusCode::OK,
|
||||
[(CONTENT_TYPE, "text/html;charset=utf-8")],
|
||||
tmpls.render("accounts.html", &ctx).unwrap(),
|
||||
tmpls.render("account_txs.html", &ctx).unwrap(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue