Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change all All<aggregate-type>View formats from HashMap to Vec #124

Open
1 task
nanderstabel opened this issue Sep 27, 2024 · 0 comments
Open
1 task

Change all All<aggregate-type>View formats from HashMap to Vec #124

nanderstabel opened this issue Sep 27, 2024 · 0 comments
Assignees
Labels
Breaking change A change to the API that requires a major release. Enhancement New feature or improvement to an existing feature

Comments

@nanderstabel
Copy link
Collaborator

Description

For example this struct:

#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct AllReceivedOffersView {
    #[serde(flatten)]
    pub offers: HashMap<String, ReceivedOfferView>,
}

impl View<Offer> for AllReceivedOffersView {
    fn update(&mut self, event: &EventEnvelope<Offer>) {
        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);
    }
}

Needs to be re-written to something like (pseudo-code):

#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct AllReceivedOffersView {
    pub offers: Vec<ReceivedOfferView>,
}

impl View<Offer> for AllReceivedOffersView {
    fn update(&mut self, event: &EventEnvelope<Offer>) {
        self.offers.push(event)
    }
}

To find all structs that need to be adjusted search for this code snippet (there should be 4):

            // 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);

Important is that for each Vector item type, there needs to be a ..._id field present. For example in the example above, the ID field needs to be added to ReceivedOfferView. In turn, this means that there needs to be an ID field added to Offer as well.

The end goal is that for all endpoints (there should be 4) that return All Credentials/Offers, the response type must change from an object {} to a list [] where all items in the list contain an ID field.

Motivation

Better API Response types.

Resources

n/a

To-do List

  • ..
@nanderstabel nanderstabel added Breaking change A change to the API that requires a major release. Enhancement New feature or improvement to an existing feature labels Sep 27, 2024
@Oran-Dan Oran-Dan self-assigned this Oct 5, 2024
@nanderstabel nanderstabel self-assigned this Oct 9, 2024
@nanderstabel nanderstabel mentioned this issue Oct 9, 2024
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking change A change to the API that requires a major release. Enhancement New feature or improvement to an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants