Skip to content

Commit

Permalink
style: box CredentialConfigurationsSupportedObject (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
nanderstabel authored Nov 19, 2024
1 parent d284e8a commit 731032a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
46 changes: 24 additions & 22 deletions agent_api_rest/src/issuance/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,31 @@ pub(crate) async fn credentials(

let credential_id = uuid::Uuid::new_v4().to_string();

let credential_configuration = match query_handler(SERVER_CONFIG_ID, &state.query.server_config).await {
Ok(Some(ServerConfigView {
credential_issuer_metadata:
Some(CredentialIssuerMetadata {
credential_configurations_supported,
..
}),
..
})) => {
if let Some(credential_configuration) =
credential_configurations_supported.get(&credential_configuration_id)
{
credential_configuration.clone()
} else {
return (
StatusCode::NOT_FOUND,
format!("No Credential Configuration found with id: `{credential_configuration_id}`"),
)
.into_response();
let credential_configuration = Box::new(
match query_handler(SERVER_CONFIG_ID, &state.query.server_config).await {
Ok(Some(ServerConfigView {
credential_issuer_metadata:
Some(CredentialIssuerMetadata {
credential_configurations_supported,
..
}),
..
})) => {
if let Some(credential_configuration) =
credential_configurations_supported.get(&credential_configuration_id)
{
credential_configuration.clone()
} else {
return (
StatusCode::NOT_FOUND,
format!("No Credential Configuration found with id: `{credential_configuration_id}`"),
)
.into_response();
}
}
}
_ => return StatusCode::INTERNAL_SERVER_ERROR.into_response(),
};
_ => return StatusCode::INTERNAL_SERVER_ERROR.into_response(),
},
);

let command = if is_signed {
CredentialCommand::CreateSignedCredential {
Expand Down
8 changes: 4 additions & 4 deletions agent_issuance/src/credential/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl Aggregate for Credential {
credential_configuration,
} => {
self.data.replace(data);
self.credential_configuration = credential_configuration;
self.credential_configuration = *credential_configuration;
}
SignedCredentialCreated { signed_credential } => {
self.signed.replace(signed_credential);
Expand Down Expand Up @@ -295,13 +295,13 @@ pub mod credential_tests {
data: Data {
raw: credential_subject,
},
credential_configuration: credential_configuration.clone(),
credential_configuration: Box::new(credential_configuration.clone()),
})
.then_expect_events(vec![CredentialEvent::UnsignedCredentialCreated {
data: Data {
raw: unsigned_credential,
},
credential_configuration,
credential_configuration: Box::new(credential_configuration),
}])
}

Expand All @@ -327,7 +327,7 @@ pub mod credential_tests {
data: Data {
raw: unsigned_credential,
},
credential_configuration,
credential_configuration: Box::new(credential_configuration),
}])
.when(CredentialCommand::SignCredential {
subject_id: SUBJECT_KEY_DID.identifier("did:key", Algorithm::EdDSA).await.unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion agent_issuance/src/credential/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::entity::Data;
pub enum CredentialCommand {
CreateUnsignedCredential {
data: Data,
credential_configuration: CredentialConfigurationsSupportedObject,
credential_configuration: Box<CredentialConfigurationsSupportedObject>,
},
CreateSignedCredential {
signed_credential: serde_json::Value,
Expand Down
2 changes: 1 addition & 1 deletion agent_issuance/src/credential/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub enum CredentialEvent {
// TODO: rename to `DataCredentialCreated`?
UnsignedCredentialCreated {
data: Data,
credential_configuration: CredentialConfigurationsSupportedObject,
credential_configuration: Box<CredentialConfigurationsSupportedObject>,
},
SignedCredentialCreated {
signed_credential: serde_json::Value,
Expand Down
2 changes: 1 addition & 1 deletion agent_issuance/src/credential/queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl View<Credential> for CredentialView {
credential_configuration,
} => {
self.data.replace(data.clone());
self.credential_configuration = credential_configuration.clone();
self.credential_configuration = *credential_configuration.clone();
}
CredentialEvent::SignedCredentialCreated { signed_credential } => {
self.signed.replace(signed_credential.clone());
Expand Down

0 comments on commit 731032a

Please sign in to comment.