diff --git a/agent_api_rest/postman/ssi-agent.postman_collection.json b/agent_api_rest/postman/ssi-agent.postman_collection.json index 924b87ad..84802c04 100644 --- a/agent_api_rest/postman/ssi-agent.postman_collection.json +++ b/agent_api_rest/postman/ssi-agent.postman_collection.json @@ -118,6 +118,46 @@ }, "response": [] }, + { + "name": "all_credentials", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "" + ], + "type": "text/javascript", + "packages": {} + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript", + "packages": {} + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{HOST}}/v0/credentials", + "host": [ + "{{HOST}}" + ], + "path": [ + "v0", + "credentials" + ] + } + }, + "response": [] + }, { "name": "offers", "event": [ @@ -177,6 +217,46 @@ }, "response": [] }, + { + "name": "all_offers", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "" + ], + "type": "text/javascript", + "packages": {} + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript", + "packages": {} + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{HOST}}/v0/offers", + "host": [ + "{{HOST}}" + ], + "path": [ + "v0", + "offers" + ] + } + }, + "response": [] + }, { "name": "offers_send", "request": { diff --git a/agent_api_rest/src/holder/holder/credentials/mod.rs b/agent_api_rest/src/holder/holder/credentials/mod.rs index c18e9f71..76c53cb2 100644 --- a/agent_api_rest/src/holder/holder/credentials/mod.rs +++ b/agent_api_rest/src/holder/holder/credentials/mod.rs @@ -10,7 +10,7 @@ use serde_json::json; #[axum_macros::debug_handler] pub(crate) async fn credentials(State(state): State) -> Response { - match query_handler("all_credentials", &state.query.all_credentials).await { + match query_handler("all_holder_credentials", &state.query.all_holder_credentials).await { Ok(Some(all_credentials_view)) => (StatusCode::OK, Json(all_credentials_view)).into_response(), Ok(None) => (StatusCode::OK, Json(json!({}))).into_response(), _ => StatusCode::INTERNAL_SERVER_ERROR.into_response(), diff --git a/agent_api_rest/src/holder/holder/offers/accept.rs b/agent_api_rest/src/holder/holder/offers/accept.rs index ee3f819a..9022f14b 100644 --- a/agent_api_rest/src/holder/holder/offers/accept.rs +++ b/agent_api_rest/src/holder/holder/offers/accept.rs @@ -1,6 +1,6 @@ use agent_holder::{ credential::command::CredentialCommand, - offer::{command::OfferCommand, queries::OfferView}, + offer::{command::OfferCommand, queries::ReceivedOfferView}, state::HolderState, }; use agent_shared::handlers::{command_handler, query_handler}; @@ -18,8 +18,8 @@ pub(crate) async fn accept(State(state): State, Path(offer_id): Pat // Furthermore, the Application Layer (not implemented yet) should be kept very thin as well. See: https://github.com/impierce/ssi-agent/issues/114 // Accept the Credential Offer if it exists - match query_handler(&offer_id, &state.query.offer).await { - Ok(Some(OfferView { .. })) => { + match query_handler(&offer_id, &state.query.received_offer).await { + Ok(Some(ReceivedOfferView { .. })) => { let command = OfferCommand::AcceptCredentialOffer { offer_id: offer_id.clone(), }; @@ -45,8 +45,8 @@ pub(crate) async fn accept(State(state): State, Path(offer_id): Pat return StatusCode::INTERNAL_SERVER_ERROR.into_response(); } - let credentials = match query_handler(&offer_id, &state.query.offer).await { - Ok(Some(OfferView { credentials, .. })) => credentials, + let credentials = match query_handler(&offer_id, &state.query.received_offer).await { + Ok(Some(ReceivedOfferView { credentials, .. })) => credentials, _ => return StatusCode::INTERNAL_SERVER_ERROR.into_response(), }; diff --git a/agent_api_rest/src/holder/holder/offers/mod.rs b/agent_api_rest/src/holder/holder/offers/mod.rs index a5130017..d674cec6 100644 --- a/agent_api_rest/src/holder/holder/offers/mod.rs +++ b/agent_api_rest/src/holder/holder/offers/mod.rs @@ -13,7 +13,7 @@ use serde_json::json; #[axum_macros::debug_handler] pub(crate) async fn offers(State(state): State) -> Response { - match query_handler("all_offers", &state.query.all_offers).await { + match query_handler("all_received_offers", &state.query.all_received_offers).await { Ok(Some(all_offers_view)) => (StatusCode::OK, Json(all_offers_view)).into_response(), Ok(None) => (StatusCode::OK, Json(json!({}))).into_response(), _ => StatusCode::INTERNAL_SERVER_ERROR.into_response(), diff --git a/agent_api_rest/src/issuance/credentials.rs b/agent_api_rest/src/issuance/credentials.rs index f8ea8a11..41e3a56e 100644 --- a/agent_api_rest/src/issuance/credentials.rs +++ b/agent_api_rest/src/issuance/credentials.rs @@ -17,6 +17,8 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; use tracing::info; +use serde_json::json; + #[axum_macros::debug_handler] pub(crate) async fn get_credentials(State(state): State, Path(credential_id): Path) -> Response { // Get the credential if it exists. @@ -160,6 +162,15 @@ pub(crate) async fn credentials( } } +#[axum_macros::debug_handler] +pub(crate) async fn all_credentials(State(state): State) -> Response { + match query_handler("all_credentials", &state.query.all_credentials).await { + Ok(Some(all_credentials_view)) => (StatusCode::OK, Json(all_credentials_view)).into_response(), + Ok(None) => (StatusCode::OK, Json(json!({}))).into_response(), + _ => StatusCode::INTERNAL_SERVER_ERROR.into_response(), + } +} + #[cfg(test)] pub mod tests { use super::*; diff --git a/agent_api_rest/src/issuance/mod.rs b/agent_api_rest/src/issuance/mod.rs index 0bf4064e..be505596 100644 --- a/agent_api_rest/src/issuance/mod.rs +++ b/agent_api_rest/src/issuance/mod.rs @@ -5,6 +5,8 @@ pub mod offers; use agent_issuance::state::IssuanceState; use axum::routing::get; use axum::{routing::post, Router}; +use credentials::all_credentials; +use offers::all_offers; use crate::issuance::{ credential_issuer::{ @@ -21,9 +23,9 @@ pub fn router(issuance_state: IssuanceState) -> Router { .nest( API_VERSION, Router::new() - .route("/credentials", post(credentials)) + .route("/credentials", post(credentials).get(all_credentials)) .route("/credentials/:credential_id", get(get_credentials)) - .route("/offers", post(offers)) + .route("/offers", post(offers).get(all_offers)) .route("/offers/send", post(send)), ) .route( diff --git a/agent_api_rest/src/issuance/offers/mod.rs b/agent_api_rest/src/issuance/offers/mod.rs index 06900dfb..491ac021 100644 --- a/agent_api_rest/src/issuance/offers/mod.rs +++ b/agent_api_rest/src/issuance/offers/mod.rs @@ -13,6 +13,7 @@ use axum::{ }; use hyper::header; use serde::{Deserialize, Serialize}; +use serde_json::json; use serde_json::Value; use tracing::info; @@ -81,6 +82,15 @@ pub(crate) async fn offers(State(state): State, Json(payload): Js } } +#[axum_macros::debug_handler] +pub(crate) async fn all_offers(State(state): State) -> Response { + match query_handler("all_offers", &state.query.all_offers).await { + Ok(Some(all_offers_view)) => (StatusCode::OK, Json(all_offers_view)).into_response(), + Ok(None) => (StatusCode::OK, Json(json!({}))).into_response(), + _ => StatusCode::INTERNAL_SERVER_ERROR.into_response(), + } +} + #[cfg(test)] pub mod tests { use super::*; diff --git a/agent_application/docker/db/init.sql b/agent_application/docker/db/init.sql index f333905c..e8d2d537 100644 --- a/agent_application/docker/db/init.sql +++ b/agent_application/docker/db/init.sql @@ -18,6 +18,14 @@ CREATE TABLE offer PRIMARY KEY (view_id) ); +CREATE TABLE all_offers +( + view_id text NOT NULL, + version bigint CHECK (version >= 0) NOT NULL, + payload json NOT NULL, + PRIMARY KEY (view_id) +); + CREATE TABLE pre_authorized_code ( view_id text NOT NULL, @@ -42,6 +50,14 @@ CREATE TABLE credential PRIMARY KEY (view_id) ); +CREATE TABLE all_credentials +( + view_id text NOT NULL, + version bigint CHECK (version >= 0) NOT NULL, + payload json NOT NULL, + PRIMARY KEY (view_id) +); + CREATE TABLE server_config ( view_id text NOT NULL, @@ -58,7 +74,7 @@ CREATE TABLE received_offer PRIMARY KEY (view_id) ); -CREATE TABLE all_offers +CREATE TABLE all_received_offers ( view_id text NOT NULL, version bigint CHECK (version >= 0) NOT NULL, @@ -75,7 +91,7 @@ CREATE TABLE holder_credential ); -CREATE TABLE all_credentials +CREATE TABLE all_holder_credentials ( view_id text NOT NULL, version bigint CHECK (version >= 0) NOT NULL, diff --git a/agent_holder/src/credential/queries/all_credentials.rs b/agent_holder/src/credential/queries/all_credentials.rs index 48000182..a0296451 100644 --- a/agent_holder/src/credential/queries/all_credentials.rs +++ b/agent_holder/src/credential/queries/all_credentials.rs @@ -1,16 +1,16 @@ -use super::CredentialView; +use super::HolderCredentialView; use crate::credential::queries::Credential; use cqrs_es::{EventEnvelope, View}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; #[derive(Debug, Default, Serialize, Deserialize, Clone)] -pub struct AllCredentialsView { +pub struct AllHolderCredentialsView { #[serde(flatten)] - pub credentials: HashMap, + pub credentials: HashMap, } -impl View for AllCredentialsView { +impl View for AllHolderCredentialsView { fn update(&mut self, event: &EventEnvelope) { self.credentials // Get the entry for the aggregate_id diff --git a/agent_holder/src/credential/queries/mod.rs b/agent_holder/src/credential/queries/mod.rs index 007f0255..125054ea 100644 --- a/agent_holder/src/credential/queries/mod.rs +++ b/agent_holder/src/credential/queries/mod.rs @@ -6,13 +6,13 @@ use cqrs_es::{EventEnvelope, View}; use serde::{Deserialize, Serialize}; #[derive(Debug, Default, Serialize, Deserialize, Clone)] -pub struct CredentialView { +pub struct HolderCredentialView { pub credential_id: Option, pub offer_id: Option, pub credential: Option, } -impl View for CredentialView { +impl View for HolderCredentialView { fn update(&mut self, event: &EventEnvelope) { use CredentialEvent::*; diff --git a/agent_holder/src/offer/queries/all_offers.rs b/agent_holder/src/offer/queries/all_offers.rs index b9696bba..5c32922a 100644 --- a/agent_holder/src/offer/queries/all_offers.rs +++ b/agent_holder/src/offer/queries/all_offers.rs @@ -1,16 +1,16 @@ -use super::OfferView; +use super::ReceivedOfferView; use crate::offer::queries::Offer; use cqrs_es::{EventEnvelope, View}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; #[derive(Debug, Default, Serialize, Deserialize, Clone)] -pub struct AllOffersView { +pub struct AllReceivedOffersView { #[serde(flatten)] - pub offers: HashMap, + pub offers: HashMap, } -impl View for AllOffersView { +impl View for AllReceivedOffersView { fn update(&mut self, event: &EventEnvelope) { self.offers // Get the entry for the aggregate_id diff --git a/agent_holder/src/offer/queries/mod.rs b/agent_holder/src/offer/queries/mod.rs index ad13bde1..05bae107 100644 --- a/agent_holder/src/offer/queries/mod.rs +++ b/agent_holder/src/offer/queries/mod.rs @@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize}; use std::collections::HashMap; #[derive(Debug, Default, Serialize, Deserialize, Clone)] -pub struct OfferView { +pub struct ReceivedOfferView { pub credential_offer: Option, pub status: Status, pub credential_configurations: Option>, @@ -19,7 +19,7 @@ pub struct OfferView { pub credentials: Vec, } -impl View for OfferView { +impl View for ReceivedOfferView { fn update(&mut self, event: &EventEnvelope) { use crate::offer::event::OfferEvent::*; diff --git a/agent_holder/src/state.rs b/agent_holder/src/state.rs index 2ebbddf4..cef3ff26 100644 --- a/agent_holder/src/state.rs +++ b/agent_holder/src/state.rs @@ -3,11 +3,11 @@ use cqrs_es::persist::ViewRepository; use std::sync::Arc; use crate::credential::aggregate::Credential; -use crate::credential::queries::all_credentials::AllCredentialsView; -use crate::credential::queries::CredentialView; +use crate::credential::queries::all_credentials::AllHolderCredentialsView; +use crate::credential::queries::HolderCredentialView; use crate::offer::aggregate::Offer; -use crate::offer::queries::all_offers::AllOffersView; -use crate::offer::queries::OfferView; +use crate::offer::queries::all_offers::AllReceivedOffersView; +use crate::offer::queries::ReceivedOfferView; #[derive(Clone)] pub struct HolderState { @@ -26,32 +26,32 @@ pub struct CommandHandlers { /// that any type of repository that implements the `ViewRepository` trait can be used, but the corresponding `View` and /// `Aggregate` types must be the same. type Queries = ViewRepositories< - dyn ViewRepository, - dyn ViewRepository, - dyn ViewRepository, - dyn ViewRepository, + dyn ViewRepository, + dyn ViewRepository, + dyn ViewRepository, + dyn ViewRepository, >; pub struct ViewRepositories where - C1: ViewRepository + ?Sized, - C2: ViewRepository + ?Sized, - O1: ViewRepository + ?Sized, - O2: ViewRepository + ?Sized, + C1: ViewRepository + ?Sized, + C2: ViewRepository + ?Sized, + O1: ViewRepository + ?Sized, + O2: ViewRepository + ?Sized, { - pub credential: Arc, - pub all_credentials: Arc, - pub offer: Arc, - pub all_offers: Arc, + pub holder_credential: Arc, + pub all_holder_credentials: Arc, + pub received_offer: Arc, + pub all_received_offers: Arc, } impl Clone for Queries { fn clone(&self) -> Self { ViewRepositories { - credential: self.credential.clone(), - all_credentials: self.all_credentials.clone(), - offer: self.offer.clone(), - all_offers: self.all_offers.clone(), + holder_credential: self.holder_credential.clone(), + all_holder_credentials: self.all_holder_credentials.clone(), + received_offer: self.received_offer.clone(), + all_received_offers: self.all_received_offers.clone(), } } } diff --git a/agent_issuance/src/credential/queries/all_credentials.rs b/agent_issuance/src/credential/queries/all_credentials.rs new file mode 100644 index 00000000..48000182 --- /dev/null +++ b/agent_issuance/src/credential/queries/all_credentials.rs @@ -0,0 +1,23 @@ +use super::CredentialView; +use crate::credential::queries::Credential; +use cqrs_es::{EventEnvelope, View}; +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; + +#[derive(Debug, Default, Serialize, Deserialize, Clone)] +pub struct AllCredentialsView { + #[serde(flatten)] + pub credentials: HashMap, +} + +impl View for AllCredentialsView { + fn update(&mut self, event: &EventEnvelope) { + self.credentials + // Get the entry for the aggregate_id + .entry(event.aggregate_id.clone()) + // or insert a new one if it doesn't exist + .or_default() + // update the view with the event + .update(event); + } +} diff --git a/agent_issuance/src/credential/queries.rs b/agent_issuance/src/credential/queries/mod.rs similarity index 97% rename from agent_issuance/src/credential/queries.rs rename to agent_issuance/src/credential/queries/mod.rs index 3c23c98d..dccea99e 100644 --- a/agent_issuance/src/credential/queries.rs +++ b/agent_issuance/src/credential/queries/mod.rs @@ -1,3 +1,5 @@ +pub mod all_credentials; + use super::{entity::Data, event::CredentialEvent}; use crate::credential::aggregate::Credential; use cqrs_es::{EventEnvelope, View}; diff --git a/agent_issuance/src/offer/queries/all_offers.rs b/agent_issuance/src/offer/queries/all_offers.rs new file mode 100644 index 00000000..b9696bba --- /dev/null +++ b/agent_issuance/src/offer/queries/all_offers.rs @@ -0,0 +1,23 @@ +use super::OfferView; +use crate::offer::queries::Offer; +use cqrs_es::{EventEnvelope, View}; +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; + +#[derive(Debug, Default, Serialize, Deserialize, Clone)] +pub struct AllOffersView { + #[serde(flatten)] + pub offers: HashMap, +} + +impl View for AllOffersView { + fn update(&mut self, event: &EventEnvelope) { + self.offers + // Get the entry for the aggregate_id + .entry(event.aggregate_id.clone()) + // or insert a new one if it doesn't exist + .or_default() + // update the view with the event + .update(event); + } +} diff --git a/agent_issuance/src/offer/queries/mod.rs b/agent_issuance/src/offer/queries/mod.rs index 806f7240..a32544a0 100644 --- a/agent_issuance/src/offer/queries/mod.rs +++ b/agent_issuance/src/offer/queries/mod.rs @@ -1,4 +1,5 @@ pub mod access_token; +pub mod all_offers; pub mod pre_authorized_code; use super::event::OfferEvent; diff --git a/agent_issuance/src/state.rs b/agent_issuance/src/state.rs index 4384deb6..2f520eb9 100644 --- a/agent_issuance/src/state.rs +++ b/agent_issuance/src/state.rs @@ -5,9 +5,11 @@ use std::sync::Arc; use tracing::{info, warn}; use crate::credential::aggregate::Credential; +use crate::credential::queries::all_credentials::AllCredentialsView; use crate::credential::queries::CredentialView; use crate::offer::aggregate::Offer; use crate::offer::queries::access_token::AccessTokenView; +use crate::offer::queries::all_offers::AllOffersView; use crate::offer::queries::pre_authorized_code::PreAuthorizedCodeView; use crate::offer::queries::OfferView; use crate::server_config::aggregate::ServerConfig; @@ -34,24 +36,30 @@ pub struct CommandHandlers { type Queries = ViewRepositories< dyn ViewRepository, dyn ViewRepository, + dyn ViewRepository, dyn ViewRepository, + dyn ViewRepository, dyn ViewRepository, dyn ViewRepository, >; -pub struct ViewRepositories +pub struct ViewRepositories where SC: ViewRepository + ?Sized, C: ViewRepository + ?Sized, + C1: ViewRepository + ?Sized, O: ViewRepository + ?Sized, - O1: ViewRepository + ?Sized, - O2: ViewRepository + ?Sized, + O1: ViewRepository + ?Sized, + O2: ViewRepository + ?Sized, + O3: ViewRepository + ?Sized, { pub server_config: Arc, pub credential: Arc, + pub all_credentials: Arc, pub offer: Arc, - pub pre_authorized_code: Arc, - pub access_token: Arc, + pub all_offers: Arc, + pub pre_authorized_code: Arc, + pub access_token: Arc, } impl Clone for Queries { @@ -59,7 +67,9 @@ impl Clone for Queries { ViewRepositories { server_config: self.server_config.clone(), credential: self.credential.clone(), + all_credentials: self.all_credentials.clone(), offer: self.offer.clone(), + all_offers: self.all_offers.clone(), pre_authorized_code: self.pre_authorized_code.clone(), access_token: self.access_token.clone(), } diff --git a/agent_store/src/in_memory.rs b/agent_store/src/in_memory.rs index 5e5fef7d..b95316dc 100644 --- a/agent_store/src/in_memory.rs +++ b/agent_store/src/in_memory.rs @@ -121,15 +121,20 @@ pub async fn issuance_state( ) -> IssuanceState { // Initialize the in-memory repositories. let server_config = Arc::new(MemRepository::default()); - let credential = Arc::new(MemRepository::default()); - let offer = Arc::new(MemRepository::default()); let pre_authorized_code = Arc::new(MemRepository::::new()); let access_token = Arc::new(MemRepository::::new()); + let credential = Arc::new(MemRepository::default()); + let offer = Arc::new(MemRepository::default()); + let all_credentials = Arc::new(MemRepository::default()); + let all_offers = Arc::new(MemRepository::default()); // Create custom-queries for the offer aggregate. let pre_authorized_code_query = PreAuthorizedCodeQuery::new(pre_authorized_code.clone()); let access_token_query = AccessTokenQuery::new(access_token.clone()); + let all_credentials_query = ListAllQuery::new(all_credentials.clone(), "all_credentials"); + let all_offers_query = ListAllQuery::new(all_offers.clone(), "all_offers"); + // Partition the event_publishers into the different aggregates. let (server_config_event_publishers, credential_event_publishers, offer_event_publishers, _, _, _, _) = partition_event_publishers(event_publishers); @@ -148,7 +153,8 @@ pub async fn issuance_state( credential_event_publishers.into_iter().fold( AggregateHandler::new(issuance_services.clone()) .append_query(SimpleLoggingQuery {}) - .append_query(generic_query(credential.clone())), + .append_query(generic_query(credential.clone())) + .append_query(all_credentials_query), |aggregate_handler, event_publisher| aggregate_handler.append_event_publisher(event_publisher), ), ), @@ -157,6 +163,7 @@ pub async fn issuance_state( AggregateHandler::new(issuance_services) .append_query(SimpleLoggingQuery {}) .append_query(generic_query(offer.clone())) + .append_query(all_offers_query) .append_query(pre_authorized_code_query) .append_query(access_token_query), |aggregate_handler, event_publisher| aggregate_handler.append_event_publisher(event_publisher), @@ -165,10 +172,12 @@ pub async fn issuance_state( }, query: ViewRepositories { server_config, - credential, - offer, pre_authorized_code, access_token, + credential, + all_credentials, + offer, + all_offers, }, } } @@ -178,14 +187,14 @@ pub async fn holder_state( event_publishers: Vec>, ) -> HolderState { // Initialize the in-memory repositories. - let credential = Arc::new(MemRepository::default()); - let offer = Arc::new(MemRepository::default()); - let all_credentials = Arc::new(MemRepository::default()); - let all_offers = Arc::new(MemRepository::default()); + let holder_credential = Arc::new(MemRepository::default()); + let received_offer = Arc::new(MemRepository::default()); + let all_holder_credentials = Arc::new(MemRepository::default()); + let all_received_offers = Arc::new(MemRepository::default()); // Create custom-queries for the offer aggregate. - let all_credentials_query = ListAllQuery::new(all_credentials.clone(), "all_credentials"); - let all_offers_query = ListAllQuery::new(all_offers.clone(), "all_offers"); + let all_holder_credentials_query = ListAllQuery::new(all_holder_credentials.clone(), "all_holder_credentials"); + let all_received_offers_query = ListAllQuery::new(all_received_offers.clone(), "all_received_offers"); // Partition the event_publishers into the different aggregates. let (_, _, _, credential_event_publishers, offer_event_publishers, _, _) = @@ -197,8 +206,8 @@ pub async fn holder_state( credential_event_publishers.into_iter().fold( AggregateHandler::new(holder_services.clone()) .append_query(SimpleLoggingQuery {}) - .append_query(generic_query(credential.clone())) - .append_query(all_credentials_query), + .append_query(generic_query(holder_credential.clone())) + .append_query(all_holder_credentials_query), |aggregate_handler, event_publisher| aggregate_handler.append_event_publisher(event_publisher), ), ), @@ -206,17 +215,17 @@ pub async fn holder_state( offer_event_publishers.into_iter().fold( AggregateHandler::new(holder_services.clone()) .append_query(SimpleLoggingQuery {}) - .append_query(generic_query(offer.clone())) - .append_query(all_offers_query), + .append_query(generic_query(received_offer.clone())) + .append_query(all_received_offers_query), |aggregate_handler, event_publisher| aggregate_handler.append_event_publisher(event_publisher), ), ), }, query: agent_holder::state::ViewRepositories { - credential, - all_credentials, - offer, - all_offers, + holder_credential, + all_holder_credentials, + received_offer, + all_received_offers, }, } } diff --git a/agent_store/src/postgres.rs b/agent_store/src/postgres.rs index 5a91de7e..7b704f2e 100644 --- a/agent_store/src/postgres.rs +++ b/agent_store/src/postgres.rs @@ -76,10 +76,12 @@ pub async fn issuance_state( // Initialize the postgres repositories. let server_config = Arc::new(PostgresViewRepository::new("server_config", pool.clone())); - let credential = Arc::new(PostgresViewRepository::new("credential", pool.clone())); - let offer = Arc::new(PostgresViewRepository::new("offer", pool.clone())); let pre_authorized_code = Arc::new(PostgresViewRepository::new("pre_authorized_code", pool.clone())); let access_token = Arc::new(PostgresViewRepository::new("access_token", pool.clone())); + let credential = Arc::new(PostgresViewRepository::new("credential", pool.clone())); + let all_credentials = Arc::new(PostgresViewRepository::new("all_credentials", pool.clone())); + let offer = Arc::new(PostgresViewRepository::new("offer", pool.clone())); + let all_offers = Arc::new(PostgresViewRepository::new("all_offers", pool.clone())); // Create custom-queries for the offer aggregate. let pre_authorized_code_query = PreAuthorizedCodeQuery::new(pre_authorized_code.clone()); @@ -89,6 +91,10 @@ pub async fn issuance_state( let (server_config_event_publishers, credential_event_publishers, offer_event_publishers, _, _, _, _) = partition_event_publishers(event_publishers); + // Create custom-queries for the offer aggregate. + let all_credentials_query = ListAllQuery::new(all_credentials.clone(), "all_credentials"); + let all_offers_query = ListAllQuery::new(all_offers.clone(), "all_offers"); + IssuanceState { command: CommandHandlers { server_config: Arc::new( @@ -103,7 +109,8 @@ pub async fn issuance_state( credential_event_publishers.into_iter().fold( AggregateHandler::new(pool.clone(), issuance_services.clone()) .append_query(SimpleLoggingQuery {}) - .append_query(generic_query(credential.clone())), + .append_query(generic_query(credential.clone())) + .append_query(all_credentials_query), |aggregate_handler, event_publisher| aggregate_handler.append_event_publisher(event_publisher), ), ), @@ -112,6 +119,7 @@ pub async fn issuance_state( AggregateHandler::new(pool.clone(), issuance_services) .append_query(SimpleLoggingQuery {}) .append_query(generic_query(offer.clone())) + .append_query(all_offers_query) .append_query(pre_authorized_code_query) .append_query(access_token_query), |aggregate_handler, event_publisher| aggregate_handler.append_event_publisher(event_publisher), @@ -120,10 +128,12 @@ pub async fn issuance_state( }, query: ViewRepositories { server_config, - credential, - offer, pre_authorized_code, access_token, + credential, + all_credentials, + offer, + all_offers, }, } } @@ -138,16 +148,16 @@ pub async fn holder_state( let pool = default_postgress_pool(&connection_string).await; // Initialize the postgres repositories. - let credential: Arc> = + let holder_credential: Arc> = Arc::new(PostgresViewRepository::new("holder_credential", pool.clone())); - let all_credentials: Arc> = - Arc::new(PostgresViewRepository::new("all_credentials", pool.clone())); - let offer = Arc::new(PostgresViewRepository::new("received_offer", pool.clone())); - let all_offers = Arc::new(PostgresViewRepository::new("all_offers", pool.clone())); + let all_holder_credentials: Arc> = + Arc::new(PostgresViewRepository::new("all_holder_credentials", pool.clone())); + let received_offer = Arc::new(PostgresViewRepository::new("received_offer", pool.clone())); + let all_received_offers = Arc::new(PostgresViewRepository::new("all_received_offers", pool.clone())); // Create custom-queries for the offer aggregate. - let all_credentials_query = ListAllQuery::new(all_credentials.clone(), "all_credentials"); - let all_offers_query = ListAllQuery::new(all_offers.clone(), "all_offers"); + let all_holder_credentials_query = ListAllQuery::new(all_holder_credentials.clone(), "all_holder_credentials"); + let all_received_offers_query = ListAllQuery::new(all_received_offers.clone(), "all_received_offers"); // Partition the event_publishers into the different aggregates. let (_, _, _, credential_event_publishers, offer_event_publishers, _, _) = @@ -159,8 +169,8 @@ pub async fn holder_state( credential_event_publishers.into_iter().fold( AggregateHandler::new(pool.clone(), holder_services.clone()) .append_query(SimpleLoggingQuery {}) - .append_query(generic_query(credential.clone())) - .append_query(all_credentials_query), + .append_query(generic_query(holder_credential.clone())) + .append_query(all_holder_credentials_query), |aggregate_handler, event_publisher| aggregate_handler.append_event_publisher(event_publisher), ), ), @@ -168,17 +178,17 @@ pub async fn holder_state( offer_event_publishers.into_iter().fold( AggregateHandler::new(pool, holder_services.clone()) .append_query(SimpleLoggingQuery {}) - .append_query(generic_query(offer.clone())) - .append_query(all_offers_query), + .append_query(generic_query(received_offer.clone())) + .append_query(all_received_offers_query), |aggregate_handler, event_publisher| aggregate_handler.append_event_publisher(event_publisher), ), ), }, query: agent_holder::state::ViewRepositories { - credential, - all_credentials, - offer, - all_offers, + holder_credential, + all_holder_credentials, + received_offer, + all_received_offers, }, } }