Skip to content

Commit

Permalink
its: Added IssueResolution arg to Issue::finish
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Apr 14, 2022
1 parent 4932748 commit 3645106
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
9 changes: 5 additions & 4 deletions its/crates/domain/src/domain/aggregate/issue.rs
Expand Up @@ -65,12 +65,11 @@ impl IssueAggregate {
return Err(IssueAggregateError::InvalidEventSequence);
}

// FIXME: Use resolution
issue = IssueAggregate {
events: vec![],
issue: issue
.issue
.finish()
.finish(resolution.clone())
.map_err(|_| IssueAggregateError::InvalidEventSequence)?,
version: *version,
}
Expand Down Expand Up @@ -126,15 +125,17 @@ impl IssueAggregate {
}

pub fn finish(&self, at: Instant) -> Result<IssueAggregate, IssueAggregateError> {
// FIXME: resolution
let resolution = None;
let updated_issue = self
.issue
.finish()
.finish(resolution.clone())
.map_err(|_| IssueAggregateError::Unknown)?;
let updated_version = self.version.next().ok_or(IssueAggregateError::Unknown)?;
let event = IssueFinished {
at,
issue_id: self.id().clone(),
resolution: None, // FIXME
resolution,
version: updated_version,
}
.into();
Expand Down
17 changes: 14 additions & 3 deletions its/crates/domain/src/domain/entity/issue.rs
@@ -1,6 +1,8 @@
use thiserror::Error;

use crate::{IssueCreatedV2, IssueDue, IssueId, IssueNumber, IssueStatus, IssueTitle};
use crate::{
IssueCreatedV2, IssueDue, IssueId, IssueNumber, IssueResolution, IssueStatus, IssueTitle,
};

#[derive(Debug, Error)]
pub enum IssueError {
Expand All @@ -11,6 +13,7 @@ pub enum IssueError {
#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) struct Issue {
id: IssueId,
resolution: Option<IssueResolution>,
status: IssueStatus,
title: IssueTitle,
due: Option<IssueDue>,
Expand All @@ -20,6 +23,7 @@ impl Issue {
pub(crate) fn from_event(event: IssueCreatedV2) -> Self {
Self {
id: event.issue_id,
resolution: None,
status: IssueStatus::Todo,
title: event.issue_title,
due: event.issue_due,
Expand All @@ -29,18 +33,20 @@ impl Issue {
pub(crate) fn new(id: IssueId, title: IssueTitle, due: Option<IssueDue>) -> Self {
Self {
id,
resolution: None,
status: IssueStatus::Todo,
title,
due,
}
}

pub(crate) fn finish(&self) -> Result<Self, IssueError> {
pub(crate) fn finish(&self, resolution: Option<IssueResolution>) -> Result<Self, IssueError> {
if self.status == IssueStatus::Done {
return Err(IssueError::AlreadyFinished);
}
Ok(Self {
id: self.id.clone(),
resolution,
status: IssueStatus::Done,
title: self.title.clone(),
due: self.due,
Expand All @@ -50,6 +56,7 @@ impl Issue {
pub(crate) fn change_due(&self, due: Option<IssueDue>) -> Self {
Self {
id: self.id.clone(),
resolution: self.resolution.clone(),
status: self.status,
title: self.title.clone(),
due,
Expand All @@ -64,6 +71,10 @@ impl Issue {
self.id.issue_number()
}

pub(crate) fn resolution(&self) -> Option<&IssueResolution> {
self.resolution.as_ref()
}

pub(crate) fn status(&self) -> IssueStatus {
self.status
}
Expand Down Expand Up @@ -112,7 +123,7 @@ mod tests {
let number = IssueNumber::try_from(1_usize)?;
let title = IssueTitle::from_str("title1")?;
let issue = Issue::new(IssueId::new(number), title, None);
let updated = issue.finish()?;
let updated = issue.finish(None)?; // TODO: Use resolution
assert_eq!(updated.status(), IssueStatus::Done);
Ok(())
}
Expand Down

0 comments on commit 3645106

Please sign in to comment.