diff --git a/src/db.rs b/src/db.rs index 28ec1b3..83ae2fa 100644 --- a/src/db.rs +++ b/src/db.rs @@ -17,6 +17,11 @@ pub struct Authorize { pub insert_time: String, } +#[derive(Debug, WeldsModel)] +pub struct Projects { + pub project: String, +} + /// 包装类,内部持有 SQLite 连接 pub struct Db { client: SqliteClient, @@ -189,17 +194,18 @@ impl Db { pub async fn get_all_project( &self, ) -> Result, Box> { - let result = Authorize::select(|a| a.project) + let rows = Authorize::all() + .select(|a| a.project) .group_by(|a| a.project) .run(&self.client) .await?; - let rows: Vec = result.collect_into()?; - let projects: Vec = Vec::new(); - for row in rows { - println!("{row:?}"); + // 用Projects结构体来收集查询到的结果 + let result: Vec = rows.collect_into()?; + let mut projects:Vec = Vec::new(); + for row in result { + projects.push(row.project); } - Ok(projects) } } diff --git a/src/main.rs b/src/main.rs index 72c16e6..e3dc003 100644 --- a/src/main.rs +++ b/src/main.rs @@ -224,7 +224,7 @@ async fn get_projects( ( StatusCode::OK, Json(ProjectResponse { - code: 404, + code: 200, projects: projects, }), )