Skip to content

Commit

Permalink
Removed unnecessary if/let statements
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan-oconnell committed Sep 23, 2024
1 parent 363d913 commit 9c954bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
12 changes: 3 additions & 9 deletions thoth-api/src/graphql/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2001,7 +2001,6 @@ impl MutationRoot {
// if user changes a non-canonical location to canonical, perform two simultaneous updates:
// change the old canonical location to non-canonical, and change the old non-canonical location to canonical
} else {
let mut old_canonical_location_id: Option<Uuid> = None;
let canonical_location = data.get_canonical_location(&context.db);

let final_canonical_location = match canonical_location {
Expand All @@ -2011,21 +2010,16 @@ impl MutationRoot {
}
};

let old_canonical_location = Some(PatchLocation {
let old_canonical_location = PatchLocation {
location_id: final_canonical_location.location_id,
publication_id: final_canonical_location.publication_id,
landing_page: final_canonical_location.landing_page.clone(),
full_text_url: final_canonical_location.full_text_url.clone(),
location_platform: final_canonical_location.location_platform.clone(),
canonical: false,
});
if let Some(ref old_canonical_location) = old_canonical_location {
old_canonical_location_id = Some(old_canonical_location.location_id);
}
};

if let Some(old_canonical_location_id) = old_canonical_location_id {
let _ = data.update_canonical_location(old_canonical_location, old_canonical_location_id, &context.db);
}
let _ = data.update_canonical_location(&old_canonical_location, old_canonical_location.location_id, &context.db);
Ok(location)
}
}
Expand Down
19 changes: 10 additions & 9 deletions thoth-api/src/model/location/crud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,6 @@ impl NewLocation {
}

impl PatchLocation {
pub fn canonical_record_complete(&self, db: &crate::db::PgPool) -> ThothResult<()> {
location_canonical_record_complete(
self.publication_id,
&self.landing_page,
&self.full_text_url,
db,
)
}

pub fn get_canonical_location(
&self,
Expand All @@ -207,7 +199,7 @@ impl PatchLocation {

pub fn update_canonical_location(
&self,
old_canonical_location: Option<PatchLocation>,
old_canonical_location: &PatchLocation,
old_canonical_location_id: Uuid,
db: &crate::db::PgPool
) -> ThothResult<()> {
Expand All @@ -229,6 +221,15 @@ impl PatchLocation {
Ok(())

}

pub fn canonical_record_complete(&self, db: &crate::db::PgPool) -> ThothResult<()> {
location_canonical_record_complete(
self.publication_id,
&self.landing_page,
&self.full_text_url,
db,
)
}
}

fn location_canonical_record_complete(
Expand Down

0 comments on commit 9c954bb

Please sign in to comment.