Skip to content

Commit

Permalink
its: Add entity::IssueComment::update
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Jul 30, 2022
1 parent 1afebb1 commit 519095e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
8 changes: 4 additions & 4 deletions its/crates/domain/src/domain/aggregate/issue_comment.rs
Expand Up @@ -2,12 +2,10 @@ pub mod attribute;
pub mod entity;
pub mod event;

use anyhow::Context;

use crate::Version;

use self::entity::IssueComment;
pub use self::event::Event;
use self::{entity::IssueComment, event::IssueCommentUpdated};

#[derive(Clone, Debug, Eq, PartialEq, thiserror::Error)]
pub enum Error {
Expand Down Expand Up @@ -41,7 +39,9 @@ impl IssueCommentAggregate {
issue_comment = match event {
Event::Created(_) => Err(Error::InvalidEventSequence),
Event::Deleted(_) => todo!(),
Event::Updated(_) => todo!(),
Event::Updated(IssueCommentUpdated { text, .. }) => {
Ok(issue_comment.update(text.clone()))
}
}?;
}
let last_event = events.last().expect("empty event sequence").clone();
Expand Down
Expand Up @@ -22,6 +22,14 @@ impl IssueComment {
pub fn new(id: IssueCommentId, issue_id: IssueId, text: IssueCommentText) -> Self {
Self { id, issue_id, text }
}

pub fn update(&self, text: IssueCommentText) -> Self {
Self {
id: self.id.clone(),
issue_id: self.issue_id.clone(),
text,
}
}
}

#[cfg(test)]
Expand Down
Expand Up @@ -18,10 +18,10 @@ pub enum Error {

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IssueCommentUpdated {
pub(super) at: Instant,
pub(super) issue_comment_id: IssueCommentId,
pub(super) text: IssueCommentText,
pub(super) version: Version,
pub(in crate::aggregate::issue_comment) at: Instant,
pub(in crate::aggregate::issue_comment) issue_comment_id: IssueCommentId,
pub(in crate::aggregate::issue_comment) text: IssueCommentText,
pub(in crate::aggregate::issue_comment) version: Version,
}

#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
Expand Down

0 comments on commit 519095e

Please sign in to comment.