Skip to content

Commit 3db7559

Browse files
committed
Return a valid structure of the API response
1 parent 173ef3b commit 3db7559

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ use actix_web::{
22
error::{ErrorBadRequest, ErrorInternalServerError, ErrorNotFound},
33
get, post, web, HttpResponse, Responder,
44
};
5-
use fplus_database::database::applications::{
6-
get_allocator_closed_applications, get_closed_applications,
7-
};
5+
86
use fplus_lib::core::{
97
application::file::{StorageProviderChangeVerifier, VerifierInput},
108
ApplicationQueryParams, BranchDeleteInfo, CompleteGovernanceReviewInfo,
@@ -39,7 +37,7 @@ pub async fn single(
3937

4038
#[get("/applications/closed")]
4139
pub async fn closed_applications() -> actix_web::Result<impl Responder> {
42-
let apps = get_closed_applications()
40+
let apps = LDNApplication::get_closed_applications()
4341
.await
4442
.map_err(ErrorInternalServerError)?;
4543

@@ -54,7 +52,7 @@ pub async fn closed_allocator_applications(
5452
query: web::Query<GithubQueryParams>,
5553
) -> actix_web::Result<impl Responder> {
5654
let GithubQueryParams { owner, repo } = query.into_inner();
57-
let apps = get_allocator_closed_applications(&owner, &repo)
55+
let apps = LDNApplication::get_allocator_closed_applications(&owner, &repo)
5856
.await
5957
.map_err(ErrorInternalServerError)?;
6058

fplus-lib/src/core/mod.rs

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,19 +513,55 @@ impl LDNApplication {
513513
}
514514

515515
pub async fn all_applications() -> Result<Vec<ApplicationResponse>, LDNError> {
516-
let db_apps = database::applications::get_active_applications()
516+
let applications = database::applications::get_active_applications()
517517
.await
518518
.map_err(|e| {
519519
LDNError::Load(format!(
520520
"Failed to get applications from the database: {}",
521521
e
522522
))
523523
})?;
524-
let mut all_apps: Vec<ApplicationResponse> = Vec::new();
525-
for app in db_apps {
524+
let applications_response = Self::prepare_applications_response(applications);
525+
Ok(applications_response)
526+
}
527+
528+
pub async fn get_closed_applications() -> Result<Vec<ApplicationResponse>, LDNError> {
529+
let applications = database::applications::get_closed_applications()
530+
.await
531+
.map_err(|e| {
532+
LDNError::Load(format!(
533+
"Failed to get applications from the database: {}",
534+
e
535+
))
536+
})?;
537+
let applications_response = Self::prepare_applications_response(applications);
538+
Ok(applications_response)
539+
}
540+
541+
pub async fn get_allocator_closed_applications(
542+
owner: &str,
543+
repo: &str,
544+
) -> Result<Vec<ApplicationResponse>, LDNError> {
545+
let applications = database::applications::get_allocator_closed_applications(owner, repo)
546+
.await
547+
.map_err(|e| {
548+
LDNError::Load(format!(
549+
"Failed to get applications from the database: {}",
550+
e
551+
))
552+
})?;
553+
let applications_response = Self::prepare_applications_response(applications);
554+
Ok(applications_response)
555+
}
556+
557+
fn prepare_applications_response(
558+
applications: Vec<ApplicationModel>,
559+
) -> Vec<ApplicationResponse> {
560+
let mut applications_response: Vec<ApplicationResponse> = Vec::new();
561+
for app in applications {
526562
if let Some(application_data) = app.application {
527563
if let Ok(app_file) = ApplicationFile::from_str(&application_data) {
528-
all_apps.push(ApplicationResponse {
564+
applications_response.push(ApplicationResponse {
529565
file: app_file,
530566
issue_reporter_handle: app.issue_reporter_handle,
531567
repo: app.repo,
@@ -534,7 +570,7 @@ impl LDNApplication {
534570
}
535571
}
536572
}
537-
Ok(all_apps)
573+
applications_response
538574
}
539575

540576
pub async fn active(

0 commit comments

Comments
 (0)