Skip to content

Commit e210ec3

Browse files
authored
Merge pull request #130 from filecoin-project/feat/retrieve_all_applications
retrieve all applications
2 parents 582e771 + be5ed92 commit e210ec3

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

fplus-http-server/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ async fn main() -> std::io::Result<()> {
3232
.service(router::application::approve)
3333
.service(router::application::merged)
3434
.service(router::application::active)
35+
.service(router::application::all_applications)
3536
.service(router::application::refill)
3637
.service(router::application::total_dc_reached)
3738
.service(router::application::single)

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,19 @@ pub async fn approve(
113113
}
114114
}
115115

116+
#[get("/applications")]
117+
pub async fn all_applications() -> impl Responder {
118+
match LDNApplication::all_applications().await {
119+
Ok(apps) => {
120+
match serde_json::to_string_pretty(&apps) {
121+
Ok(json) => HttpResponse::Ok().content_type("application/json").body(json),
122+
Err(e) => HttpResponse::InternalServerError().body(format!("Failed to serialize applications: {}", e)),
123+
}
124+
},
125+
Err(e) => HttpResponse::BadRequest().body(e.to_string()),
126+
}
127+
}
128+
116129
#[get("/application/active")]
117130
pub async fn active(query: web::Query<GithubQueryParams>) -> impl Responder {
118131
let GithubQueryParams { owner, repo } = query.into_inner();

fplus-lib/src/core/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,30 @@ 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)))?;
243+
244+
let mut all_apps: Vec<ApplicationFile> = Vec::new();
245+
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);
251+
}
252+
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);
259+
}
260+
}
261+
262+
Ok(all_apps)
263+
}
264+
241265
pub async fn active(owner: String, repo: String, filter: Option<String>) -> Result<Vec<ApplicationFile>, LDNError> {
242266
let gh: GithubWrapper = GithubWrapper::new(owner.clone(), repo.clone());
243267
let mut apps: Vec<ApplicationFile> = Vec::new();

0 commit comments

Comments
 (0)