Add a method for approving blog posts
This commit is contained in:
parent
733659f8ce
commit
9506e84f16
1 changed files with 27 additions and 0 deletions
|
@ -24,10 +24,17 @@ impl Post {
|
||||||
self.state = Some(s.request_review())
|
self.state = Some(s.request_review())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn approve(&mut self) {
|
||||||
|
if let Some(s) = self.state.take() {
|
||||||
|
self.state = Some(s.approve())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait State {
|
trait State {
|
||||||
fn request_review(self: Box<Self>) -> Box<dyn State>;
|
fn request_review(self: Box<Self>) -> Box<dyn State>;
|
||||||
|
fn approve(self: Box<Self>) -> Box<dyn State>;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Draft {}
|
struct Draft {}
|
||||||
|
@ -36,6 +43,10 @@ impl State for Draft {
|
||||||
fn request_review(self: Box<Self>) -> Box<dyn State> {
|
fn request_review(self: Box<Self>) -> Box<dyn State> {
|
||||||
Box::new(PendingReview {})
|
Box::new(PendingReview {})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn approve(self: Box<Self>) -> Box<dyn State> {
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PendingReview {}
|
struct PendingReview {}
|
||||||
|
@ -44,4 +55,20 @@ impl State for PendingReview {
|
||||||
fn request_review(self: Box<Self>) -> Box<dyn State> {
|
fn request_review(self: Box<Self>) -> Box<dyn State> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn approve(self: Box<Self>) -> Box<dyn State> {
|
||||||
|
Box::new(Published {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Published {}
|
||||||
|
|
||||||
|
impl State for Published {
|
||||||
|
fn request_review(self: Box<Self>) -> Box<dyn State> {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn approve(self: Box<Self>) -> Box<dyn State> {
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue