refactor: bal accounting data responses
All checks were successful
/ test (push) Successful in 3m21s
All checks were successful
/ test (push) Successful in 3m21s
This commit is contained in:
parent
b551f856df
commit
810fdde741
1 changed files with 6 additions and 5 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use std::{collections::{HashMap, HashSet}, sync::Arc};
|
||||
use std::{collections::HashSet, sync::Arc};
|
||||
|
||||
use axum::{extract::{Path, State}, Json};
|
||||
use reqwest::{StatusCode};
|
||||
|
|
@ -315,13 +315,14 @@ pub async fn get_bals(
|
|||
|
||||
#[derive(Serialize, utoipa::ToSchema)]
|
||||
pub struct OwnerAccountingData {
|
||||
pub owner_id: u32,
|
||||
pub owed_money: f32,
|
||||
pub owed_books: Vec<book_instance::Model>
|
||||
}
|
||||
|
||||
#[derive(Serialize, utoipa::ToSchema)]
|
||||
pub struct BalAccounting {
|
||||
pub owner_map: HashMap<u32, OwnerAccountingData>,
|
||||
pub owners: Vec<OwnerAccountingData>,
|
||||
pub total_collected_money: f32
|
||||
}
|
||||
|
||||
|
|
@ -350,7 +351,7 @@ pub async fn get_bal_accounting(
|
|||
(StatusCode::FORBIDDEN, Json(None))
|
||||
} else {
|
||||
let mut accounting_data = BalAccounting {
|
||||
owner_map: HashMap::new(),
|
||||
owners: vec![],
|
||||
total_collected_money: 0.
|
||||
};
|
||||
|
||||
|
|
@ -364,7 +365,7 @@ pub async fn get_bal_accounting(
|
|||
if owner_books.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let mut owner_accounting_data = OwnerAccountingData { owed_money: 0., owed_books: vec![] };
|
||||
let mut owner_accounting_data = OwnerAccountingData { owner_id: owner.id, owed_money: 0., owed_books: vec![] };
|
||||
for book_instance in owner_books {
|
||||
match book_instance.sold_price {
|
||||
Some(val) => owner_accounting_data.owed_money += val,
|
||||
|
|
@ -372,7 +373,7 @@ pub async fn get_bal_accounting(
|
|||
}
|
||||
}
|
||||
accounting_data.total_collected_money += owner_accounting_data.owed_money;
|
||||
accounting_data.owner_map.insert(owner.id, owner_accounting_data);
|
||||
accounting_data.owners.push(owner_accounting_data);
|
||||
}
|
||||
|
||||
(StatusCode::OK, Json(Some(accounting_data)))
|
||||
|
|
|
|||
Reference in a new issue