| 25 | |
| 26 | impl DeleteLink { |
| 27 | pub fn call<S>(&self, mut mutation: Mutation, store: &S) -> Result<DeleteLinkResult> |
| 28 | where |
| 29 | S: SaveChangesForPrefix, |
| 30 | { |
| 31 | let link = mutation.fetch_link(self.repo_id, &self.link_id); |
| 32 | if link.is_none() { |
| 33 | return Err(Error::NotFound(format!("not found: {}", self.link_id))); |
| 34 | } |
| 35 | let link = link.unwrap(); |
| 36 | |
| 37 | // Not actually used |
| 38 | let date = chrono::Utc::now(); |
| 39 | let child = link.to_topic_child(date); |
| 40 | let mut parent_topics = vec![]; |
| 41 | |
| 42 | mutation.mark_deleted(self.repo_id, &self.link_id)?; |
| 43 | |
| 44 | for ParentTopic { id: parent_id, .. } in &link.parent_topics { |
| 45 | if let Some(mut parent) = mutation.fetch_topic(self.repo_id, parent_id) { |
| 46 | parent.children.remove(&child); |
| 47 | mutation.save_topic(self.repo_id, &parent)?; |
| 48 | parent_topics.push(parent); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | let change = self.change(&link, &parent_topics, date); |
| 53 | |
| 54 | mutation.remove_link(self.repo_id, &self.link_id, &link)?; |
| 55 | mutation.add_change(self.repo_id, &change)?; |
| 56 | mutation.write(store)?; |
| 57 | |
| 58 | Ok(DeleteLinkResult { |
| 59 | alerts: vec![], |
| 60 | deleted_link_id: self.link_id.clone(), |
| 61 | }) |
| 62 | } |
| 63 | |
| 64 | fn change( |
| 65 | &self, |