feat: 添加Projects结构体并优化项目获取逻辑及状态码
- 添加Projects结构体并优化get_all_project方法以使用新结构体收集项目名称 - 将项目获取成功时的HTTP状态码从404修改为200。
This commit is contained in:
18
src/db.rs
18
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<Vec<String>, Box<dyn std::error::Error + Send + Sync>> {
|
||||
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<Authorize> = result.collect_into()?;
|
||||
let projects: Vec<String> = Vec::new();
|
||||
for row in rows {
|
||||
println!("{row:?}");
|
||||
// 用Projects结构体来收集查询到的结果
|
||||
let result: Vec<Projects> = rows.collect_into()?;
|
||||
let mut projects:Vec<String> = Vec::new();
|
||||
for row in result {
|
||||
projects.push(row.project);
|
||||
}
|
||||
|
||||
Ok(projects)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user