Skip to content

Commit 9f8f09a

Browse files
committed
feat: updated applications return to include owner and repo in response in order to generate links on front-end
1 parent e210ec3 commit 9f8f09a

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

fplus-lib/src/core/mod.rs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -238,29 +238,44 @@ 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 = database::get_allocators().await.map_err(|_| LDNError::new("Failed to get allocators from the database"))?;
243+
let mut all_apps: Vec<(ApplicationFile, String, String)> = Vec::new();
244+
let mut errors: Vec<LDNError> = Vec::new();
243245

244-
let mut all_apps: Vec<ApplicationFile> = Vec::new();
245246
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);
247+
match active(allocator.owner.clone(), allocator.repo.clone(), None).await {
248+
Ok(apps) => {
249+
for app in apps {
250+
all_apps.push((app, allocator.repo.clone(), allocator.owner.clone()));
251+
}
252+
},
253+
Err(e) => {
254+
errors.push(e);
255+
eprintln!("Failed to process active applications for allocator {}:{}", allocator.repo, allocator.owner);
256+
},
251257
}
252258

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+
match merged(allocator.owner.clone(), allocator.repo.clone()).await {
260+
Ok(merged_apps) => {
261+
for app in merged_apps {
262+
all_apps.push((app.1, allocator.repo.clone(), allocator.owner.clone()));
263+
}
264+
},
265+
Err(e) => {
266+
errors.push(e);
267+
eprintln!("Failed to process merged applications for allocator {}:{}", allocator.repo, allocator.owner);
268+
},
259269
}
260270
}
261271

262-
Ok(all_apps)
272+
if errors.is_empty() {
273+
Ok(all_apps)
274+
} else {
275+
Err(errors)
276+
}
263277
}
278+
264279

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

0 commit comments

Comments
 (0)