feat: bal start and end timestamps
All checks were successful
/ test (push) Successful in 15m34s

This commit is contained in:
Ninjdai 2025-08-10 02:29:14 +02:00
parent 7500a129bd
commit 37102f9014
4 changed files with 56 additions and 48 deletions

View file

@ -9,7 +9,8 @@ pub struct Model {
pub id: u32,
pub user_id: u32,
pub name: String,
pub ended: bool
pub start_timestamp: i64,
pub end_timestamp: i64
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

View file

@ -48,6 +48,8 @@ pub async fn get_bal_by_id(
#[derive(Deserialize, Serialize, utoipa::ToSchema)]
pub struct BalCreateParams {
name: String,
start_timestamp: i64,
end_timestamp: i64,
}
#[axum::debug_handler]
@ -72,7 +74,8 @@ pub async fn create_bal(
id: NotSet,
user_id: Set(claims.user_id),
name: Set(instance_payload.name),
ended: Set(false)
start_timestamp: Set(instance_payload.start_timestamp),
end_timestamp: Set(instance_payload.end_timestamp),
};
let b = bal.save(state.db_conn.as_ref()).await;
@ -88,6 +91,8 @@ pub async fn create_bal(
#[derive(Deserialize, Serialize, utoipa::ToSchema)]
pub struct BalUpdateParams {
name: Option<String>,
start_timestamp: Option<i64>,
end_timestamp: Option<i64>,
}
#[axum::debug_handler]
@ -121,6 +126,14 @@ pub async fn update_bal(
None => bal.name,
Some(v) => Set(v)
};
bal.start_timestamp = match instance_payload.start_timestamp {
None => bal.start_timestamp,
Some(v) => Set(v)
};
bal.end_timestamp = match instance_payload.end_timestamp {
None => bal.end_timestamp,
Some(v) => Set(v)
};
match bal.update(state.db_conn.as_ref()).await {
Err(e) => {
@ -242,12 +255,6 @@ pub async fn set_current_bal(
let _ = update_query.exec(state.db_conn.as_ref()).await;
}
// Set old bal as ended if it existed
let _ = Bal::update(bal::ActiveModel {
id: Set(old_bal_id),
ended: Set(true),
..Default::default()
}).exec(state.db_conn.as_ref()).await;
}
// Set current bal on user