feat(service): add get_all_enabled_units and get_equipment_by_unit_id

This commit is contained in:
caoqianming 2026-03-24 14:48:30 +08:00
parent 6a4c3b1d39
commit 5c0b99c0d4
1 changed files with 20 additions and 0 deletions

View File

@ -308,6 +308,26 @@ pub async fn get_events_paginated(
qb.build_query_as::<EventRecord>().fetch_all(pool).await qb.build_query_as::<EventRecord>().fetch_all(pool).await
} }
pub async fn get_all_enabled_units(pool: &PgPool) -> Result<Vec<ControlUnit>, sqlx::Error> {
sqlx::query_as::<_, ControlUnit>(
r#"SELECT * FROM unit WHERE enabled = TRUE ORDER BY created_at"#,
)
.fetch_all(pool)
.await
}
pub async fn get_equipment_by_unit_id(
pool: &PgPool,
unit_id: Uuid,
) -> Result<Vec<crate::model::Equipment>, sqlx::Error> {
sqlx::query_as::<_, crate::model::Equipment>(
r#"SELECT * FROM equipment WHERE unit_id = $1 ORDER BY created_at"#,
)
.bind(unit_id)
.fetch_all(pool)
.await
}
pub async fn get_equipment_role_points( pub async fn get_equipment_role_points(
pool: &PgPool, pool: &PgPool,
equipment_id: Uuid, equipment_id: Uuid,