From 5c0b99c0d48ec7d0401b9f17b0e90012082177fc Mon Sep 17 00:00:00 2001 From: caoqianming Date: Tue, 24 Mar 2026 14:48:30 +0800 Subject: [PATCH] feat(service): add get_all_enabled_units and get_equipment_by_unit_id --- src/service/control.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/service/control.rs b/src/service/control.rs index 7be133b..97f90c0 100644 --- a/src/service/control.rs +++ b/src/service/control.rs @@ -308,6 +308,26 @@ pub async fn get_events_paginated( qb.build_query_as::().fetch_all(pool).await } +pub async fn get_all_enabled_units(pool: &PgPool) -> Result, 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, 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( pool: &PgPool, equipment_id: Uuid,