Skip to content

Commit 9d2d761

Browse files
committed
fix errors in all_applications
1 parent 3c69105 commit 9d2d761

File tree

3 files changed

+58
-17
lines changed

3 files changed

+58
-17
lines changed

fplus-database/src/database/applications.rs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ use sha1::{Sha1, Digest};
1111
*/
1212
pub async fn get_applications() ->Result<Vec<ApplicationModel>, sea_orm::DbErr> {
1313
let conn = get_database_connection().await?;
14-
Application::find().all(&conn).await
14+
Application::find()
15+
.order_by(Column::Owner, Order::Asc)
16+
.order_by(Column::Repo, Order::Asc)
17+
.all(&conn).await
1518
}
1619

1720
/**
@@ -24,12 +27,19 @@ pub async fn get_applications() ->Result<Vec<ApplicationModel>, sea_orm::DbErr>
2427
* # Returns
2528
* @return Result<Vec<ApplicationModel>, sea_orm::DbErr> - The result of the operation
2629
*/
27-
pub async fn get_merged_applications(owner: String, repo: String) -> Result<Vec<ApplicationModel>, sea_orm::DbErr> {
30+
pub async fn get_merged_applications(owner: Option<String>, repo: Option<String>) -> Result<Vec<ApplicationModel>, sea_orm::DbErr> {
2831
let conn = get_database_connection().await?;
29-
Application::find()
30-
.filter(Column::Owner.contains(owner))
31-
.filter(Column::Repo.contains(repo))
32-
.filter(Column::PrNumber.eq(0))
32+
let mut query = Application::find()
33+
.filter(Column::PrNumber.eq(0));
34+
if let Some(owner) = owner {
35+
query = query.filter(Column::Owner.contains(owner));
36+
}
37+
if let Some(repo) = repo {
38+
query = query.filter(Column::Repo.contains(repo));
39+
}
40+
query
41+
.order_by(Column::Owner, Order::Asc)
42+
.order_by(Column::Repo, Order::Asc)
3343
.all(&conn)
3444
.await
3545
}
@@ -44,12 +54,19 @@ pub async fn get_merged_applications(owner: String, repo: String) -> Result<Vec<
4454
* # Returns
4555
* @return Result<Vec<ApplicationModel>, sea_orm::DbErr> - The result of the operation
4656
*/
47-
pub async fn get_active_applications(owner: String, repo: String) -> Result<Vec<ApplicationModel>, sea_orm::DbErr> {
57+
pub async fn get_active_applications(owner: Option<String>, repo: Option<String>) -> Result<Vec<ApplicationModel>, sea_orm::DbErr> {
4858
let conn = get_database_connection().await?;
49-
Application::find()
50-
.filter(Column::Owner.contains(owner))
51-
.filter(Column::Repo.contains(repo))
52-
.filter(Column::PrNumber.ne(0))
59+
let mut query = Application::find()
60+
.filter(Column::PrNumber.ne(0));
61+
if let Some(owner) = owner {
62+
query = query.filter(Column::Owner.contains(owner));
63+
}
64+
if let Some(repo) = repo {
65+
query = query.filter(Column::Repo.contains(repo));
66+
}
67+
query
68+
.order_by(Column::Owner, Order::Asc)
69+
.order_by(Column::Repo, Order::Asc)
5370
.all(&conn)
5471
.await
5572
}

fplus-database/src/lib.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,27 @@ mod tests {
232232

233233
}
234234

235+
/**
236+
* Test the create_application function
237+
*
238+
* # Returns
239+
* @return () - The result of the test
240+
*/
241+
#[tokio::test]
242+
#[serial]
243+
async fn test_create_application() {
244+
setup_test_environment().await;
245+
246+
let id = "test_id".to_string();
247+
let owner = "keyko-io".to_string();
248+
let repo = "great-test-library".to_string();
249+
let pr_number = 14;
250+
let app_file = "test_app_file".to_string();
251+
let sha = "test_sha".to_string();
252+
let path = "test_path".to_string();
253+
254+
let result = database::applications::create_application(id, owner, repo, pr_number, app_file, sha, path).await;
255+
assert!(result.is_ok());
256+
}
257+
235258
}

fplus-lib/src/core/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl LDNApplication {
333333

334334
pub async fn active(owner: String, repo: String, filter: Option<String>) -> Result<Vec<ApplicationFile>, LDNError> {
335335
// Get all active applications from the database.
336-
let active_apps_result = database::applications::get_active_applications(owner, repo).await;
336+
let active_apps_result = database::applications::get_active_applications(Some(owner), Some(repo)).await;
337337

338338
// Handle errors in getting active applications.
339339
let active_apps = match active_apps_result {
@@ -355,7 +355,8 @@ impl LDNApplication {
355355
if let Some(app_json) = app_model.application {
356356
match from_str::<ApplicationFile>(&app_json) {
357357
Ok(app) => apps.push(app),
358-
Err(e) => return Err(LDNError::Load(format!("Failed to parse application file: {}", e))),
358+
//if error, don't push into apps
359+
Err(_) => {}
359360
}
360361
}
361362
}
@@ -934,7 +935,7 @@ impl LDNApplication {
934935

935936
pub async fn merged(owner: String, repo: String) -> Result<Vec<(ApplicationGithubInfo, ApplicationFile)>, LDNError> {
936937
// Retrieve all applications in the main branch from the database.
937-
let merged_apps_result = database::applications::get_merged_applications(owner.clone(), repo.clone()).await;
938+
let merged_apps_result = database::applications::get_merged_applications(Some(owner.clone()), Some(repo.clone())).await;
938939

939940
// Handle errors in getting applications from the main branch.
940941
let merged_app_models = match merged_apps_result {
@@ -950,7 +951,7 @@ impl LDNApplication {
950951
if let Some(app_json) = app_model.application {
951952
match from_str::<ApplicationFile>(&app_json) {
952953
Ok(app) => merged_apps.push((ApplicationGithubInfo {sha: app_model.sha.unwrap(), path: app_model.path.unwrap()}, app)),
953-
Err(e) => return Err(LDNError::Load(format!("Failed to parse application file: {}", e))),
954+
Err(_) => {},
954955
}
955956
}
956957
}
@@ -1807,7 +1808,7 @@ Your Datacap Allocation Request has been {} by the Notary
18071808

18081809
pub async fn cache_renewal_active(owner: String, repo: String) -> Result<(), LDNError> {
18091810
let active_from_gh: Vec<ApplicationFileWithDate> = LDNApplication::active_apps_with_last_update(owner.clone(), repo.clone(), None).await?;
1810-
let active_from_db: Vec<ApplicationModel> = database::applications::get_active_applications(owner.clone(), repo.clone()).await.unwrap();
1811+
let active_from_db: Vec<ApplicationModel> = database::applications::get_active_applications(Some(owner.clone()), Some(repo.clone())).await.unwrap();
18111812

18121813
let mut db_apps_set: HashSet<String> = HashSet::new();
18131814
let mut processed_gh_apps: HashSet<String> = HashSet::new();
@@ -1864,7 +1865,7 @@ Your Datacap Allocation Request has been {} by the Notary
18641865

18651866
pub async fn cache_renewal_merged(owner: String, repo: String) -> Result<(), LDNError> {
18661867
let merged_from_gh: Vec<ApplicationFileWithDate> = LDNApplication::merged_apps_with_last_update(owner.clone(), repo.clone(), None).await?;
1867-
let merged_from_db: Vec<ApplicationModel> = database::applications::get_merged_applications(owner.clone(), repo.clone()).await.unwrap();
1868+
let merged_from_db: Vec<ApplicationModel> = database::applications::get_merged_applications(Some(owner.clone()), Some(repo.clone())).await.unwrap();
18681869

18691870
let mut db_apps_set: HashSet<String> = HashSet::new();
18701871
let mut processed_gh_apps: HashSet<String> = HashSet::new();

0 commit comments

Comments
 (0)