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,
|
pub insert_time: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, WeldsModel)]
|
||||||
|
pub struct Projects {
|
||||||
|
pub project: String,
|
||||||
|
}
|
||||||
|
|
||||||
/// 包装类,内部持有 SQLite 连接
|
/// 包装类,内部持有 SQLite 连接
|
||||||
pub struct Db {
|
pub struct Db {
|
||||||
client: SqliteClient,
|
client: SqliteClient,
|
||||||
@@ -189,17 +194,18 @@ impl Db {
|
|||||||
pub async fn get_all_project(
|
pub async fn get_all_project(
|
||||||
&self,
|
&self,
|
||||||
) -> Result<Vec<String>, Box<dyn std::error::Error + Send + Sync>> {
|
) -> 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)
|
.group_by(|a| a.project)
|
||||||
.run(&self.client)
|
.run(&self.client)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let rows: Vec<Authorize> = result.collect_into()?;
|
// 用Projects结构体来收集查询到的结果
|
||||||
let projects: Vec<String> = Vec::new();
|
let result: Vec<Projects> = rows.collect_into()?;
|
||||||
for row in rows {
|
let mut projects:Vec<String> = Vec::new();
|
||||||
println!("{row:?}");
|
for row in result {
|
||||||
|
projects.push(row.project);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(projects)
|
Ok(projects)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ async fn get_projects(
|
|||||||
(
|
(
|
||||||
StatusCode::OK,
|
StatusCode::OK,
|
||||||
Json(ProjectResponse {
|
Json(ProjectResponse {
|
||||||
code: 404,
|
code: 200,
|
||||||
projects: projects,
|
projects: projects,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user