From 9c954bb61584296af326e6838a33b2c7f3c6be8e Mon Sep 17 00:00:00 2001 From: Brendan O'Connell Date: Mon, 23 Sep 2024 16:50:46 +0200 Subject: [PATCH] Removed unnecessary if/let statements --- thoth-api/src/graphql/model.rs | 12 +++--------- thoth-api/src/model/location/crud.rs | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/thoth-api/src/graphql/model.rs b/thoth-api/src/graphql/model.rs index e39fe338..58489194 100644 --- a/thoth-api/src/graphql/model.rs +++ b/thoth-api/src/graphql/model.rs @@ -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 = None; let canonical_location = data.get_canonical_location(&context.db); let final_canonical_location = match canonical_location { @@ -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) } } diff --git a/thoth-api/src/model/location/crud.rs b/thoth-api/src/model/location/crud.rs index a8afef98..9497d947 100644 --- a/thoth-api/src/model/location/crud.rs +++ b/thoth-api/src/model/location/crud.rs @@ -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, @@ -207,7 +199,7 @@ impl PatchLocation { pub fn update_canonical_location( &self, - old_canonical_location: Option, + old_canonical_location: &PatchLocation, old_canonical_location_id: Uuid, db: &crate::db::PgPool ) -> ThothResult<()> { @@ -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(