Skip to content

Commit c9196d5

Browse files
authored
Merge pull request #131 from filecoin-project/feat/public-applications
feat: updated applications return to include owner and repo in respon…
2 parents e210ec3 + d0d63a0 commit c9196d5

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

fplus-http-server/src/router/application.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ pub async fn all_applications() -> impl Responder {
122122
Err(e) => HttpResponse::InternalServerError().body(format!("Failed to serialize applications: {}", e)),
123123
}
124124
},
125-
Err(e) => HttpResponse::BadRequest().body(e.to_string()),
125+
Err(errors) => {
126+
match serde_json::to_string_pretty(&errors) {
127+
Ok(json) => HttpResponse::BadRequest().content_type("application/json").body(json),
128+
Err(e) => HttpResponse::InternalServerError().body(format!("Failed to serialize errors: {}", e)),
129+
}
130+
},
126131
}
127132
}
128133

fplus-lib/src/core/mod.rs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -238,29 +238,46 @@ impl LDNApplication {
238238
});
239239
}
240240

241-
pub async fn all_applications() -> Result<Vec<ApplicationFile>, LDNError> {
242-
let allocators = database::get_allocators().await.map_err(|e| LDNError::Load(format!("Failed to retrieve allocators /// {}", e)))?;
241+
pub async fn all_applications() -> Result<Vec<(ApplicationFile, String, String)>, Vec<LDNError>> {
242+
let allocators = match database::get_allocators().await {
243+
Ok(allocs) => allocs,
244+
Err(e) => return Err(vec![LDNError::Load(format!("Failed to retrieve allocators: {}", e))]),
245+
}; let mut all_apps: Vec<(ApplicationFile, String, String)> = Vec::new();
246+
let mut errors: Vec<LDNError> = Vec::new();
243247

244-
let mut all_apps: Vec<ApplicationFile> = Vec::new();
245248
for allocator in allocators {
246-
// Process active applications
247-
if let Ok(apps) = Self::active(allocator.owner.clone(), allocator.repo.clone(), None).await {
248-
all_apps.extend(apps);
249-
} else {
250-
eprintln!("Failed to process active applications for allocator {}:{}", allocator.repo, allocator.owner);
249+
match Self::active(allocator.owner.clone(), allocator.repo.clone(), None).await {
250+
Ok(apps) => {
251+
for app in apps {
252+
all_apps.push((app, allocator.repo.clone(), allocator.owner.clone()));
253+
}
254+
},
255+
Err(e) => {
256+
errors.push(e);
257+
eprintln!("Failed to process active applications for allocator {}:{}", allocator.repo, allocator.owner);
258+
},
251259
}
252260

253-
// Process merged applications
254-
if let Ok(merged_apps) = Self::merged(allocator.owner.clone(), allocator.repo.clone()).await {
255-
// Assuming you only need ApplicationFile from the tuple (Content, ApplicationFile)
256-
all_apps.extend(merged_apps.into_iter().map(|(_, app_file)| app_file));
257-
} else {
258-
eprintln!("Failed to process merged applications for allocator {}:{}", allocator.repo, allocator.owner);
261+
match Self::merged(allocator.owner.clone(), allocator.repo.clone()).await {
262+
Ok(merged_apps) => {
263+
for app in merged_apps {
264+
all_apps.push((app.1, allocator.repo.clone(), allocator.owner.clone()));
265+
}
266+
},
267+
Err(e) => {
268+
errors.push(e);
269+
eprintln!("Failed to process merged applications for allocator {}:{}", allocator.repo, allocator.owner);
270+
},
259271
}
260272
}
261273

262-
Ok(all_apps)
274+
if errors.is_empty() {
275+
Ok(all_apps)
276+
} else {
277+
Err(errors)
278+
}
263279
}
280+
264281

265282
pub async fn active(owner: String, repo: String, filter: Option<String>) -> Result<Vec<ApplicationFile>, LDNError> {
266283
let gh: GithubWrapper = GithubWrapper::new(owner.clone(), repo.clone());

fplus-lib/src/error.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ use actix_web::{
88
body::{BodySize, MessageBody},
99
web::Bytes,
1010
};
11+
use serde::{Deserialize, Serialize};
1112

12-
#[derive(Debug)]
13+
#[derive(Debug, Serialize, Deserialize)]
1314
pub enum LDNError {
1415
New(String),
1516
Load(String),

0 commit comments

Comments
 (0)