This commit is contained in:
parent
810fdde741
commit
bd122f6a7b
1 changed files with 7 additions and 2 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use std::{collections::HashSet, sync::Arc};
|
||||
use std::{collections::{HashMap, HashSet}, sync::Arc};
|
||||
|
||||
use axum::{extract::{Path, State}, Json};
|
||||
use reqwest::{StatusCode};
|
||||
|
|
@ -6,7 +6,7 @@ use sea_orm::{ActiveModelTrait, ActiveValue::{NotSet, Set}, ColumnTrait, EntityT
|
|||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::IntoParams;
|
||||
|
||||
use crate::{entities::{bal::{self, BalState}, bal_stats, book_instance, owner, prelude::*}, routes::auth::Claims, AppState};
|
||||
use crate::{entities::{bal::{self, BalState}, bal_stats, book, book_instance, owner, prelude::*}, routes::auth::Claims, AppState};
|
||||
|
||||
|
||||
#[derive(IntoParams)]
|
||||
|
|
@ -323,6 +323,7 @@ pub struct OwnerAccountingData {
|
|||
#[derive(Serialize, utoipa::ToSchema)]
|
||||
pub struct BalAccounting {
|
||||
pub owners: Vec<OwnerAccountingData>,
|
||||
pub book_map: HashMap<u32, book::Model>,
|
||||
pub total_collected_money: f32
|
||||
}
|
||||
|
||||
|
|
@ -352,6 +353,7 @@ pub async fn get_bal_accounting(
|
|||
} else {
|
||||
let mut accounting_data = BalAccounting {
|
||||
owners: vec![],
|
||||
book_map: HashMap::new(),
|
||||
total_collected_money: 0.
|
||||
};
|
||||
|
||||
|
|
@ -367,6 +369,9 @@ pub async fn get_bal_accounting(
|
|||
}
|
||||
let mut owner_accounting_data = OwnerAccountingData { owner_id: owner.id, owed_money: 0., owed_books: vec![] };
|
||||
for book_instance in owner_books {
|
||||
if !accounting_data.book_map.contains_key(&book_instance.book_id) {
|
||||
accounting_data.book_map.insert(book_instance.book_id, Book::find_by_id(book_instance.book_id).one(state.db_conn.as_ref()).await.unwrap().unwrap());
|
||||
}
|
||||
match book_instance.sold_price {
|
||||
Some(val) => owner_accounting_data.owed_money += val,
|
||||
None => owner_accounting_data.owed_books.push(book_instance),
|
||||
|
|
|
|||
Reference in a new issue