Created
September 29, 2022 16:05
-
-
Save j-griffith/9f139be8fd74cd817cb1cfaedac4d759 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/api/src/api.rs b/api/src/api.rs | |
index 7f70fa10..e189c24c 100644 | |
--- a/api/src/api.rs | |
+++ b/api/src/api.rs | |
@@ -163,30 +163,45 @@ impl Forge for Api { | |
.await | |
.map_err(CarbideError::from)?; | |
- let rpc::VpcSearchQuery { id, .. } = request.into_inner(); | |
- | |
- let _uuid = match id { | |
- Some(id) => match uuid::Uuid::try_from(id) { | |
- Ok(uuid) => UuidKeyedObjectFilter::One(uuid), | |
- Err(err) => { | |
- return Err(Status::invalid_argument(format!( | |
- "Supplied invalid UUID: {}", | |
- err | |
- ))); | |
- } | |
- }, | |
- None => UuidKeyedObjectFilter::All, | |
- }; | |
+ let rpc::VpcSearchQuery { id, name, .. } = request.into_inner(); | |
+ | |
+ // id always takes precedence, if no id in the request and only a name | |
+ // we'll find by name, otherwise if there's an id provided we always choose that | |
+ if name != None && id == None { | |
+ let result = Vpc::find_by_name(&mut txn, "foo".to_string()) | |
+ .await | |
+ .map(|vpc| rpc::VpcList { | |
+ vpcs: vpc.into_iter().map(rpc::Vpc::from).collect(), | |
+ }) | |
+ .map(Response::new) | |
+ .map_err(CarbideError::from)?; | |
+ Ok(result) | |
+ | |
+ } else { | |
+ let uuid = match id { | |
+ Some(id) => match uuid::Uuid::try_from(id) { | |
+ Ok(uuid) => UuidKeyedObjectFilter::One(uuid), | |
+ Err(err) => { | |
+ return Err(Status::invalid_argument(format!( | |
+ "Supplied invalid UUID: {}", | |
+ err | |
+ ))); | |
+ } | |
+ }, | |
+ // Should not happen, but need to handle the None match | |
+ None => UuidKeyedObjectFilter::All, | |
+ }; | |
+ let result = Vpc::find(&mut txn, uuid) | |
+ .await | |
+ .map(|vpc| rpc::VpcList { | |
+ vpcs: vpc.into_iter().map(rpc::Vpc::from).collect(), | |
+ }) | |
+ .map(Response::new) | |
+ .map_err(CarbideError::from)?; | |
+ Ok(result) | |
- let result = Vpc::find(&mut txn, _uuid) | |
- .await | |
- .map(|vpc| rpc::VpcList { | |
- vpcs: vpc.into_iter().map(rpc::Vpc::from).collect(), | |
- }) | |
- .map(Response::new) | |
- .map_err(CarbideError::from)?; | |
+ } | |
- Ok(result) | |
} | |
#[tracing::instrument(skip_all, fields(request = ?request.get_ref()))] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment