Skip to content

Commit

Permalink
refactor: use list struct for project lists (#1774)
Browse files Browse the repository at this point in the history
  • Loading branch information
chesedo authored May 16, 2024
1 parent f87b873 commit 7451353
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
4 changes: 2 additions & 2 deletions cargo-shuttle/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl ShuttleApiClient {
pub async fn get_projects_list(&self) -> Result<Vec<project::Response>> {
self.get("/projects".to_owned()).await
}
pub async fn get_projects_list_beta(&self) -> Result<Vec<project::ResponseBeta>> {
pub async fn get_projects_list_beta(&self) -> Result<project::ResponseListBeta> {
self.get("/projects".to_owned()).await
}

Expand All @@ -243,7 +243,7 @@ impl ShuttleApiClient {
pub async fn get_team_projects_list_beta(
&self,
team_id: &str,
) -> Result<Vec<project::ResponseBeta>> {
) -> Result<project::ResponseListBeta> {
self.get(format!("/teams/{team_id}/projects")).await
}

Expand Down
48 changes: 26 additions & 22 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2142,16 +2142,20 @@ impl Shuttle {
let client = self.client.as_ref().unwrap();

let projects_table = if self.beta {
project::get_projects_table_beta(&client.get_projects_list_beta().await.map_err(
|err| {
suggestions::project::project_request_failure(
err,
"Getting projects list failed",
false,
"getting the projects list fails repeatedly",
)
},
)?)
project::get_projects_table_beta(
&client
.get_projects_list_beta()
.await
.map_err(|err| {
suggestions::project::project_request_failure(
err,
"Getting projects list failed",
false,
"getting the projects list fails repeatedly",
)
})?
.projects,
)
} else {
project::get_projects_table(
&client.get_projects_list().await.map_err(|err| {
Expand All @@ -2173,18 +2177,18 @@ impl Shuttle {

for team in teams {
let team_projects_table = if self.beta {
let team_projects =
client
.get_team_projects_list_beta(&team.id)
.await
.map_err(|err| {
suggestions::project::project_request_failure(
err,
"Getting teams projects list failed",
false,
"getting the team projects list fails repeatedly",
)
})?;
let team_projects = client
.get_team_projects_list_beta(&team.id)
.await
.map_err(|err| {
suggestions::project::project_request_failure(
err,
"Getting teams projects list failed",
false,
"getting the team projects list fails repeatedly",
)
})?
.projects;
project::get_projects_table_beta(&team_projects)
} else {
let team_projects =
Expand Down
5 changes: 5 additions & 0 deletions common/src/models/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ pub struct ResponseBeta {
pub is_admin: bool,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
pub struct ResponseListBeta {
pub projects: Vec<ResponseBeta>,
}

#[derive(Clone, Debug, Deserialize, Serialize, EnumString)]
#[serde(rename_all = "lowercase")]
pub enum State {
Expand Down

0 comments on commit 7451353

Please sign in to comment.